From: Adrian Cumiskey Date: Wed, 29 Oct 2008 11:21:32 +0000 (+0000) Subject: Renamed GenericGraphics2DImagePainter to a slightly more meaningful name of BatikGrap... X-Git-Tag: fop-1_0~376^2~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6ba537ec897da9120a6105d6f4c5fc6aa48e7658;p=xmlgraphics-fop.git Renamed GenericGraphics2DImagePainter to a slightly more meaningful name of BatikGraphics2DImagePainter. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@708877 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/image/loader/batik/BatikGraphics2DImagePainter.java b/src/java/org/apache/fop/image/loader/batik/BatikGraphics2DImagePainter.java new file mode 100644 index 000000000..983033027 --- /dev/null +++ b/src/java/org/apache/fop/image/loader/batik/BatikGraphics2DImagePainter.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 BatikGraphics2DImagePainter 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 BatikGraphics2DImagePainter(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/GenericGraphics2DImagePainter.java b/src/java/org/apache/fop/image/loader/batik/GenericGraphics2DImagePainter.java deleted file mode 100644 index aa4d991b6..000000000 --- a/src/java/org/apache/fop/image/loader/batik/GenericGraphics2DImagePainter.java +++ /dev/null @@ -1,95 +0,0 @@ -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 a2c0128c2..40dc600be 100644 --- a/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java +++ b/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java @@ -116,7 +116,7 @@ public class ImageConverterSVG2G2D extends AbstractImageConverter { */ protected Graphics2DImagePainter createPainter( final ImageXMLDOM svg, final BridgeContext ctx, final GraphicsNode root) { - return new GenericGraphics2DImagePainter(svg, ctx, root); + return new BatikGraphics2DImagePainter(svg, ctx, root); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java b/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java index 81d00bd10..da9a37b76 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java @@ -36,7 +36,7 @@ import org.apache.fop.afp.AFPState; import org.apache.fop.afp.AFPTextElementBridge; import org.apache.fop.afp.AFPTextHandler; import org.apache.fop.afp.AFPTextPainter; -import org.apache.fop.image.loader.batik.GenericGraphics2DImagePainter; +import org.apache.fop.image.loader.batik.BatikGraphics2DImagePainter; import org.apache.fop.render.RendererContext; import org.apache.fop.svg.SVGUserAgent; import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; @@ -117,8 +117,8 @@ public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory { // set painter ImageGraphics2D imageG2D = (ImageGraphics2D)rendererImageInfo.getImage(); - GenericGraphics2DImagePainter painter - = (GenericGraphics2DImagePainter)imageG2D.getGraphics2DImagePainter(); + BatikGraphics2DImagePainter painter + = (BatikGraphics2DImagePainter)imageG2D.getGraphics2DImagePainter(); painter = new AFPGraphics2DImagePainter(painter); imageG2D.setGraphics2DImagePainter(painter); graphicsObjectInfo.setPainter(painter); @@ -131,13 +131,13 @@ public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory { return graphicsObjectInfo; } - private class AFPGraphics2DImagePainter extends GenericGraphics2DImagePainter { + private class AFPGraphics2DImagePainter extends BatikGraphics2DImagePainter { /** * Copy constructor * * @param painter a graphics 2D image painter */ - public AFPGraphics2DImagePainter(GenericGraphics2DImagePainter painter) { + public AFPGraphics2DImagePainter(BatikGraphics2DImagePainter painter) { super(painter.getImageXMLDOM(), painter.getBridgeContext(), painter.getRoot()); }