diff options
author | Keiron Liddle <keiron@apache.org> | 2001-09-07 09:26:16 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-09-07 09:26:16 +0000 |
commit | 745d0e9b985c4103f295f43eda63697a2bd194a8 (patch) | |
tree | 9102d7a31143f25506cc9875167792de2aee2f30 | |
parent | 08f39c78ca6447b59b38c1e0c5c18962e4577c1e (diff) | |
download | xmlgraphics-fop-745d0e9b985c4103f295f43eda63697a2bd194a8.tar.gz xmlgraphics-fop-745d0e9b985c4103f295f43eda63697a2bd194a8.zip |
this handles viewBox links in svg better
the target position and scaling are wrong
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194453 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/org/apache/fop/pdf/PDFDocument.java | 51 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFGoTo.java | 17 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFANode.java | 42 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFGraphics2D.java | 9 |
4 files changed, 108 insertions, 11 deletions
diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index b30280dc2..6a1027000 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -150,6 +150,11 @@ public class PDFDocument { 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 @@ public class PDFDocument { 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()) { @@ -1028,6 +1047,38 @@ public class PDFDocument { 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; + } + /** Ensure there is room in the locations xref for the number of objects that have been created. diff --git a/src/org/apache/fop/pdf/PDFGoTo.java b/src/org/apache/fop/pdf/PDFGoTo.java index bd32c58d5..f8dd65a8e 100644 --- a/src/org/apache/fop/pdf/PDFGoTo.java +++ b/src/org/apache/fop/pdf/PDFGoTo.java @@ -17,6 +17,7 @@ public class PDFGoTo extends PDFAction { * the pageReference */ protected String pageReference; + protected String destination = null; protected float xPosition = 0, yPosition = 0; /** @@ -55,7 +56,9 @@ public class PDFGoTo extends PDFAction { this.yPosition = (yPosition / 1000f); } - + public void setDestination(String dest) { + destination = dest; + } /** * Sets the x Position to jump to @@ -77,10 +80,16 @@ public class PDFGoTo extends PDFAction { * @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(); } diff --git a/src/org/apache/fop/svg/PDFANode.java b/src/org/apache/fop/svg/PDFANode.java index d7c8c9c08..c9c88028f 100644 --- a/src/org/apache/fop/svg/PDFANode.java +++ b/src/org/apache/fop/svg/PDFANode.java @@ -17,6 +17,8 @@ import java.awt.geom.Point2D; 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 @@ public class PDFANode extends CompositeGraphicsNode { 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 - // - } diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index e8b3c4a0e..5d89d2ea4 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -158,8 +158,13 @@ public class PDFGraphics2D extends AbstractGraphics2D { 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() { |