From 13a3f8ffed7661ad52f61195fc8dc6f5fcf202ab Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 10 Nov 2005 15:01:49 +0000 Subject: [PATCH] Bugzilla #37305: Better approach to higher resolution on-the-fly images generated by Batik. Submitted by: Thomas Deweese Changes to the patch: Added a transcoding hint to be able to set this value. Default device resolution set to 300dpi. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@332304 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/svg/PDFDocumentGraphics2D.java | 41 +++++++++++++++++-- .../org/apache/fop/svg/PDFTranscoder.java | 13 +++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java index 85e5f667f..43d0cdf3c 100644 --- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -67,11 +67,22 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D private float svgWidth; private float svgHeight; - /** Initial clipping area, used to restore to original setting when a new page is started. */ + /** Default device resolution (300dpi is a resonable quality for most purposes) */ + public static final int DEFAULT_NATIVE_DPI = 300; + + /** + * The device resolution may be different from the normal target resolution. See + * http://issues.apache.org/bugzilla/show_bug.cgi?id=37305 + */ + private float deviceDPI = DEFAULT_NATIVE_DPI; + + /** Initial clipping area, used to restore to original setting + * when a new page is started. */ protected Shape initialClip; + /** - * Initial transformation matrix, used to restore to original setting when a new page is - * started. + * Initial transformation matrix, used to restore to original + * setting when a new page is started. */ protected AffineTransform initialTransform; @@ -182,6 +193,22 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D setOutputStream(stream); } + /** + * Set the device resolution for rendering. Will take effect at the + * start of the next page. + * @param deviceDPI the device resolution (in dpi) + */ + public void setDeviceDPI(float deviceDPI) { + this.deviceDPI = deviceDPI; + } + + /** + * @return the device resolution (in dpi) for rendering. + */ + public float getDeviceDPI() { + return deviceDPI; + } + /** * Get the font info for this pdf document. * @return the font information @@ -316,6 +343,14 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D currentStream.write("" + PDFNumber.doubleOut(scaleX) + " 0 0 " + PDFNumber.doubleOut(scaleY) + " 0 0 cm\n"); } + if (deviceDPI != DEFAULT_NATIVE_DPI) { + double s = DEFAULT_NATIVE_DPI / deviceDPI; + at.scale(s, s); + currentStream.write("" + PDFNumber.doubleOut(s) + " 0 0 " + + PDFNumber.doubleOut(s) + " 0 0 cm\n"); + + scale(1 / s, 1 / s); + } // Remember the transform we installed. graphicsState.setTransform(at); diff --git a/src/java/org/apache/fop/svg/PDFTranscoder.java b/src/java/org/apache/fop/svg/PDFTranscoder.java index d19f75bcf..a07b1c9f5 100644 --- a/src/java/org/apache/fop/svg/PDFTranscoder.java +++ b/src/java/org/apache/fop/svg/PDFTranscoder.java @@ -32,7 +32,9 @@ import org.apache.batik.bridge.UserAgent; import org.apache.batik.ext.awt.RenderingHintsKeyExt; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.TranscodingHints; import org.apache.batik.transcoder.image.ImageTranscoder; +import org.apache.batik.transcoder.keys.FloatKey; import org.w3c.dom.Document; import org.w3c.dom.svg.SVGLength; @@ -66,7 +68,13 @@ import org.w3c.dom.svg.SVGLength; public class PDFTranscoder extends AbstractFOPTranscoder implements Configurable { - private Configuration cfg = null; + /** + * The key is used to specify the resolution for on-the-fly images generated + * due to complex effects like gradients and filters. + */ + public static final TranscodingHints.Key KEY_DEVICE_RESOLUTION = new FloatKey(); + + private Configuration cfg = null; /** Graphics2D instance that is used to paint to */ protected PDFDocumentGraphics2D graphics = null; @@ -143,6 +151,9 @@ public class PDFTranscoder extends AbstractFOPTranscoder //int h = (int)(height + 0.5); try { + if (hints.containsKey(KEY_DEVICE_RESOLUTION)) { + graphics.setDeviceDPI(((Float)hints.get(KEY_DEVICE_RESOLUTION)).floatValue()); + } graphics.setupDocument(output.getOutputStream(), w, h); graphics.setSVGDimension(width, height); -- 2.39.5