aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-11-10 15:01:49 +0000
committerJeremias Maerki <jeremias@apache.org>2005-11-10 15:01:49 +0000
commit13a3f8ffed7661ad52f61195fc8dc6f5fcf202ab (patch)
tree4d893c747233e43c31b8589871df851e8f45f043
parentd5b1a063526e5560af3ab579974f1238a08525e0 (diff)
downloadxmlgraphics-fop-13a3f8ffed7661ad52f61195fc8dc6f5fcf202ab.tar.gz
xmlgraphics-fop-13a3f8ffed7661ad52f61195fc8dc6f5fcf202ab.zip
Bugzilla #37305:
Better approach to higher resolution on-the-fly images generated by Batik. Submitted by: Thomas Deweese <deweese.at.apache.org> 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
-rw-r--r--src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java41
-rw-r--r--src/java/org/apache/fop/svg/PDFTranscoder.java13
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;
@@ -183,6 +194,22 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
}
/**
+ * 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);