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;
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
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);
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;
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;
//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);