diff options
Diffstat (limited to 'src/org/apache/fop/svg')
-rw-r--r-- | src/org/apache/fop/svg/PDFANode.java | 6 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTextPainter.java | 37 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTranscoder.java | 42 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGElement.java | 27 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGUserAgent.java | 146 |
5 files changed, 193 insertions, 65 deletions
diff --git a/src/org/apache/fop/svg/PDFANode.java b/src/org/apache/fop/svg/PDFANode.java index c9c88028f..3fd4be391 100644 --- a/src/org/apache/fop/svg/PDFANode.java +++ b/src/org/apache/fop/svg/PDFANode.java @@ -50,13 +50,13 @@ public class PDFANode extends CompositeGraphicsNode { * @param g2d the Graphics2D to use * @param rc the GraphicsNodeRenderContext to use */ - public void paint(Graphics2D g2d, GraphicsNodeRenderContext rc) { + public void paint(Graphics2D g2d) { if (isVisible) { - super.paint(g2d, rc); + super.paint(g2d); if(g2d instanceof PDFGraphics2D) { PDFGraphics2D pdfg = (PDFGraphics2D)g2d; int type = org.apache.fop.layout.LinkSet.EXTERNAL; - Shape outline = getOutline(rc); + Shape outline = getOutline(); if(destination.startsWith("#svgView(viewBox(")) { String nums = destination.substring(18, destination.length() - 2); float x = 0; diff --git a/src/org/apache/fop/svg/PDFTextPainter.java b/src/org/apache/fop/svg/PDFTextPainter.java index ae5512e34..238406f33 100644 --- a/src/org/apache/fop/svg/PDFTextPainter.java +++ b/src/org/apache/fop/svg/PDFTextPainter.java @@ -10,7 +10,6 @@ package org.apache.fop.svg; import java.awt.Graphics2D; import java.awt.*; import java.text.AttributedCharacterIterator; -import java.awt.font.FontRenderContext; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.Font; @@ -53,8 +52,7 @@ public class PDFTextPainter implements TextPainter { * @param g2d the Graphics2D to use * @param context the rendering context. */ - public void paint(TextNode node, Graphics2D g2d, - GraphicsNodeRenderContext context) { + public void paint(TextNode node, Graphics2D g2d) { // System.out.println("PDFText paint"); String txt = node.getText(); Point2D loc = node.getLocation(); @@ -191,12 +189,11 @@ public class PDFTextPainter implements TextPainter { * @param y the y coordinate, in the text layout's coordinate system, * of the selection event. * @param aci the AttributedCharacterIterator describing the text - * @param context the GraphicsNodeRenderContext to use when doing text layout. * @return an instance of Mark which encapsulates the state necessary to * implement hit testing and text selection. */ public Mark selectAt(double x, double y, AttributedCharacterIterator aci, - TextNode node, GraphicsNodeRenderContext context) { + TextNode node) { System.out.println("PDFText selectAt"); return null; } @@ -209,13 +206,12 @@ public class PDFTextPainter implements TextPainter { * @param y the y coordinate, in the text layout's coordinate system, * of the selection event. * @param aci the AttributedCharacterIterator describing the text - * @param context the GraphicsNodeRenderContext to use when doing text layout. * @return an instance of Mark which encapsulates the state necessary to * implement hit testing and text selection. */ public Mark selectTo(double x, double y, Mark beginMark, - AttributedCharacterIterator aci, TextNode node, - GraphicsNodeRenderContext context) { + AttributedCharacterIterator aci, + TextNode node) { System.out.println("PDFText selectTo"); return null; } @@ -228,13 +224,12 @@ public class PDFTextPainter implements TextPainter { * @param y the y coordinate, in the text layout's coordinate system, * of the selection event. * @param aci the AttributedCharacterIterator describing the text - * @param context the GraphicsNodeRenderContext to use when doing text layout. * @return an instance of Mark which encapsulates the state necessary to * implement hit testing and text selection. */ public Mark selectAll(double x, double y, - AttributedCharacterIterator aci, TextNode node, - GraphicsNodeRenderContext context) { + AttributedCharacterIterator aci, + TextNode node) { System.out.println("PDFText selectAll"); return null; } @@ -244,8 +239,8 @@ public class PDFTextPainter implements TextPainter { * Selects the first glyph in the text node. */ public Mark selectFirst(double x, double y, - AttributedCharacterIterator aci, TextNode node, - GraphicsNodeRenderContext context) { + AttributedCharacterIterator aci, + TextNode node) { System.out.println("PDFText selectFirst"); return null; } @@ -255,8 +250,8 @@ public class PDFTextPainter implements TextPainter { * Selects the last glyph in the text node. */ public Mark selectLast(double x, double y, - AttributedCharacterIterator aci, TextNode node, - GraphicsNodeRenderContext context) { + AttributedCharacterIterator aci, + TextNode node) { System.out.println("PDFText selectLast"); return null; } @@ -300,7 +295,7 @@ public class PDFTextPainter implements TextPainter { * @param includeStroke whether to create the "stroke shape outlines" * instead of glyph outlines. */ - public Shape getShape(TextNode node, FontRenderContext frc) { + public Shape getShape(TextNode node) { System.out.println("PDFText getShape"); return null; } @@ -314,7 +309,7 @@ public class PDFTextPainter implements TextPainter { * @param includeStroke whether to create the "stroke shape outlines" * instead of glyph outlines. */ - public Shape getDecoratedShape(TextNode node, FontRenderContext frc) { + public Shape getDecoratedShape(TextNode node) { System.out.println("PDFText getDecoratedShape"); return new Rectangle(1, 1); } @@ -326,7 +321,7 @@ public class PDFTextPainter implements TextPainter { * @param g2d the Graphics2D to use * @param context rendering context. */ - public Rectangle2D getBounds(TextNode node, FontRenderContext frc) { + public Rectangle2D getBounds(TextNode node) { System.out.println("PDFText getBounds"); return null; } @@ -339,8 +334,7 @@ public class PDFTextPainter implements TextPainter { * @param g2d the Graphics2D to use * @param context rendering context. */ - public Rectangle2D getDecoratedBounds(TextNode node, - FontRenderContext frc) { + public Rectangle2D getDecoratedBounds(TextNode node) { System.out.println("PDFText getDecoratedBounds"); return null; } @@ -353,8 +347,7 @@ public class PDFTextPainter implements TextPainter { * @param g2d the Graphics2D to use * @param context rendering context. */ - public Rectangle2D getPaintedBounds(TextNode node, - FontRenderContext frc) { + public Rectangle2D getPaintedBounds(TextNode node) { // System.out.println("PDFText getPaintedBounds"); return null; } diff --git a/src/org/apache/fop/svg/PDFTranscoder.java b/src/org/apache/fop/svg/PDFTranscoder.java index 74197263d..73d5fcb46 100644 --- a/src/org/apache/fop/svg/PDFTranscoder.java +++ b/src/org/apache/fop/svg/PDFTranscoder.java @@ -49,7 +49,6 @@ import org.apache.batik.dom.util.DocumentFactory; import org.apache.batik.ext.awt.image.GraphicsUtil; import org.apache.batik.gvt.GraphicsNode; -import org.apache.batik.gvt.GraphicsNodeRenderContext; import org.apache.batik.gvt.event.EventDispatcher; import org.apache.batik.gvt.renderer.ImageRenderer; import org.apache.batik.gvt.renderer.ImageRendererFactory; @@ -178,8 +177,11 @@ public class PDFTranscoder extends XMLAbstractTranscoder { // build the GVT tree GVTBuilder builder = new GVTBuilder(); ImageRendererFactory rendFactory = new StaticRendererFactory(); - GraphicsNodeRenderContext rc = getRenderContext(stroke); - BridgeContext ctx = new BridgeContext(userAgent, rc); + BridgeContext ctx = new BridgeContext(userAgent); + TextPainter textPainter = null; + textPainter = new StrokingTextPainter(); + ctx.setTextPainter(textPainter); + PDFAElementBridge pdfAElementBridge = new PDFAElementBridge(); AffineTransform currentTransform = new AffineTransform(1, 0, 0, 1, 0, 0); pdfAElementBridge.setCurrentTransform(currentTransform); @@ -269,18 +271,16 @@ public class PDFTranscoder extends XMLAbstractTranscoder { graphics.setSVGDimension(docWidth, docHeight); currentTransform.setTransform(1, 0, 0, -1, 0, height); if (!stroke) { - TextPainter textPainter = null; textPainter = new PDFTextPainter(graphics.getFontState()); - rc.setTextPainter(textPainter); + ctx.setTextPainter(textPainter); } if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) { graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR)); } graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); - graphics.setRenderingHints(rc.getRenderingHints()); - gvtRoot.paint(graphics, rc); + gvtRoot.paint(graphics); try { graphics.finish(); @@ -290,34 +290,6 @@ public class PDFTranscoder extends XMLAbstractTranscoder { } } - public GraphicsNodeRenderContext getRenderContext(boolean stroke) { - GraphicsNodeRenderContext nodeRenderContext = null; - if (nodeRenderContext == null) { - RenderingHints hints = new RenderingHints(null); - hints.put(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - hints.put(RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BILINEAR); - - FontRenderContext fontRenderContext = - new FontRenderContext(new AffineTransform(), true, true); - - TextPainter textPainter = null; - textPainter = new StrokingTextPainter(); - - GraphicsNodeRableFactory gnrFactory = - new ConcreteGraphicsNodeRableFactory(); - - nodeRenderContext = - new GraphicsNodeRenderContext(new AffineTransform(), null, - hints, fontRenderContext, - textPainter, gnrFactory); - } - - return nodeRenderContext; - } - /** * Creates a <tt>DocumentFactory</tt> that is used to create an SVG DOM * tree. The specified DOM Implementation is ignored and the Batik diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java index 8642b3ebc..30d7a06f7 100644 --- a/src/org/apache/fop/svg/SVGElement.java +++ b/src/org/apache/fop/svg/SVGElement.java @@ -20,6 +20,13 @@ import org.apache.batik.dom.svg.*; import org.w3c.dom.*; import org.w3c.dom.svg.*; import org.w3c.dom.svg.SVGLength; +import org.apache.batik.bridge.*; +import org.apache.batik.swing.svg.*; +import org.apache.batik.swing.gvt.*; +import org.apache.batik.gvt.*; +import org.apache.batik.gvt.renderer.*; +import org.apache.batik.gvt.filter.*; +import org.apache.batik.gvt.event.*; import org.w3c.dom.DOMImplementation; import org.apache.batik.dom.svg.SVGDOMImplementation; @@ -28,6 +35,7 @@ import java.io.File; import java.net.URL; import java.util.List; import java.util.ArrayList; +import java.awt.geom.AffineTransform; /** * class representing svg:svg pseudo flow object. @@ -51,7 +59,6 @@ public class SVGElement extends SVGObj { PropertyList propertyList) throws FOPException { return new SVGElement(parent, propertyList); } - } /** @@ -131,10 +138,20 @@ public class SVGElement extends SVGObj { }; ((SVGOMDocument)doc).setSVGContext(dc); - float width = - ((SVGSVGElement)element).getWidth().getBaseVal().getValue(); - float height = - ((SVGSVGElement)element).getHeight().getBaseVal().getValue(); + // this is ugly preprocessing to get the width and height + SVGUserAgent userAgent = new SVGUserAgent(new AffineTransform()); + userAgent.setLogger(log); + GVTBuilder builder = new GVTBuilder(); + BridgeContext ctx = new BridgeContext(userAgent); + GraphicsNode root; + root = builder.build(ctx, doc); + // get the 'width' and 'height' attributes of the SVG document + float width = (float)ctx.getDocumentSize().getWidth(); + float height = (float)ctx.getDocumentSize().getHeight(); + ctx = null; + builder = null; + /////// + SVGArea svg = new SVGArea(fs, width, height); svg.setSVGDocument(doc); svg.start(); diff --git a/src/org/apache/fop/svg/SVGUserAgent.java b/src/org/apache/fop/svg/SVGUserAgent.java new file mode 100644 index 000000000..bbd3b08e6 --- /dev/null +++ b/src/org/apache/fop/svg/SVGUserAgent.java @@ -0,0 +1,146 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.svg; + +import org.apache.log.Logger; + +import org.apache.batik.bridge.*; +import org.apache.batik.swing.svg.*; +import org.apache.batik.swing.gvt.*; +import org.apache.batik.gvt.*; +import org.apache.batik.gvt.renderer.*; +import org.apache.batik.gvt.filter.*; +import org.apache.batik.gvt.event.*; + +import org.w3c.dom.*; +import org.w3c.dom.svg.*; +import org.w3c.dom.css.*; +import org.w3c.dom.svg.SVGLength; + +// Java +import java.io.IOException; +import java.io.OutputStream; +import java.util.Enumeration; +import java.util.Vector; +import java.util.Hashtable; +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; +import java.awt.Point; +import java.awt.RenderingHints; +import java.awt.Dimension; + +public class SVGUserAgent implements UserAgent { + AffineTransform currentTransform = null; + Logger log; + + /** + * Creates a new SVGUserAgent. + */ + public SVGUserAgent(AffineTransform at) { + currentTransform = at; + } + + public void setLogger(Logger logger) { + log = logger; + } + + /** + * Displays an error message. + */ + public void displayError(String message) { + log.error(message); + } + + /** + * Displays an error resulting from the specified Exception. + */ + public void displayError(Exception ex) { + log.error("SVG Error" + ex.getMessage(), ex); + } + + /** + * Displays a message in the User Agent interface. + * The given message is typically displayed in a status bar. + */ + public void displayMessage(String message) { + log.info(message); + } + + /** + * Returns a customized the pixel to mm factor. + */ + public float getPixelToMM() { + // this is set to 72dpi as the values in fo are 72dpi + return 0.35277777777777777778f; // 72 dpi + // return 0.26458333333333333333333333333333f; // 96dpi + } + + /** + * Returns the language settings. + */ + public String getLanguages() { + return "en"; // userLanguages; + } + + /** + * Returns the user stylesheet uri. + * @return null if no user style sheet was specified. + */ + public String getUserStyleSheetURI() { + return null; // userStyleSheetURI; + } + + /** + * Returns the class name of the XML parser. + */ + public String getXMLParserClassName() { + return org.apache.fop.apps.Driver.getParserClassName(); + } + + /** + * Opens a link in a new component. + * @param doc The current document. + * @param uri The document URI. + */ + public void openLink(SVGAElement elt) { + } + + + public Point getClientAreaLocationOnScreen() { + return new Point(0, 0); + } + + public void setSVGCursor(java.awt.Cursor cursor) {} + + public AffineTransform getTransform() { + return currentTransform; + } + + public Dimension2D getViewportSize() { + return new Dimension(100, 100); + } + + public EventDispatcher getEventDispatcher() { + return null; + } + + public boolean supportExtension(String str) { + return false; + } + + public boolean hasFeature(String str) { + return false; + } + + public void registerExtension(BridgeExtension be) {} + + public void handleElement(Element elt, Object data) {} + + +} + |