Author: ssteiner
Date: Tue Apr  3 10:46:05 2018
New Revision: 1828216

URL: http://svn.apache.org/viewvc?rev=1828216&view=rev
Log:
FOP-2782: Bookmarks point to last page when run via IF

Modified:
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
    
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java?rev=1828216&r1=1828215&r2=1828216&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
 Tue Apr  3 10:46:05 2018
@@ -123,7 +123,7 @@ public class DocumentNavigationHandler e
                     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 e
         }
     }
 
+    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)) {

Modified: 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java?rev=1828216&r1=1828215&r2=1828216&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
 Tue Apr  3 10:46:05 2018
@@ -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 DocumentNavigationHandlerTe
         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);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org

Reply via email to