keiron 01/09/07 02:26:17
Modified: src/org/apache/fop/pdf PDFDocument.java PDFGoTo.java
src/org/apache/fop/svg PDFANode.java PDFGraphics2D.java
Log:
this handles viewBox links in svg better
the target position and scaling are wrong
Revision Changes Path
1.29 +52 -1 xml-fop/src/org/apache/fop/pdf/PDFDocument.java
Index: PDFDocument.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- PDFDocument.java 2001/08/30 23:21:40 1.28
+++ PDFDocument.java 2001/09/07 09:26:16 1.29
@@ -1,5 +1,5 @@
/*
- * $Id: PDFDocument.java,v 1.28 2001/08/30 23:21:40 gears Exp $
+ * $Id: PDFDocument.java,v 1.29 2001/09/07 09:26:16 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.
@@ -150,6 +150,11 @@
protected Hashtable xObjectsMap = new Hashtable();
/**
+ * the objects themselves
+ */
+ protected Vector pendingLinks = null;
+
+ /**
* creates an empty PDF document <p>
*
* The constructor creates a /Root and /Pages object to
@@ -941,6 +946,20 @@
PDFPage page = new PDFPage(++this.objectcount, resources, contents,
pagewidth, pageheight);
+ if(pendingLinks != null) {
+ for(Enumeration e = pendingLinks.elements(); e.hasMoreElements(); ) {
+ PendingLink pl = (PendingLink)e.nextElement();
+ PDFGoTo gt = new PDFGoTo(++this.objectcount,
+ page.referencePDF());
+ gt.setDestination(pl.dest);
+ addTrailerObject(gt);
+ PDFInternalLink internalLink =
+ new PDFInternalLink(gt.referencePDF());
+ pl.link.setAction(internalLink);
+ }
+ pendingLinks = null;
+ }
+
if (currentPage != null) {
Enumeration enum = currentPage.getIDList().elements();
while (enum.hasMoreElements()) {
@@ -1026,6 +1045,38 @@
public void addTrailerObject(PDFObject object) {
this.trailerObjects.addElement(object);
+ }
+
+ class PendingLink {
+ PDFLink link;
+ String dest;
+ }
+
+ public PDFLink makeLinkCurrentPage(Rectangle rect, String dest) {
+ PDFLink link = new PDFLink(++this.objectcount, rect);
+ this.objects.addElement(link);
+ PendingLink pl = new PendingLink();
+ pl.link = link;
+ pl.dest = dest;
+ if(pendingLinks == null) {
+ pendingLinks = new Vector();
+ }
+ pendingLinks.addElement(pl);
+
+ return link;
+ }
+
+ public PDFLink makeLink(Rectangle rect, String page, String dest) {
+ PDFLink link = new PDFLink(++this.objectcount, rect);
+ this.objects.addElement(link);
+
+ PDFGoTo gt = new PDFGoTo(++this.objectcount, page);
+ gt.setDestination(dest);
+ addTrailerObject(gt);
+ PDFInternalLink internalLink = new PDFInternalLink(gt.referencePDF());
+ link.setAction(internalLink);
+
+ return link;
}
/**
1.6 +14 -5 xml-fop/src/org/apache/fop/pdf/PDFGoTo.java
Index: PDFGoTo.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFGoTo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PDFGoTo.java 2001/07/30 20:29:30 1.5
+++ PDFGoTo.java 2001/09/07 09:26:16 1.6
@@ -1,5 +1,5 @@
/*
- * $Id: PDFGoTo.java,v 1.5 2001/07/30 20:29:30 tore Exp $
+ * $Id: PDFGoTo.java,v 1.6 2001/09/07 09:26:16 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.
@@ -17,6 +17,7 @@
* the pageReference
*/
protected String pageReference;
+ protected String destination = null;
protected float xPosition = 0, yPosition = 0;
/**
@@ -55,7 +56,9 @@
this.yPosition = (yPosition / 1000f);
}
-
+ public void setDestination(String dest) {
+ destination = dest;
+ }
/**
* Sets the x Position to jump to
@@ -77,10 +80,16 @@
* @return the PDF string
*/
public byte[] toPDF() {
- String p = new String(this.number + " " + this.generation
- + " obj\n<<\n/S /GoTo\n" + "/D ["
+ if(destination == null) {
+ destination = "/D ["
+ this.pageReference + " /XYZ " + xPosition
- + " " + yPosition + " null]\n"
+ + " " + yPosition + " null]\n";
+ } else {
+ destination = "/D ["
+ + this.pageReference + " " + destination + "]\n";
+ }
+ String p = new String(this.number + " " + this.generation
+ + " obj\n<<\n/S /GoTo\n" + destination
+ ">>\nendobj\n");
return p.getBytes();
}
1.4 +38 -6 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PDFANode.java 2001/08/14 14:50:30 1.3
+++ PDFANode.java 2001/09/07 09:26:16 1.4
@@ -1,5 +1,5 @@
/*
- * $Id: PDFANode.java,v 1.3 2001/08/14 14:50:30 keiron Exp $
+ * $Id: PDFANode.java,v 1.4 2001/09/07 09:26:16 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.
@@ -17,6 +17,8 @@
import java.awt.geom.Dimension2D;
import java.awt.geom.AffineTransform;
+import java.util.StringTokenizer;
+
/**
* A graphics node that represents an image described as a graphics node.
*
@@ -55,15 +57,45 @@
PDFGraphics2D pdfg = (PDFGraphics2D)g2d;
int type = org.apache.fop.layout.LinkSet.EXTERNAL;
Shape outline = getOutline(rc);
- //Rectangle bounds =
transform.createTransformedShape(outline).getBounds();
+ if(destination.startsWith("#svgView(viewBox(")) {
+ String nums = destination.substring(18, destination.length() -
2);
+ float x = 0;
+ float y = 0;
+ float width = 0;
+ float height;
+ int count = 0;
+ try {
+ StringTokenizer st = new StringTokenizer(nums, ",");
+ while(st.hasMoreTokens()) {
+ String tok = st.nextToken();
+ count++;
+ switch(count) {
+ case 1:
+ x = Float.parseFloat(tok);
+ break;
+ case 2:
+ y = Float.parseFloat(tok);
+ break;
+ case 3:
+ width = Float.parseFloat(tok);
+ break;
+ case 4:
+ height = Float.parseFloat(tok);
+ break;
+ default:
+ break;
+ }
+ }
+ } catch(Exception e) {
+ }
+ // these numbers need conversion to current
+ // svg position and scaled for the page
+ destination = "" + x + " " + y + " " + 200 / width;
+ }
pdfg.addLink(outline, transform, destination, type);
}
}
}
-
- //
- // Properties methods
- //
}
1.18 +9 -4 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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- PDFGraphics2D.java 2001/08/30 08:50:00 1.17
+++ PDFGraphics2D.java 2001/09/07 09:26:16 1.18
@@ -1,5 +1,5 @@
/*
- * $Id: PDFGraphics2D.java,v 1.17 2001/08/30 08:50:00 keiron Exp $
+ * $Id: PDFGraphics2D.java,v 1.18 2001/09/07 09:26:16 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.
@@ -43,7 +43,7 @@
* implementing a <tt>Graphic2D</tt> piece-meal.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a>
- * @version $Id: PDFGraphics2D.java,v 1.17 2001/08/30 08:50:00 keiron Exp $
+ * @version $Id: PDFGraphics2D.java,v 1.18 2001/09/07 09:26:16 keiron Exp $
* @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
*/
public class PDFGraphics2D extends AbstractGraphics2D {
@@ -158,8 +158,13 @@
rect.y = rect.y * 1000;
rect.height = -rect.height * 1000;
rect.width = rect.width * 1000;
- currentAnnotList.addLink(pdfDoc.makeLink(rect,
- dest, linkType));
+ if(linkType == LinkSet.EXTERNAL) {
+ String pdfdest = "/XYZ " + dest;
+ currentAnnotList.addLink(pdfDoc.makeLinkCurrentPage(rect, pdfdest));
+ } else {
+ currentAnnotList.addLink(pdfDoc.makeLink(rect,
+ dest, linkType));
+ }
}
public PDFAnnotList getAnnotList() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]