import org.apache.fop.render.XMLHandler;
import org.apache.fop.render.RendererContext;
import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFNumber;
import org.apache.fop.pdf.PDFPage;
import org.apache.fop.pdf.PDFState;
import org.apache.fop.pdf.PDFStream;
import org.apache.fop.pdf.PDFResourceContext;
+import org.apache.fop.svg.PDFBridgeContext;
import org.apache.fop.svg.PDFTextElementBridge;
import org.apache.fop.svg.PDFAElementBridge;
import org.apache.fop.svg.PDFGraphics2D;
import java.io.OutputStream;
+import org.apache.batik.bridge.Bridge;
import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.ViewBox;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.gvt.GraphicsNode;
+import org.apache.batik.util.SVGConstants;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGSVGElement;
int xOffset = pdfInfo.currentXPosition;
int yOffset = pdfInfo.currentYPosition;
- SVGUserAgent ua
- = new SVGUserAgent(context.getUserAgent().getPixelUnitToMillimeter(),
- new AffineTransform());
+ log.debug("Generating SVG at "
+ + context.getUserAgent().getResolution()
+ + "dpi.");
+
+ final int uaResolution = 72; //Should not be changed
+ final float deviceResolution
+ = context.getUserAgent().getResolution();
+ SVGUserAgent ua = new SVGUserAgent(25.4f / uaResolution, new AffineTransform());
GVTBuilder builder = new GVTBuilder();
- BridgeContext ctx = new BridgeContext(ua);
- PDFTextElementBridge tBridge = new PDFTextElementBridge(pdfInfo.fi);
- ctx.putBridge(tBridge);
-
- PDFAElementBridge aBridge = new PDFAElementBridge();
- // to get the correct transform we need to use the PDFState
- AffineTransform transform = pdfInfo.pdfState.getTransform();
- transform.translate(xOffset / 1000f, yOffset / 1000f);
- aBridge.setCurrentTransform(transform);
- ctx.putBridge(aBridge);
-
+
+ //TODO This AffineTransform here has to be fixed!!!
+ AffineTransform linkTransform = pdfInfo.pdfState.getTransform();
+ linkTransform.translate(xOffset / 1000f, yOffset / 1000f);
+
+ final boolean strokeText = false;
+ BridgeContext ctx = new PDFBridgeContext(ua,
+ (strokeText ? null : pdfInfo.fi),
+ linkTransform);
+
GraphicsNode root;
try {
root = builder.build(ctx, doc);
pdfInfo.currentFontSize);
graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
pdfInfo.pdfState.push();
- transform = new AffineTransform();
+ AffineTransform transform = new AffineTransform();
// scale to viewbox
transform.translate(xOffset / 1000f, yOffset / 1000f);
+
+ if (deviceResolution != uaResolution) {
+ //Scale for higher resolution on-the-fly images from Batik
+ double s = uaResolution / deviceResolution;
+ at.scale(s, s);
+ pdfInfo.currentStream.add("" + PDFNumber.doubleOut(s) + " 0 0 "
+ + PDFNumber.doubleOut(s) + " 0 0 cm\n");
+ graphics.scale(1 / s, 1 / s);
+ }
+
pdfInfo.pdfState.setTransform(transform);
graphics.setPDFState(pdfInfo.pdfState);
graphics.setOutputStream(pdfInfo.outputStream);
--- /dev/null
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.svg;
+
+import java.awt.geom.AffineTransform;
+
+import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.UserAgent;
+import org.apache.fop.fonts.FontInfo;
+
+/**
+ * BridgeContext which registers the custom bridges for PDF output.
+ */
+public class PDFBridgeContext extends BridgeContext {
+
+ /** The font list. */
+ private final FontInfo fontInfo;
+
+ private AffineTransform linkTransform;
+
+ /**
+ * Constructs a new bridge context.
+ * @param userAgent the user agent
+ * @param fontInfo the font list for the text painter, may be null in which case text is
+ * painted as shapes
+ * @param linkTransform AffineTransform to properly place links, may be null
+ */
+ public PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo,
+ AffineTransform linkTransform) {
+ super(userAgent);
+ this.fontInfo = fontInfo;
+ this.linkTransform = linkTransform;
+ }
+
+ /**
+ * Constructs a new bridge context.
+ * @param userAgent the user agent
+ * @param fontInfo the font list for the text painter, may be null in which case text is
+ * painted as shapes
+ */
+ public PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo) {
+ this(userAgent, fontInfo, null);
+ }
+
+ /** @see org.apache.batik.bridge.BridgeContext#registerSVGBridges() */
+ public void registerSVGBridges() {
+ super.registerSVGBridges();
+
+ if (fontInfo != null) {
+ putBridge(new PDFTextElementBridge(fontInfo));
+ }
+
+ PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
+ if (linkTransform != null) {
+ pdfAElementBridge.setCurrentTransform(linkTransform);
+ } else {
+ pdfAElementBridge.setCurrentTransform(new AffineTransform());
+ }
+ putBridge(pdfAElementBridge);
+
+ putBridge(new PDFImageElementBridge());
+ }
+
+}
\ No newline at end of file
package org.apache.fop.svg;
import java.awt.Color;
-import java.awt.geom.AffineTransform;
import java.io.IOException;
import org.apache.avalon.framework.configuration.Configurable;
/** @see org.apache.batik.transcoder.SVGAbstractTranscoder#createBridgeContext() */
protected BridgeContext createBridgeContext() {
- BridgeContext ctx = new PDFBridgeContext(userAgent);
-
+ BridgeContext ctx = new PDFBridgeContext(userAgent, graphics.getFontInfo());
return ctx;
}
- /**
- * BridgeContext which registers the custom bridges for PDF output.
- */
- public class PDFBridgeContext extends BridgeContext {
- /**
- * Constructs a new bridge context.
- * @param userAgent the user agent
- */
- public PDFBridgeContext(UserAgent userAgent) {
- super(userAgent);
- }
-
- /** @see org.apache.batik.bridge.BridgeContext#registerSVGBridges() */
- public void registerSVGBridges() {
- super.registerSVGBridges();
-
- /*
- boolean stroke = true;
- if (hints.containsKey(KEY_STROKE_TEXT)) {
- stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
- }
- if (!stroke) {
- textPainter = new PDFTextPainter(graphics.getFontInfo());
- ctx.setTextPainter(textPainter);
- }
- */
-
- putBridge(new PDFTextElementBridge(graphics.getFontInfo()));
-
- PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
- pdfAElementBridge.setCurrentTransform(new AffineTransform());
- putBridge(pdfAElementBridge);
-
- putBridge(new PDFImageElementBridge());
- }
-
- }
-
}