diff options
author | Simon Steiner <ssteiner@apache.org> | 2018-04-03 10:46:05 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2018-04-03 10:46:05 +0000 |
commit | fbdd70cf1980956555dec8c3b3502fc1d2dab217 (patch) | |
tree | b4d8c37eb5f8a661fe6011e2375645131d511616 /fop-core | |
parent | a7f1b37afd5b7a814960a4d6e78589b3aa3839a2 (diff) | |
download | xmlgraphics-fop-fbdd70cf1980956555dec8c3b3502fc1d2dab217.tar.gz xmlgraphics-fop-fbdd70cf1980956555dec8c3b3502fc1d2dab217.zip |
FOP-2782: Bookmarks point to last page when run via IF
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1828216 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
2 files changed, 52 insertions, 1 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java index fe7a744f0..5221ad04b 100644 --- a/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java +++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java @@ -123,7 +123,7 @@ public class DocumentNavigationHandler extends DefaultHandler if (pageIndex < 0) { location = null; } else { - if (hasNavigation()) { + if (hasNavigation() && !inBookmark()) { int currentPageIndex = navHandler.getPageIndex(); if (currentPageIndex >= 0) { pageIndex = currentPageIndex; @@ -170,6 +170,10 @@ public class DocumentNavigationHandler extends DefaultHandler } } + private boolean inBookmark() { + return !objectStack.empty() && objectStack.peek() instanceof Bookmark; + } + /** {@inheritDoc} */ public void endElement(String uri, String localName, String qName) throws SAXException { if (NAMESPACE.equals(uri)) { 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 ee020aec7..523da388f 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 @@ -46,6 +46,8 @@ import org.apache.fop.fonts.FontInfo; import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.render.intermediate.extensions.AbstractAction; +import org.apache.fop.render.intermediate.extensions.Bookmark; +import org.apache.fop.render.intermediate.extensions.BookmarkTree; import org.apache.fop.render.intermediate.extensions.DocumentNavigationExtensionConstants; import org.apache.fop.render.intermediate.extensions.DocumentNavigationHandler; import org.apache.fop.render.intermediate.extensions.GoToXYAction; @@ -126,4 +128,49 @@ public class DocumentNavigationHandlerTestCase { Assert.assertEquals(pageLink.size(), 2); Assert.assertFalse(pageLink.get(0).equals(pageLink.get(1))); } + + @Test + public void testBookmarkGotoXY() throws SAXException, IFException { + FOUserAgent ua = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent(); + PDFDocumentHandler documentHandler = new PDFDocumentHandler(new IFContext(ua)); + documentHandler.setResult(new StreamResult(new ByteArrayOutputStream())); + documentHandler.setFontInfo(new FontInfo()); + documentHandler.startDocument(); + + documentHandler.startPage(0, "", "", new Dimension()); + documentHandler.endPage(); + + int currentPage = 1; + documentHandler.startPage(currentPage, "", "", new Dimension()); + + final List<BookmarkTree> trees = new ArrayList<BookmarkTree>(); + PDFDocumentNavigationHandler pdfDocumentNavigationHandler = new PDFDocumentNavigationHandler(documentHandler) { + public void renderBookmarkTree(BookmarkTree tree) throws IFException { + trees.add(tree); + } + }; + DocumentNavigationHandler navigationHandler = new DocumentNavigationHandler(pdfDocumentNavigationHandler, + new HashMap<String, StructureTreeElement>()); + Attributes attributes = mock(Attributes.class); + when(attributes.getValue("page-index")).thenReturn("0"); + when(attributes.getValue("x")).thenReturn("0"); + when(attributes.getValue("y")).thenReturn("0"); + + for (QName q : Arrays.asList(DocumentNavigationExtensionConstants.BOOKMARK_TREE, + DocumentNavigationExtensionConstants.BOOKMARK, + DocumentNavigationExtensionConstants.GOTO_XY)) { + navigationHandler.startElement(q.getNamespaceURI(), q.getLocalName(), null, attributes); + } + for (QName q : Arrays.asList(DocumentNavigationExtensionConstants.GOTO_XY, + DocumentNavigationExtensionConstants.BOOKMARK, + DocumentNavigationExtensionConstants.BOOKMARK_TREE)) { + navigationHandler.endElement(q.getNamespaceURI(), q.getLocalName(), null); + } + + documentHandler.endPage(); + + Bookmark b = (Bookmark) trees.get(0).getBookmarks().get(0); + GoToXYAction a = (GoToXYAction) b.getAction(); + Assert.assertEquals(a.getPageIndex(), 0); + } } |