]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3125: NPE when using broken link and PDF 1.5
authorSimon Steiner <ssteiner@apache.org>
Thu, 30 Mar 2023 06:45:01 +0000 (07:45 +0100)
committerSimon Steiner <ssteiner@apache.org>
Thu, 30 Mar 2023 06:45:01 +0000 (07:45 +0100)
fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
fop-core/src/test/resources/org/apache/fop/render/extensions/linkmissingdest.if.xml [new file with mode: 0644]

index ae2053061fc71a33cbb677537ff6ddd0cfef8ee4..09eb12c541560c5ce9af668d917eb151951d7ead 100644 (file)
@@ -183,6 +183,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
 
     /** {@inheritDoc} */
     public void endDocument() throws IFException {
+        documentNavigationHandler.registerIncompleteActions();
         pdfDoc.getResources().addFonts(pdfDoc, fontInfo);
         try {
             if (pdfDoc.isLinearizationEnabled()) {
index 005c82a6f26b24ec3182febe2e112cdbde5c2f46..5521399804f0319efa3a1b414a8caa61a16ce7b9 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFFactory;
 import org.apache.fop.pdf.PDFGoTo;
 import org.apache.fop.pdf.PDFLink;
+import org.apache.fop.pdf.PDFObject;
 import org.apache.fop.pdf.PDFOutline;
 import org.apache.fop.pdf.PDFReference;
 import org.apache.fop.pdf.PDFStructElem;
@@ -214,4 +215,9 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler
         return action.getID();
     }
 
+    public void registerIncompleteActions() {
+        for (Object action : incompleteActions.values()) {
+            getPDFDoc().addObject((PDFObject) action);
+        }
+    }
 }
index 1b8efd1125b297e0b54be0ca4c9e4d3747d99eb5..0578d27e7649d1ec342e6ab65c1daeaa68d6edb4 100644 (file)
@@ -109,13 +109,14 @@ public class DocumentNavigationHandlerTestCase {
     @Test
     public void testGotoXYMergedIF() throws Exception {
         InputStream ifXml = getClass().getResourceAsStream("link.if.xml");
-        ByteArrayOutputStream pdf = iFToPDF(ifXml);
+        ByteArrayOutputStream pdf = iFToPDF(ifXml, "<fop/>");
         Assert.assertTrue(pdf.toString().contains("/S /GoTo"));
     }
 
-    private ByteArrayOutputStream iFToPDF(InputStream is) throws Exception {
+    private ByteArrayOutputStream iFToPDF(InputStream is, String fopxconf) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        FOUserAgent userAgent = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
+        FOUserAgent userAgent = FopFactory.newInstance(new File(".").toURI(),
+                new ByteArrayInputStream(fopxconf.getBytes())).newFOUserAgent();
         Transformer transformer = TransformerFactory.newInstance().newTransformer();
         Source src = new StreamSource(is);
         IFDocumentHandler documentHandler
@@ -255,4 +256,19 @@ public class DocumentNavigationHandlerTestCase {
         GoToXYAction a = (GoToXYAction) b.getAction();
         Assert.assertEquals(a.getPageIndex(), 0);
     }
+
+    @Test
+    public void testGotoXYMissingDestIF() throws Exception {
+        InputStream ifXml = getClass().getResourceAsStream("linkmissingdest.if.xml");
+        String fopxconf = "<fop version=\"1.0\">\n"
+                + "  <accessibility>true</accessibility>\n"
+                + "  <renderers>\n"
+                + "    <renderer mime=\"application/pdf\">\n"
+                + "      <version>1.5</version>\n"
+                + "    </renderer>\n"
+                + "  </renderers>\n"
+                + "</fop>";
+        ByteArrayOutputStream pdf = iFToPDF(ifXml, fopxconf);
+        Assert.assertTrue(pdf.toString().contains("/S /GoTo"));
+    }
 }
diff --git a/fop-core/src/test/resources/org/apache/fop/render/extensions/linkmissingdest.if.xml b/fop-core/src/test/resources/org/apache/fop/render/extensions/linkmissingdest.if.xml
new file mode 100644 (file)
index 0000000..f2e6eac
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document xmlns="http://xmlgraphics.apache.org/fop/intermediate" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:nav="http://xmlgraphics.apache.org/fop/intermediate/document-navigation" xmlns:foi="http://xmlgraphics.apache.org/fop/internal">
+<header>
+<locale xml:lang="en"/>
+<x:xmpmeta xmlns:x="adobe:ns:meta/">
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
+<dc:creator>creator</dc:creator>
+<dc:title>Document title</dc:title>
+</rdf:Description>
+</rdf:RDF>
+</x:xmpmeta>
+</header>
+<page-sequence xml:lang="en" xml:space="preserve">
+<structure-tree xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+<fo:flow xmlns:fo="http://www.w3.org/1999/XSL/Format" flow-name="xsl-region-body">
+<fo:block>
+<marked-content foi:struct-id="0"/>
+<fo:basic-link fox:alt-text="" foi:struct-id="1">
+<marked-content foi:struct-id="2" foi:struct-ref="1"/>
+</fo:basic-link>
+<marked-content foi:struct-id="3"/>
+</fo:block>
+</fo:flow>
+</structure-tree>
+<page index="0" name="1" page-master-name="FirstPage" width="612000" height="792000">
+<page-header/>
+<content>
+<viewport transform="translate(54000,108000)" width="504000" height="630000">
+<font family="any" style="normal" weight="400" variant="normal" size="12000" color="#000000"/>
+<text x="0" y="9996" foi:struct-ref="2">test</text>
+</viewport>
+</content>
+<page-trailer>
+<nav:link rect="54000 109800 16668 10800">
+<nav:goto-xy id="1" page-index="-1" x="0" y="0"/>
+</nav:link>
+</page-trailer>
+</page>
+</page-sequence>
+<trailer/>
+</document>