diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 11 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFAElementBridge.java | 9 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFANode.java | 22 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFDocumentGraphics2D.java | 3 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFGraphics2D.java | 40 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTranscoder.java | 5 |
6 files changed, 81 insertions, 9 deletions
diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 01dacee24..3fa74f812 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -417,7 +417,7 @@ public class PDFRenderer extends PrintRenderer { currentYPosition); graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); graphics.setRenderingHints(rc.getRenderingHints()); - aBridge.setPDFGraphics2D(graphics); + aBridge.setCurrentTransform(new AffineTransform(sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f)); try { root = builder.build(ctx, doc); root.paint(graphics, rc); @@ -427,6 +427,8 @@ public class PDFRenderer extends PrintRenderer { + e.getMessage()); } + currentAnnotList = graphics.getAnnotList(); + currentStream.add("Q\n"); } @@ -740,8 +742,10 @@ public class PDFRenderer extends PrintRenderer { page.getWidth() / 1000, page.getHeight() / 1000, page); - if (page.hasLinks()) { - currentAnnotList = this.pdfDoc.makeAnnotList(); + if (page.hasLinks() || currentAnnotList != null) { + if(currentAnnotList == null) { + currentAnnotList = this.pdfDoc.makeAnnotList(); + } currentPage.setAnnotList(currentAnnotList); Enumeration e = page.getLinkSets().elements(); @@ -758,6 +762,7 @@ public class PDFRenderer extends PrintRenderer { dest, linkType)); } } + currentAnnotList = null; } else { // just to be on the safe side currentAnnotList = null; diff --git a/src/org/apache/fop/svg/PDFAElementBridge.java b/src/org/apache/fop/svg/PDFAElementBridge.java index 560e8fb13..dfc79bf74 100644 --- a/src/org/apache/fop/svg/PDFAElementBridge.java +++ b/src/org/apache/fop/svg/PDFAElementBridge.java @@ -8,6 +8,7 @@ package org.apache.fop.svg; import java.awt.Cursor; +import java.awt.geom.AffineTransform; import org.apache.batik.bridge.*; @@ -29,15 +30,15 @@ import org.w3c.dom.svg.SVGAElement; * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a> */ public class PDFAElementBridge extends AbstractGraphicsNodeBridge { - PDFGraphics2D pdfDoc; + AffineTransform transform; /** * Constructs a new bridge for the <a> element. */ public PDFAElementBridge() {} - public void setPDFGraphics2D(PDFGraphics2D doc) { - this.pdfDoc = doc; + public void setCurrentTransform(AffineTransform tf) { + transform = tf; } /** @@ -64,6 +65,8 @@ public class PDFAElementBridge extends AbstractGraphicsNodeBridge { */ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { PDFANode aNode = (PDFANode)super.createGraphicsNode(ctx, e); + aNode.setDestination(((SVGAElement)e).getHref().getBaseVal()); + aNode.setTransform(transform); return aNode; } diff --git a/src/org/apache/fop/svg/PDFANode.java b/src/org/apache/fop/svg/PDFANode.java index e604e74d0..d7c8c9c08 100644 --- a/src/org/apache/fop/svg/PDFANode.java +++ b/src/org/apache/fop/svg/PDFANode.java @@ -11,9 +11,11 @@ import org.apache.batik.gvt.*; import java.awt.Graphics2D; import java.awt.Shape; +import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.awt.geom.Point2D; import java.awt.geom.Dimension2D; +import java.awt.geom.AffineTransform; /** * A graphics node that represents an image described as a graphics node. @@ -21,6 +23,8 @@ import java.awt.geom.Dimension2D; * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a> */ public class PDFANode extends CompositeGraphicsNode { + String destination; + AffineTransform transform; /** * Constructs a new empty <tt>PDFANode</tt>. @@ -28,6 +32,17 @@ public class PDFANode extends CompositeGraphicsNode { public PDFANode() {} /** + * Set the destination String. + */ + public void setDestination(String dest) { + destination = dest; + } + + public void setTransform(AffineTransform tf) { + transform = tf; + } + + /** * Paints this node if visible. * * @param g2d the Graphics2D to use @@ -36,6 +51,13 @@ public class PDFANode extends CompositeGraphicsNode { public void paint(Graphics2D g2d, GraphicsNodeRenderContext rc) { if (isVisible) { super.paint(g2d, rc); + if(g2d instanceof PDFGraphics2D) { + PDFGraphics2D pdfg = (PDFGraphics2D)g2d; + int type = org.apache.fop.layout.LinkSet.EXTERNAL; + Shape outline = getOutline(rc); + //Rectangle bounds = transform.createTransformedShape(outline).getBounds(); + pdfg.addLink(outline, transform, destination, type); + } } } diff --git a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java index 05f230a34..d0b63a3de 100644 --- a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -131,6 +131,9 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { PDFResources pdfResources = this.pdfDoc.getResources(); PDFPage currentPage = this.pdfDoc.makePage(pdfResources, pdfStream, width, height, null); + if(currentAnnotList != null) { + currentPage.setAnnotList(currentAnnotList); + } if (fontInfo != null) { FontSetup.addToResources(this.pdfDoc, fontInfo); } diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index e60c749aa..fa3e713dd 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -51,6 +51,11 @@ public class PDFGraphics2D extends AbstractGraphics2D { */ protected PDFDocument pdfDoc; + /** + * the current annotation list to add annotations to + */ + PDFAnnotList currentAnnotList = null; + protected FontState fontState; /** @@ -129,6 +134,31 @@ public class PDFGraphics2D extends AbstractGraphics2D { } /** + * This is a pdf specific method used to add a link to the + * pdf document. + */ + public void addLink(Shape bounds, AffineTransform trans, String dest, int linkType) { + if(currentAnnotList == null) { + currentAnnotList = pdfDoc.makeAnnotList(); + } + AffineTransform at = getTransform(); + Shape b = at.createTransformedShape(bounds); + b = trans.createTransformedShape(b); + Rectangle rect = b.getBounds(); + // this handles the / 1000 in PDFLink + rect.x = rect.x * 1000; + rect.y = rect.y * 1000; + rect.height = -rect.height * 1000; + rect.width = rect.width * 1000; + currentAnnotList.addLink(pdfDoc.makeLink(rect, + dest, linkType)); + } + + public PDFAnnotList getAnnotList() { + return currentAnnotList; + } + + /** * Draws as much of the specified image as is currently available. * The image is drawn with its top-left corner at * (<i>x</i>, <i>y</i>) in this graphics context's coordinate @@ -882,10 +912,18 @@ public class PDFGraphics2D extends AbstractGraphics2D { */ public void fill(Shape s) { // System.err.println("fill"); + Color c; + c = getBackground(); + if(c.getAlpha() == 0) { + c = getColor(); + if(c.getAlpha() == 0) { + return; + } + } currentStream.write("q\n"); Shape imclip = getClip(); writeClip(imclip); - Color c = getColor(); + c = getColor(); applyColor(c, true); c = getBackground(); applyColor(c, false); diff --git a/src/org/apache/fop/svg/PDFTranscoder.java b/src/org/apache/fop/svg/PDFTranscoder.java index 1a37558ad..74197263d 100644 --- a/src/org/apache/fop/svg/PDFTranscoder.java +++ b/src/org/apache/fop/svg/PDFTranscoder.java @@ -181,6 +181,8 @@ public class PDFTranscoder extends XMLAbstractTranscoder { GraphicsNodeRenderContext rc = getRenderContext(stroke); BridgeContext ctx = new BridgeContext(userAgent, rc); PDFAElementBridge pdfAElementBridge = new PDFAElementBridge(); + AffineTransform currentTransform = new AffineTransform(1, 0, 0, 1, 0, 0); + pdfAElementBridge.setCurrentTransform(currentTransform); ctx.putBridge(pdfAElementBridge); GraphicsNode gvtRoot; try { @@ -265,14 +267,13 @@ public class PDFTranscoder extends XMLAbstractTranscoder { PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(stroke, output.getOutputStream(), w, h); graphics.setSVGDimension(docWidth, docHeight); - + currentTransform.setTransform(1, 0, 0, -1, 0, height); if (!stroke) { TextPainter textPainter = null; textPainter = new PDFTextPainter(graphics.getFontState()); rc.setTextPainter(textPainter); } - pdfAElementBridge.setPDFGraphics2D(graphics); if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) { graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR)); } |