ASF Bugzilla – Attachment 22969 Details for
Bug 41959
External links are broken if pdf is encryped
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed way to approach this problem.
encrypted-links.diff (text/plain), 30.27 KB, created by
Jeremias Maerki
on 2008-12-01 02:24:21 UTC
(
hide
)
Description:
Proposed way to approach this problem.
Filename:
MIME Type:
Creator:
Jeremias Maerki
Created:
2008-12-01 02:24:21 UTC
Size:
30.27 KB
patch
obsolete
>Index: src/java/org/apache/fop/pdf/PDFAction.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFAction.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFAction.java (working copy) >@@ -20,20 +20,13 @@ > package org.apache.fop.pdf; > > /** >- * class representing an action object. >+ * Abstract base class for actions objects. > */ >-public abstract class PDFAction extends PDFObject { >+public abstract class PDFAction extends PDFDictionary { > >+ public PDFAction() { >+ super(); >+ put("Type", new PDFName("Action")); >+ } > >- /** >- * represent the action to call >- * this method should be implemented to return the action which gets >- * called by the Link Object. This could be a reference to another object >- * or the specific destination of the link >- * >- * @return the action to place next to /A within a Link >- */ >- public abstract String getAction(); >- >- > } >Index: src/java/org/apache/fop/pdf/PDFDictionary.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFDictionary.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFDictionary.java (working copy) >@@ -147,4 +147,35 @@ > writer.write(">>\n"); > } > >+ /** {@inheritDoc} */ >+ public int hashCode() { >+ final int prime = 31; >+ int result = 1; >+ result = prime * result + ((entries == null) ? 0 : entries.hashCode()); >+ return result; >+ } >+ >+ /** {@inheritDoc} */ >+ public boolean equals(Object obj) { >+ if (this == obj) { >+ return true; >+ } >+ if (obj == null) { >+ return false; >+ } >+ if (getClass() != obj.getClass()) { >+ return false; >+ } >+ PDFDictionary other = (PDFDictionary) obj; >+ if (entries == null) { >+ if (other.entries != null) { >+ return false; >+ } >+ } else if (!entries.equals(other.entries)) { >+ return false; >+ } >+ return true; >+ } >+ >+ > } >Index: src/java/org/apache/fop/pdf/PDFDocument.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFDocument.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFDocument.java (working copy) >@@ -900,7 +900,7 @@ > return outlineRoot; > } > >- outlineRoot = new PDFOutline(null, null, true); >+ outlineRoot = new PDFOutline(null, (PDFAction)null, true); > assignObjectNumber(outlineRoot); > addTrailerObject(outlineRoot); > root.setRootOutline(outlineRoot); >Index: src/java/org/apache/fop/pdf/PDFFactory.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFFactory.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFFactory.java (working copy) >@@ -956,8 +956,7 @@ > PDFGoTo gt = new PDFGoTo(page); > gt.setDestination(dest); > getDocument().addTrailerObject(gt); >- PDFInternalLink internalLink = new PDFInternalLink(gt.referencePDF()); >- link.setAction(internalLink); >+ link.setAction(gt); > > return link; > } >@@ -981,9 +980,8 @@ > link.setAction(getExternalAction(destination, false)); > } else { > // linkType is internal >- String goToReference = getGoToReference(destination, yoffset); >- PDFInternalLink internalLink = new PDFInternalLink(goToReference); >- link.setAction(internalLink); >+ PDFGoTo goTo = getPDFGoTo(destination, new Point2D.Float(0, yoffset)); >+ link.setAction(goTo); > } > > PDFLink oldlink = getDocument().findLink(link); >@@ -1147,6 +1145,7 @@ > * @param actionRef the action reference string to be placed after the /A > * @param showSubItems whether to initially display child outline items > * @return the new PDF outline object >+ * @deprecated use variant with PDFAction as parameter > */ > public PDFOutline makeOutline(PDFOutline parent, String label, > String actionRef, boolean showSubItems) { >@@ -1169,31 +1168,15 @@ > */ > public PDFOutline makeOutline(PDFOutline parent, String label, > PDFAction pdfAction, boolean showSubItems) { >- return pdfAction == null >- ? null >- : makeOutline(parent, label, pdfAction.getAction(), showSubItems); >+ PDFOutline pdfOutline = new PDFOutline(label, pdfAction, showSubItems); >+ if (parent != null) { >+ parent.addOutline(pdfOutline); >+ } >+ getDocument().registerObject(pdfOutline); >+ return pdfOutline; > } > >- // This one is obsolete now, at least it isn't called from anywhere inside FOP >- /** >- * Make an outline object and add it to the given outline >- * >- * @param parent parent PDFOutline object which may be null >- * @param label the title for the new outline object >- * @param destination the reference string for the action to go to >- * @param yoffset the yoffset on the destination page >- * @param showSubItems whether to initially display child outline items >- * @return the new PDF outline object >- */ >- public PDFOutline makeOutline(PDFOutline parent, String label, >- String destination, float yoffset, >- boolean showSubItems) { > >- String goToRef = getGoToReference(destination, yoffset); >- return makeOutline(parent, label, goToRef, showSubItems); >- } >- >- > /* ========================= fonts ===================================== */ > > /** >Index: src/java/org/apache/fop/pdf/PDFFileSpec.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFFileSpec.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFFileSpec.java (working copy) >@@ -20,71 +20,22 @@ > package org.apache.fop.pdf; > > /** >- * class representing a /FileSpec object. >+ * Class representing a /FileSpec object. > * > */ >-public class PDFFileSpec extends PDFObject { >+public class PDFFileSpec extends PDFDictionary { > > /** >- * the filename >- */ >- protected String filename; >- >- /** > * create a /FileSpec object. > * > * @param filename the filename represented by this object > */ > public PDFFileSpec(String filename) { >- >- /* generic creation of object */ > super(); > >- this.filename = filename; >+ put("Type", new PDFName("FileSpec")); >+ put("F", new PDFString(filename)); > } > >- /** >- * {@inheritDoc} >- */ >- public String toPDFString() { >- return getObjectID() >- + "<<\n/Type /FileSpec\n" >- + "/F (" + this.filename + ")\n" >- + ">>\nendobj\n"; >- } >- >- /* >- * example >- * 29 0 obj >- * << >- * /Type /FileSpec >- * /F (table1.pdf) >- * >> >- * endobj >- */ >- >- /** >- * Check if this equals another object. >- * >- * @param obj the object to compare >- * @return true if this equals other object >- */ >- public boolean equals(Object obj) { >- if (this == obj) { >- return true; >- } >- >- if (obj == null || !(obj instanceof PDFFileSpec)) { >- return false; >- } >- >- PDFFileSpec spec = (PDFFileSpec)obj; >- >- if (!spec.filename.equals(filename)) { >- return false; >- } >- >- return true; >- } > } > >Index: src/java/org/apache/fop/pdf/PDFGoTo.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFGoTo.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFGoTo.java (working copy) >@@ -20,18 +20,18 @@ > package org.apache.fop.pdf; > > import java.awt.geom.Point2D; >+import java.io.IOException; >+import java.io.OutputStream; >+import java.io.Writer; > > /** >- * class representing a /GoTo object. >+ * Class representing a /GoTo object. > * This can either have a Goto to a page reference and location > * or to a specified PDF reference string. > */ > public class PDFGoTo extends PDFAction { > >- /** >- * the pageReference >- */ >- private String pageReference; >+ private PDFReference pageReference; > private String destination = null; > private float xPosition = 0; > private float yPosition = 0; >@@ -40,12 +40,24 @@ > * create a /GoTo object. > * > * @param pageReference the pageReference represented by this object >+ * @deprecated Use constructor with PDFReference as parameter instead > */ > public PDFGoTo(String pageReference) { > /* generic creation of object */ >+ this(new PDFReference(pageReference)); >+ } >+ >+ /** >+ * Create a /GoTo object. >+ * >+ * @param pageReference the pageReference represented by this object >+ */ >+ public PDFGoTo(PDFReference pageReference) { >+ /* generic creation of object */ > super(); > >- this.pageReference = pageReference; >+ put("S", new PDFName("GoTo")); >+ setPageReference(pageReference); > } > > /** >@@ -53,12 +65,22 @@ > * > * @param pageReference the PDF reference to the target page > * @param position the target area's on-page coordinates in points >+ * @deprecated Use Constructor with PDFReference as parameter instead > */ > public PDFGoTo(String pageReference, Point2D position) { > /* generic creation of object */ >- super(); >+ this(new PDFReference(pageReference), position); >+ } > >- this.pageReference = pageReference; >+ /** >+ * create a /GoTo object. >+ * >+ * @param pageReference the PDF reference to the target page >+ * @param position the target area's on-page coordinates in points >+ */ >+ public PDFGoTo(PDFReference pageReference, Point2D position) { >+ /* generic creation of object */ >+ this(pageReference); > setPosition(position); > } > >@@ -66,8 +88,18 @@ > * Sets page reference after object has been created > * > * @param pageReference the new page reference to use >+ * @deprecated Use {@code #setPageReference(PDFReference)} instead > */ > public void setPageReference(String pageReference) { >+ this.pageReference = new PDFReference(pageReference); >+ } >+ >+ /** >+ * Sets page reference after object has been created >+ * >+ * @param pageReference the new page reference to use >+ */ >+ public void setPageReference(PDFReference pageReference) { > this.pageReference = pageReference; > } > >@@ -108,41 +140,23 @@ > destination = dest; > } > >- /** >- * Get the PDF reference for the GoTo action. >- * >- * @return the PDF reference for the action >- */ >- public String getAction() { >- return referencePDF(); >+ /** {@inheritDoc} */ >+ protected void writeDictionary(OutputStream out, Writer writer) >+ throws IOException { >+ fillDict(); >+ super.writeDictionary(out, writer); > } > >- /** >- * {@inheritDoc} >- */ >- public String toPDFString() { >- String dest; >+ private void fillDict() { > if (destination == null) { >- dest = "/D [" + this.pageReference + " /XYZ " + xPosition >- + " " + yPosition + " null]\n"; >+ put("D", new PDFArray(this, new Object[] {this.pageReference, >+ new PDFName("XYZ"), new Float(xPosition), new Float(yPosition), null})); > } else { >- dest = "/D [" + this.pageReference + " " + destination + "]\n"; >+ put("D", new PDFArray(this, new Object[] {this.pageReference, >+ destination})); > } >- return getObjectID() >- + "<< /Type /Action\n/S /GoTo\n" + dest >- + ">>\nendobj\n"; > } > >- /* >- * example >- * 29 0 obj >- * << >- * /S /GoTo >- * /D [23 0 R /FitH 600] >- * >> >- * endobj >- */ >- > /** > * Check if this equals another object. > * >@@ -150,38 +164,34 @@ > * @return true if this equals other object > */ > public boolean equals(Object obj) { >- if (this == obj) { >- return true; >- } >+ boolean e = super.equals(obj); >+ if (e && obj instanceof PDFGoTo) { >+ PDFGoTo gt = (PDFGoTo)obj; >+ if (gt.pageReference == null) { >+ if (pageReference != null) { >+ return false; >+ } >+ } else { >+ if (!gt.pageReference.equals(pageReference)) { >+ return false; >+ } >+ } > >- if (obj == null || !(obj instanceof PDFGoTo)) { >- return false; >- } >- >- PDFGoTo gt = (PDFGoTo)obj; >- >- if (gt.pageReference == null) { >- if (pageReference != null) { >- return false; >+ if (destination == null) { >+ if (!(gt.destination == null && gt.xPosition == xPosition >+ && gt.yPosition == yPosition)) { >+ return false; >+ } >+ } else { >+ if (!destination.equals(gt.destination)) { >+ return false; >+ } > } >- } else { >- if (!gt.pageReference.equals(pageReference)) { >- return false; >- } >- } > >- if (destination == null) { >- if (!(gt.destination == null && gt.xPosition == xPosition >- && gt.yPosition == yPosition)) { >- return false; >- } >+ return true; > } else { >- if (!destination.equals(gt.destination)) { >- return false; >- } >+ return false; > } >- >- return true; > } > } > >Index: src/java/org/apache/fop/pdf/PDFGoToRemote.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFGoToRemote.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFGoToRemote.java (working copy) >@@ -25,14 +25,6 @@ > public class PDFGoToRemote extends PDFAction { > > /** >- * the file specification >- */ >- private PDFFileSpec pdfFileSpec; >- private int pageReference = 0; >- private String destination = null; >- private boolean newWindow = false; >- >- /** > * Create an GoToR object. > * > * @param pdfFileSpec the fileSpec associated with the action >@@ -40,11 +32,7 @@ > * displayed in a new window > */ > public PDFGoToRemote(PDFFileSpec pdfFileSpec, boolean newWindow) { >- /* generic creation of object */ >- super(); >- >- this.pdfFileSpec = pdfFileSpec; >- this.newWindow = newWindow; >+ this(pdfFileSpec, 0, newWindow); > } > > /** >@@ -59,9 +47,11 @@ > /* generic creation of object */ > super(); > >- this.pdfFileSpec = pdfFileSpec; >- this.pageReference = page; >- this.newWindow = newWindow; >+ put("S", new PDFName("GoToR")); >+ setFileSpec(pdfFileSpec); >+ setNewWindow(newWindow); >+ put("D", new PDFArray(this, new Object[] {Integer.valueOf(page), >+ new PDFName("XYZ"), null, null, null})); > } > > /** >@@ -73,92 +63,21 @@ > * displayed in a new window > */ > public PDFGoToRemote(PDFFileSpec pdfFileSpec, String dest, boolean newWindow) { >- /* generic creation of object */ > super(); > >- this.pdfFileSpec = pdfFileSpec; >- this.destination = dest; >- this.newWindow = newWindow; >+ put("S", new PDFName("GoToR")); >+ setFileSpec(pdfFileSpec); >+ setNewWindow(newWindow); >+ put("D", dest); > } > >- /** >- * return the action string which will reference this object >- * >- * @return the action String >- */ >- public String getAction() { >- return this.referencePDF(); >+ public void setFileSpec(PDFFileSpec fileSpec) { >+ put("F", fileSpec); > } > >- /** >- * {@inheritDoc} >- */ >- public String toPDFString() { >- StringBuffer sb = new StringBuffer(64); >- sb.append(getObjectID()); >- sb.append("<<\n/S /GoToR\n/F "); >- sb.append(pdfFileSpec.referencePDF()); >- sb.append("\n"); >- >- if (destination != null) { >- sb.append("/D (").append(this.destination).append(")"); >- } else { >- sb.append("/D [ ").append(this.pageReference).append(" /XYZ null null null ]"); >- } >- >- if (newWindow) { >- sb.append("/NewWindow true"); >- } >- >- sb.append(" \n>>\nendobj\n"); >- >- return sb.toString(); >+ public void setNewWindow(boolean newWindow) { >+ put("NewWindow", Boolean.valueOf(newWindow)); > } > >- >- /* >- * example >- * 28 0 obj >- * << >- * /S /GoToR >- * /F 29 0 R >- * /D [ 0 /XYZ -6 797 null ] >- * >> >- * endobj >- */ >- >- /** >- * Check if this equals another object. >- * >- * @param obj the object to compare >- * @return true if this equals other object >- */ >- public boolean equals(Object obj) { >- if (this == obj) { >- return true; >- } >- >- if (obj == null || !(obj instanceof PDFGoToRemote)) { >- return false; >- } >- >- PDFGoToRemote remote = (PDFGoToRemote)obj; >- >- if (!remote.pdfFileSpec.referencePDF().equals(pdfFileSpec.referencePDF())) { >- return false; >- } >- >- if (destination != null) { >- if (!destination.equals(remote.destination)) { >- return false; >- } >- } else { >- if (pageReference != remote.pageReference) { >- return false; >- } >- } >- >- return (this.newWindow == remote.newWindow); >- } > } > >Index: src/java/org/apache/fop/pdf/PDFInternalLink.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFInternalLink.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFInternalLink.java (working copy) >@@ -1,55 +0,0 @@ >-/* >- * Licensed to the Apache Software Foundation (ASF) under one or more >- * contributor license agreements. See the NOTICE file distributed with >- * this work for additional information regarding copyright ownership. >- * The ASF licenses this file to You 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.pdf; >- >-/** >- * class used to create a PDF internal link >- */ >-public class PDFInternalLink extends PDFAction { >- >- private String goToReference; >- >- /** >- * create an internal link instance. >- * >- * @param goToReference the GoTo Reference to which the link should point >- */ >- public PDFInternalLink(String goToReference) { >- >- this.goToReference = goToReference; >- } >- >- /** >- * returns the action ncecessary for an internal link >- * >- * @return the action to place next to /A within a Link >- */ >- public String getAction() { >- return goToReference; >- } >- >- /** >- * {@inheritDoc} >- */ >- protected String toPDFString() { >- throw new UnsupportedOperationException("This method should not be called"); >- } >- >-} >Index: src/java/org/apache/fop/pdf/PDFLaunch.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFLaunch.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFLaunch.java (working copy) >@@ -22,47 +22,10 @@ > */ > public class PDFLaunch extends PDFAction { > >- private PDFFileSpec externalFileSpec; >- > public PDFLaunch(PDFFileSpec fileSpec) { >- this.externalFileSpec = fileSpec; >+ super(); >+ put("S", new PDFName("Launch")); >+ put("F", fileSpec); > } > >- public String getAction() { >- return this.referencePDF(); >- } >- >- public String toPDFString() { >- StringBuffer sb = new StringBuffer(64); >- sb.append(getObjectID()); >- sb.append("<<\n/S /Launch\n/F "); >- sb.append(externalFileSpec.referencePDF()); >- sb.append(" \n>>\nendobj\n"); >- >- return sb.toString(); >- } >- >- /** >- * Check if this equals another object. >- * >- * @param obj the object to compare >- * @return true if this equals other object >- */ >- public boolean equals(Object obj) { >- if (this == obj) { >- return true; >- } >- >- if (obj == null || !(obj instanceof PDFLaunch)) { >- return false; >- } >- >- PDFLaunch launch = (PDFLaunch) obj; >- >- if (!launch.externalFileSpec.referencePDF().equals(externalFileSpec.referencePDF())) { >- return false; >- } >- >- return true; >- } > } >Index: src/java/org/apache/fop/pdf/PDFLink.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFLink.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFLink.java (working copy) >@@ -21,11 +21,14 @@ > > // Java > import java.awt.geom.Rectangle2D; >+import java.io.IOException; >+import java.io.OutputStream; >+import java.io.Writer; > > /** >- * class representing an /Annot object of /Subtype /Link >+ * Class representing an /Annot object of /Subtype /Link > */ >-public class PDFLink extends PDFObject { >+public class PDFLink extends PDFDictionary { > /** > * Used to represent an external link. > */ >@@ -36,13 +39,6 @@ > */ > public static final int INTERNAL = 1; > >- private float ulx; >- private float uly; >- private float brx; >- private float bry; >- private String color; >- private PDFAction action; >- > /** > * create objects associated with a link annotation (GoToR) > * >@@ -51,12 +47,14 @@ > public PDFLink(Rectangle2D r) { > /* generic creation of PDF object */ > super(); >+ put("Type", new PDFName("Annot")); >+ put("Subtype", new PDFName("Link")); > >- this.ulx = (float)r.getX(); >- this.uly = (float)r.getY(); >- this.brx = (float)(r.getX() + r.getWidth()); >- this.bry = (float)(r.getY() + r.getHeight()); >- this.color = "0 0 0"; // just for now >+ put("Rect", new PDFArray(this, new double[] >+ {r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY()})); >+ put("C", new PDFArray(this, new int[] {0, 0, 0})); //just for now >+ put("Border", new PDFArray(this, new int[] {0, 0, 0})); //just for now >+ put("H", new PDFName("I")); //Invert > > } > >@@ -64,76 +62,23 @@ > * Set the pdf action for this link. > * @param action the pdf action that is activated for this link > */ >- public void setAction(PDFAction action) { >- this.action = action; >+ public void setAction(PDFObject action) { >+ put("A", action); > } > >- /** >- * {@inheritDoc} >- */ >- public String toPDFString() { >+ /** {@inheritDoc} */ >+ protected void writeDictionary(OutputStream out, Writer writer) >+ throws IOException { > getDocumentSafely().getProfile().verifyAnnotAllowed(); >- String fFlag = ""; > if (getDocumentSafely().getProfile().getPDFAMode().isPDFA1LevelB()) { > int f = 0; > f |= 1 << (3 - 1); //Print, bit 3 > f |= 1 << (4 - 1); //NoZoom, bit 4 > f |= 1 << (5 - 1); //NoRotate, bit 5 >- fFlag = "/F " + f; >+ put("F", f); > } >- String s = getObjectID() >- + "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ " >- + (ulx) + " " + (uly) + " " >- + (brx) + " " + (bry) + " ]\n" + "/C [ " >- + this.color + " ]\n" + "/Border [ 0 0 0 ]\n" + "/A " >- + this.action.getAction() + "\n" + "/H /I\n" >- + fFlag + "\n>>\nendobj\n"; >- return s; >+ super.writeDictionary(out, writer); > } > >- /* >- * example >- * 19 0 obj >- * << >- * /Type /Annot >- * /Subtype /Link >- * /Rect [ 176.032 678.48412 228.73579 692.356 ] >- * /C [ 0.86491 0.03421 0.02591 ] >- * /Border [ 0 0 1 ] >- * /A 28 0 R >- * /H /I >- * >> >- * endobj >- */ >- >- /** >- * Check if this equals another object. >- * >- * @param obj the object to compare >- * @return true if this equals other object >- */ >- public boolean equals(Object obj) { >- if (this == obj) { >- return true; >- } >- >- if (obj == null || !(obj instanceof PDFLink)) { >- return false; >- } >- >- PDFLink link = (PDFLink)obj; >- >- if (!((link.ulx == ulx) && (link.uly == uly) >- && (link.brx == brx) && (link.bry == bry))) { >- return false; >- } >- >- if (!(link.color.equals(color) >- && link.action.getAction().equals(action.getAction()))) { >- return false; >- } >- >- return true; >- } > } > >Index: src/java/org/apache/fop/pdf/PDFObject.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFObject.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFObject.java (working copy) >@@ -280,7 +280,13 @@ > * @return byte[] the encoded string > */ > protected byte[] encodeString(String string) { >- return encodeText(string); >+ if (getDocumentSafely().isEncryptionActive()) { >+ final byte[] buf = PDFDocument.encode(string); >+ return PDFText.escapeByteArray( >+ getDocument().getEncryption().encrypt(buf, this)); >+ } else { >+ return encode(PDFText.escapeText(string, false)); >+ } > } > > /** >@@ -324,6 +330,9 @@ > } else if (obj instanceof byte[]) { > writer.flush(); > encodeBinaryToHexString((byte[])obj, out); >+ } else if (obj instanceof PDFString) { >+ writer.flush(); >+ out.write(encodeString(((PDFString)obj).getText())); > } else { > writer.flush(); > out.write(encodeText(obj.toString())); >Index: src/java/org/apache/fop/pdf/PDFOutline.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFOutline.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFOutline.java (working copy) >@@ -83,6 +83,17 @@ > } > > /** >+ * Create a PDF outline with the title and action. >+ * >+ * @param title the title of the outline entry (can only be null for root Outlines obj) >+ * @param action the action for this outline >+ * @param openItem indicator of whether child items are visible or not >+ */ >+ public PDFOutline(String title, PDFAction action, boolean openItem) { >+ this(title, (action != null ? action.referencePDF() : null), openItem); >+ } >+ >+ /** > * Set the title of this Outline object. > * > * @param t the title of the outline >Index: src/java/org/apache/fop/pdf/PDFString.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFString.java (revision 0) >+++ src/java/org/apache/fop/pdf/PDFString.java (revision 0) >@@ -0,0 +1,53 @@ >+/* >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You 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.pdf; >+ >+/** >+ * Class representing a "string" object in PDF. Normally, the PDF library treats >+ * {@link java.lang.String} as "text string" objects. In some cases, however, the >+ * PDF spec requires "string" objects which need to be treated differently, >+ * especially in the case of encryption. For the formatting, see {@link PDFObject}. >+ */ >+public class PDFString { >+ >+ private final String text; >+ >+ /** >+ * Creates a new "string" object. >+ * @param text the text >+ */ >+ public PDFString(String text) { >+ this.text = text; >+ } >+ >+ /** >+ * Returns the string object's text. >+ * @return the text >+ */ >+ public String getText() { >+ return this.text; >+ } >+ >+ /** {@inheritDoc} */ >+ public String toString() { >+ return "(" + getText() + ")"; >+ } >+ >+} >Index: src/java/org/apache/fop/pdf/PDFUri.java >=================================================================== >--- src/java/org/apache/fop/pdf/PDFUri.java (revision 721769) >+++ src/java/org/apache/fop/pdf/PDFUri.java (working copy) >@@ -20,35 +20,19 @@ > package org.apache.fop.pdf; > > /** >- * class used to create a PDF Uri link >+ * Class used to create a PDF URI action (a link to an external resource/website). > */ > public class PDFUri extends PDFAction { > >- private String uri; >- > /** >- * create a Uri instance. >+ * Create a URI action. > * >- * @param uri the uri to which the link should point >+ * @param uri the URI to which the link should point > */ > public PDFUri(String uri) { >- this.uri = uri; >+ super(); >+ put("S", new PDFName("URI")); >+ put("URI", new PDFString(uri)); > } > >- /** >- * returns the action ncecessary for a uri >- * >- * @return the action to place next to /A within a Link >- */ >- public String getAction() { >- return "<< /URI (" + uri + ")\n/S /URI >>"; >- } >- >- /** >- * {@inheritDoc} >- */ >- public String toPDFString() { >- throw new UnsupportedOperationException("This method should not be called"); >- } >- > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 41959
:
22969
|
23053
|
23054