summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2017-11-27 11:25:42 +0000
committerSimon Steiner <ssteiner@apache.org>2017-11-27 11:25:42 +0000
commita6cb59fb424d2ce7da4aa4f6d855d36f28893b44 (patch)
tree1158db7b55383edbbec70ff68ff8f57d686f04d3
parentd086a61db20f1ff4db85ae97724ac96dfc27a9dd (diff)
downloadxmlgraphics-fop-a6cb59fb424d2ce7da4aa4f6d855d36f28893b44.tar.gz
xmlgraphics-fop-a6cb59fb424d2ce7da4aa4f6d855d36f28893b44.zip
FOP-2760: Make unique links for merged IF
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1816435 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java14
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java41
2 files changed, 52 insertions, 3 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
index e9622309a..005c82a6f 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
@@ -147,7 +147,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler
if (action == null) {
return null;
}
- PDFAction pdfAction = (PDFAction)this.completeActions.get(action.getID());
+ PDFAction pdfAction = (PDFAction)this.completeActions.get(getCompleteID(action));
if (pdfAction != null) {
return pdfAction;
} else if (action instanceof GoToXYAction) {
@@ -175,7 +175,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler
//Some PDF actions are pooled
getPDFDoc().registerObject(pdfAction);
}
- this.completeActions.put(action.getID(), pdfAction);
+ this.completeActions.put(getCompleteID(action), pdfAction);
return pdfAction;
} else {
throw new UnsupportedOperationException("Unsupported action type: "
@@ -202,8 +202,16 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler
//Queue this object now that it's complete
getPDFDoc().addObject(pdfGoTo);
- this.completeActions.put(action.getID(), pdfGoTo);
+ this.completeActions.put(getCompleteID(action), pdfGoTo);
}
}
+ private String getCompleteID(AbstractAction action) {
+ if (action instanceof GoToXYAction && action.isComplete()) {
+ int extra = ((GoToXYAction) action).getPageIndex();
+ return action.getID() + "_" + extra;
+ }
+ return action.getID();
+ }
+
}
diff --git a/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java b/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
index 390bcbe50..ee020aec7 100644
--- a/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
@@ -22,7 +22,9 @@ import java.awt.Dimension;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import javax.xml.transform.stream.StreamResult;
@@ -85,4 +87,43 @@ public class DocumentNavigationHandlerTestCase {
//Since user may merge IF files we want to use current page
Assert.assertEquals(goToXYActions.get(0).getPageIndex(), currentPage);
}
+
+ @Test
+ public void testGotoXYUniqueLinks() throws IFException, SAXException {
+ FOUserAgent ua = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
+ PDFDocumentHandler documentHandler = new PDFDocumentHandler(new IFContext(ua));
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ documentHandler.setResult(new StreamResult(bos));
+ documentHandler.setFontInfo(new FontInfo());
+ documentHandler.startDocument();
+
+ PDFDocumentNavigationHandler pdfDocumentNavigationHandler = new PDFDocumentNavigationHandler(documentHandler);
+ DocumentNavigationHandler navigationHandler = new DocumentNavigationHandler(pdfDocumentNavigationHandler,
+ new HashMap<String, StructureTreeElement>());
+ QName xy = DocumentNavigationExtensionConstants.GOTO_XY;
+
+ Attributes attributes = mock(Attributes.class);
+ when(attributes.getValue("page-index")).thenReturn("0");
+ when(attributes.getValue("x")).thenReturn("0");
+ when(attributes.getValue("y")).thenReturn("0");
+
+ documentHandler.startPage(0, "", "", new Dimension());
+ navigationHandler.startElement(xy.getNamespaceURI(), xy.getLocalName(), null, attributes);
+ navigationHandler.endElement(xy.getNamespaceURI(), xy.getLocalName(), null);
+ documentHandler.endPage();
+ documentHandler.startPage(1, "", "", new Dimension());
+ navigationHandler.startElement(xy.getNamespaceURI(), xy.getLocalName(), null, attributes);
+ navigationHandler.endElement(xy.getNamespaceURI(), xy.getLocalName(), null);
+ documentHandler.endPage();
+
+ Iterator<String> i = Arrays.asList(bos.toString().split("\n")).iterator();
+ List<String> pageLink = new ArrayList<String>();
+ while (i.hasNext()) {
+ if (i.next().equals("/S /GoTo")) {
+ pageLink.add(i.next());
+ }
+ }
+ Assert.assertEquals(pageLink.size(), 2);
+ Assert.assertFalse(pageLink.get(0).equals(pageLink.get(1)));
+ }
}