From: Jeremias Maerki Date: Fri, 22 Apr 2011 06:55:48 +0000 (+0000) Subject: Enable fox:conversion-mode="bitmap" for PDF output. X-Git-Tag: fop-1_1rc1old~230 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b5c893c24c1ab7bdc7ae6ecd88035eed20565df7;p=xmlgraphics-fop.git Enable fox:conversion-mode="bitmap" for PDF output. Release memory from Batik GVT as early as possible to break some peaks. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1095876 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java index d309a00aa..a71ade911 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java @@ -31,6 +31,7 @@ import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; import org.apache.fop.render.AbstractImageHandlerGraphics2D; +import org.apache.fop.render.ImageHandlerUtil; import org.apache.fop.render.RenderingContext; import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo; import org.apache.fop.svg.PDFGraphics2D; @@ -60,8 +61,8 @@ public class PDFImageHandlerGraphics2D extends AbstractImageHandlerGraphics2D { float imw = (float)dim.getWidth() / 1000f; float imh = (float)dim.getHeight() / 1000f; - float sx = fwidth / (float)imw; - float sy = fheight / (float)imh; + float sx = fwidth / imw; + float sy = fheight / imh; generator.comment("G2D start"); boolean accessibilityEnabled = context.getUserAgent().isAccessibilityEnabled(); @@ -123,8 +124,16 @@ public class PDFImageHandlerGraphics2D extends AbstractImageHandlerGraphics2D { /** {@inheritDoc} */ public boolean isCompatible(RenderingContext targetContext, Image image) { - return (image == null || image instanceof ImageGraphics2D) + boolean supported = (image == null || image instanceof ImageGraphics2D) && targetContext instanceof PDFRenderingContext; + if (supported) { + String mode = (String)targetContext.getHint(ImageHandlerUtil.CONVERSION_MODE); + if (ImageHandlerUtil.isConversionModeBitmap(mode)) { + //Disabling this image handler automatically causes a bitmap to be generated + return false; + } + } + return supported; } } diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java index d47142fb6..2b02b60fb 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java @@ -43,6 +43,7 @@ import org.apache.fop.apps.FOUserAgent; import org.apache.fop.image.loader.batik.BatikImageFlavors; import org.apache.fop.image.loader.batik.BatikUtil; import org.apache.fop.render.ImageHandler; +import org.apache.fop.render.ImageHandlerUtil; import org.apache.fop.render.RenderingContext; import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo; import org.apache.fop.svg.PDFAElementBridge; @@ -200,6 +201,7 @@ public class PDFImageHandlerSVG implements ImageHandler { graphics.setOutputStream(generator.getOutputStream()); try { root.paint(graphics); + ctx.dispose(); generator.add(graphics.getString()); } catch (Exception e) { SVGEventProducer eventProducer = SVGEventProducer.Provider.get( @@ -236,10 +238,18 @@ public class PDFImageHandlerSVG implements ImageHandler { /** {@inheritDoc} */ public boolean isCompatible(RenderingContext targetContext, Image image) { - return (image == null + boolean supported = (image == null || (image instanceof ImageXMLDOM && image.getFlavor().isCompatible(BatikImageFlavors.SVG_DOM))) && targetContext instanceof PDFRenderingContext; + if (supported) { + String mode = (String)targetContext.getHint(ImageHandlerUtil.CONVERSION_MODE); + if (ImageHandlerUtil.isConversionModeBitmap(mode)) { + //Disabling this image handler automatically causes a bitmap to be generated + return false; + } + } + return supported; } }