return link;
}
+ /**
+ * Make an internal link.
+ *
+ * @param rect the hotspot position in absolute coordinates
+ * @param dest the position destination
+ * @param isNamedDestination set to true if dest param is a named destination
+ * @return the new PDF link object
+ */
+ public PDFLink makeLink(Rectangle2D rect, String dest, boolean isNamedDestination) {
+ PDFLink link = new PDFLink(rect);
+ getDocument().registerObject(link);
+
+ PDFAction pdfAction = new PDFGoTo(dest, isNamedDestination);
+ getDocument().registerObject(pdfAction);
+
+ link.setAction(pdfAction);
+
+ return link;
+ }
+
/**
* Make a {@link PDFLink} object
*
private String destination;
private float xPosition;
private float yPosition;
+ private boolean isNamedDestination;
+
+ /**
+ * create a /GoTo object.
+ *
+ * @param destination name of the destination
+ * @param isNamedDestination set to true if the destination is a named destination
+ */
+ public PDFGoTo(String destination, boolean isNamedDestination) {
+ super();
+ this.destination = destination;
+ this.isNamedDestination = isNamedDestination;
+ }
/**
* create a /GoTo object.
+ " " + yPosition + " null]\n";
} else {
dest = "/D [" + this.pageReference + " " + destination + "]\n";
+ if (this.isNamedDestination) {
+ dest = "/D (" + this.destination + ")\n";
+ } else {
+ dest = "/D [" + this.pageReference + " " + destination + "]\n";
+ }
}
return "<< /Type /Action\n/S /GoTo\n" + dest + ">>";
}
}
}
- return true;
+ return (isNamedDestination == gt.isNamedDestination);
}
}
import java.util.StringTokenizer;
import org.apache.batik.gvt.CompositeGraphicsNode;
+import org.apache.fop.pdf.PDFLink;
/**
* <p>A graphics node that represents an image described as a graphics node.</p>
destination = "" + x + " " + y + " "
+ (x + width) + " " + (y + height);
+ } else if (destination.startsWith("#")) {
+ pdfg.addLink(getBounds(), transform, destination, PDFLink.INTERNAL);
+ } else {
+ pdfg.addLink(getBounds(), transform, destination, type);
}
- pdfg.addLink(getBounds(), transform, destination, type);
}
}
}
Rectangle rect = b.getBounds();
if (linkType != PDFLink.EXTERNAL) {
- String pdfdest = "/FitR " + dest;
- resourceContext.addAnnotation(
- pdfDoc.getFactory().makeLink(rect, getPageReference().toString(), pdfdest));
+ if (dest.startsWith("#")) {
+ String idDest = dest.substring(1);
+ resourceContext.addAnnotation(
+ pdfDoc.getFactory().makeLink(rect, idDest, true));
+ } else {
+ String pdfdest = "/FitR " + dest;
+ resourceContext.addAnnotation(
+ pdfDoc.getFactory().makeLink(rect, getPageReference().toString(), pdfdest));
+ }
} else {
resourceContext.addAnnotation(
pdfDoc.getFactory().makeLink(rect, dest, linkType, 0));
package org.apache.fop.pdf;
import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
assertEquals(expectedString, pdfAction.toPDFString());
}
+
+ @Test
+ public void testMakeLink() {
+ PDFDocument doc = new PDFDocument("");
+ PDFFactory pdfFactory = new PDFFactory(doc);
+ Rectangle2D rect = new Rectangle(10,20);
+ PDFLink link = pdfFactory.makeLink(rect, "dest", true);
+
+ String expectedString = "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ "
+ + "0.0 0.0 10.0 20.0 ]\n/C [ 0 0 0 ]\n"
+ + "/Border [ 0 0 0 ]\n" + "/A 1 0 R"
+ + "\n/H /I\n\n>>";
+
+ assertEquals(expectedString, link.toPDFString());
+ }
}
--- /dev/null
+package org.apache.fop.pdf;\r
+\r
+import org.junit.Test;\r
+\r
+import static junit.framework.TestCase.assertEquals;\r
+\r
+public class PDFGoToTestCase {\r
+\r
+ @Test\r
+ public void test() {\r
+ PDFGoTo pdfGoTo = new PDFGoTo("destination", true);\r
+ String expected = "<< /Type /Action\n"\r
+ + "/S /GoTo\n/D (destination)\n"\r
+ + ">>";\r
+ assertEquals(expected, pdfGoTo.toPDFString());\r
+ }\r
+}\r