diff options
author | Adrian Cumiskey <acumiskey@apache.org> | 2008-10-20 10:57:29 +0000 |
---|---|---|
committer | Adrian Cumiskey <acumiskey@apache.org> | 2008-10-20 10:57:29 +0000 |
commit | 298e1f31e9d0591d9555347ef0964e835e7f70ee (patch) | |
tree | 6545f567d8e2f103427d8457017f8b94cb6a7c03 /src/java/org/apache/fop/image | |
parent | 575187323ab8e636c4e04b4f77b5bda6a137d61d (diff) | |
download | xmlgraphics-fop-298e1f31e9d0591d9555347ef0964e835e7f70ee.tar.gz xmlgraphics-fop-298e1f31e9d0591d9555347ef0964e835e7f70ee.zip |
* SVG circle drawing improvements in AFPGraphics2D.
* GenericGraphics2DImagePainter becomes a top level class.
* AFPGraphics2DImagePainter implementation to correctly adjust y-axis for AFP.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@706226 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/image')
-rw-r--r-- | src/java/org/apache/fop/image/loader/batik/GenericGraphics2DImagePainter.java | 95 | ||||
-rw-r--r-- | src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java | 56 |
2 files changed, 95 insertions, 56 deletions
diff --git a/src/java/org/apache/fop/image/loader/batik/GenericGraphics2DImagePainter.java b/src/java/org/apache/fop/image/loader/batik/GenericGraphics2DImagePainter.java new file mode 100644 index 000000000..aa4d991b6 --- /dev/null +++ b/src/java/org/apache/fop/image/loader/batik/GenericGraphics2DImagePainter.java @@ -0,0 +1,95 @@ +package org.apache.fop.image.loader.batik; + +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; + +import org.apache.batik.bridge.BridgeContext; +import org.apache.batik.gvt.GraphicsNode; +import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; +import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; + +/** + * A generic graphics 2D image painter implementation + */ +public class GenericGraphics2DImagePainter implements Graphics2DImagePainter { + + protected final ImageXMLDOM svg; + protected final BridgeContext ctx; + protected final GraphicsNode root; + + /** + * Constructor + * + * @param svg the svg image dom + * @param ctx the bridge context + * @param root the graphics node root + */ + public GenericGraphics2DImagePainter(ImageXMLDOM svg, BridgeContext ctx, GraphicsNode root) { + this.svg = svg; + this.ctx = ctx; + this.root = root; + } + + /** + * Initialises the graphics 2d + * + * @param g2d the graphics 2d + * @param area the rectangle drawing area + */ + protected void init(Graphics2D g2d, Rectangle2D area) { + // If no viewbox is defined in the svg file, a viewbox of 100x100 is + // assumed, as defined in SVGUserAgent.getViewportSize() + double tx = area.getX(); + double ty = area.getY(); + if (tx != 0 || ty != 0) { + g2d.translate(tx, ty); + } + + float iw = (float) ctx.getDocumentSize().getWidth(); + float ih = (float) ctx.getDocumentSize().getHeight(); + float w = (float) area.getWidth(); + float h = (float) area.getHeight(); + float sx = w / iw; + float sy = h / ih; + if (sx != 1.0 || sy != 1.0) { + g2d.scale(sx, sy); + } + } + + /** {@inheritDoc} */ + public void paint(Graphics2D g2d, Rectangle2D area) { + init(g2d, area); + root.paint(g2d); + } + + /** {@inheritDoc} */ + public Dimension getImageSize() { + return new Dimension(svg.getSize().getWidthMpt(), svg.getSize().getHeightMpt()); + } + + /** + * Returns the svg image dom + * @return the svg image dom + */ + public ImageXMLDOM getImageXMLDOM() { + return svg; + } + + /** + * Returns the bridge context + * @return the bridge context + */ + public BridgeContext getBridgeContext() { + return ctx; + } + + /** + * Returns the graphics root node + * @return the graphics root node + */ + public GraphicsNode getRoot() { + return root; + } + +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java b/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java index 65b2f71cf..a2c0128c2 100644 --- a/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java +++ b/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java @@ -19,10 +19,7 @@ package org.apache.fop.image.loader.batik; -import java.awt.Dimension; -import java.awt.Graphics2D; import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; import java.util.Map; import org.apache.batik.bridge.BridgeContext; @@ -110,59 +107,6 @@ public class ImageConverterSVG2G2D extends AbstractImageConverter { } /** - * A generic graphics 2D image painter implementation - */ - protected class GenericGraphics2DImagePainter implements Graphics2DImagePainter { - - private final ImageXMLDOM svg; - private final BridgeContext ctx; - private final GraphicsNode root; - - /** - * Constructor - * - * @param svg the svg image dom - * @param ctx the bridge context - * @param root the graphics node root - */ - public GenericGraphics2DImagePainter(ImageXMLDOM svg, BridgeContext ctx, GraphicsNode root) { - this.svg = svg; - this.ctx = ctx; - this.root = root; - } - - protected void init(Graphics2D g2d, Rectangle2D area) { - // If no viewbox is defined in the svg file, a viewbox of 100x100 is - // assumed, as defined in SVGUserAgent.getViewportSize() - double tx = area.getX(); - double ty = area.getY(); - if (tx != 0 || ty != 0) { - g2d.translate(tx, ty); - } - - float iw = (float) ctx.getDocumentSize().getWidth(); - float ih = (float) ctx.getDocumentSize().getHeight(); - float w = (float) area.getWidth(); - float h = (float) area.getHeight(); - float sx = w / iw; - float sy = h / ih; - if (sx != 1.0 || sy != 1.0) { - g2d.scale(sx, sy); - } - } - - public void paint(Graphics2D g2d, Rectangle2D area) { - init(g2d, area); - root.paint(g2d); - } - - public Dimension getImageSize() { - return new Dimension(svg.getSize().getWidthMpt(), svg.getSize().getHeightMpt()); - } - - } - - /** * Creates a Graphics 2D image painter * * @param svg the svg image dom |