keiron 01/08/14 07:50:31 Modified: src/org/apache/fop/render/pdf PDFRenderer.java src/org/apache/fop/svg PDFAElementBridge.java PDFANode.java PDFDocumentGraphics2D.java PDFGraphics2D.java PDFTranscoder.java Log: adds support for svg links to be put into the pdf Revision Changes Path 1.82 +9 -4 xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java Index: PDFRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v retrieving revision 1.81 retrieving revision 1.82 diff -u -r1.81 -r1.82 --- PDFRenderer.java 2001/08/13 07:52:21 1.81 +++ PDFRenderer.java 2001/08/14 14:50:30 1.82 @@ -1,5 +1,5 @@ /* - * $Id: PDFRenderer.java,v 1.81 2001/08/13 07:52:21 keiron Exp $ + * $Id: PDFRenderer.java,v 1.82 2001/08/14 14:50:30 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -417,7 +417,7 @@ 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 @@ + e.getMessage()); } + currentAnnotList = graphics.getAnnotList(); + currentStream.add("Q\n"); } @@ -740,8 +742,10 @@ 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 @@ dest, linkType)); } } + currentAnnotList = null; } else { // just to be on the safe side currentAnnotList = null; 1.3 +7 -4 xml-fop/src/org/apache/fop/svg/PDFAElementBridge.java Index: PDFAElementBridge.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFAElementBridge.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PDFAElementBridge.java 2001/07/30 20:29:34 1.2 +++ PDFAElementBridge.java 2001/08/14 14:50:30 1.3 @@ -1,5 +1,5 @@ /* - * $Id: PDFAElementBridge.java,v 1.2 2001/07/30 20:29:34 tore Exp $ + * $Id: PDFAElementBridge.java,v 1.3 2001/08/14 14:50:30 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -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 @@ * @author <a href="mailto:[EMAIL PROTECTED]">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 GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { PDFANode aNode = (PDFANode)super.createGraphicsNode(ctx, e); + aNode.setDestination(((SVGAElement)e).getHref().getBaseVal()); + aNode.setTransform(transform); return aNode; } 1.3 +23 -1 xml-fop/src/org/apache/fop/svg/PDFANode.java Index: PDFANode.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFANode.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PDFANode.java 2001/07/30 20:29:34 1.2 +++ PDFANode.java 2001/08/14 14:50:30 1.3 @@ -1,5 +1,5 @@ /* - * $Id: PDFANode.java,v 1.2 2001/07/30 20:29:34 tore Exp $ + * $Id: PDFANode.java,v 1.3 2001/08/14 14:50:30 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -11,9 +11,11 @@ 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 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a> */ public class PDFANode extends CompositeGraphicsNode { + String destination; + AffineTransform transform; /** * Constructs a new empty <tt>PDFANode</tt>. @@ -28,6 +32,17 @@ 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 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); + } } } 1.11 +5 -2 xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java Index: PDFDocumentGraphics2D.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- PDFDocumentGraphics2D.java 2001/08/02 10:07:14 1.10 +++ PDFDocumentGraphics2D.java 2001/08/14 14:50:30 1.11 @@ -1,5 +1,5 @@ /* - * $Id: PDFDocumentGraphics2D.java,v 1.10 2001/08/02 10:07:14 keiron Exp $ + * $Id: PDFDocumentGraphics2D.java,v 1.11 2001/08/14 14:50:30 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -31,7 +31,7 @@ * <tt>PDFGraphics2D</tt>. * * @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a> - * @version $Id: PDFDocumentGraphics2D.java,v 1.10 2001/08/02 10:07:14 keiron Exp $ + * @version $Id: PDFDocumentGraphics2D.java,v 1.11 2001/08/14 14:50:30 keiron Exp $ * @see org.apache.fop.svg.PDFGraphics2D */ public class PDFDocumentGraphics2D extends PDFGraphics2D { @@ -131,6 +131,9 @@ 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); } 1.14 +41 -3 xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java Index: PDFGraphics2D.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- PDFGraphics2D.java 2001/08/09 13:29:31 1.13 +++ PDFGraphics2D.java 2001/08/14 14:50:30 1.14 @@ -1,5 +1,5 @@ /* - * $Id: PDFGraphics2D.java,v 1.13 2001/08/09 13:29:31 keiron Exp $ + * $Id: PDFGraphics2D.java,v 1.14 2001/08/14 14:50:30 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -40,7 +40,7 @@ * implementing a <tt>Graphic2D</tt> piece-meal. * * @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a> - * @version $Id: PDFGraphics2D.java,v 1.13 2001/08/09 13:29:31 keiron Exp $ + * @version $Id: PDFGraphics2D.java,v 1.14 2001/08/14 14:50:30 keiron Exp $ * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D */ public class PDFGraphics2D extends AbstractGraphics2D { @@ -51,6 +51,11 @@ */ protected PDFDocument pdfDoc; + /** + * the current annotation list to add annotations to + */ + PDFAnnotList currentAnnotList = null; + protected FontState fontState; /** @@ -129,6 +134,31 @@ } /** + * 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 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); 1.9 +5 -4 xml-fop/src/org/apache/fop/svg/PDFTranscoder.java Index: PDFTranscoder.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFTranscoder.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PDFTranscoder.java 2001/08/06 06:21:02 1.8 +++ PDFTranscoder.java 2001/08/14 14:50:30 1.9 @@ -1,5 +1,5 @@ /* - * $Id: PDFTranscoder.java,v 1.8 2001/08/06 06:21:02 keiron Exp $ + * $Id: PDFTranscoder.java,v 1.9 2001/08/14 14:50:30 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -124,7 +124,7 @@ * millimeter conversion factor. * * @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a> - * @version $Id: PDFTranscoder.java,v 1.8 2001/08/06 06:21:02 keiron Exp $ + * @version $Id: PDFTranscoder.java,v 1.9 2001/08/14 14:50:30 keiron Exp $ */ public class PDFTranscoder extends XMLAbstractTranscoder { @@ -181,6 +181,8 @@ 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 @@ 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)); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]