Author: ssteiner
Date: Mon Nov  6 11:56:26 2017
New Revision: 1814395

URL: http://svn.apache.org/viewvc?rev=1814395&view=rev
Log:
FOP-2756: Merged IF has wrong Table of Contents page links

Added:
    
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
   (with props)
Modified:
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFDocumentNavigationHandler.java
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFDocumentNavigationHandler.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFDocumentNavigationHandler.java?rev=1814395&r1=1814394&r2=1814395&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFDocumentNavigationHandler.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFDocumentNavigationHandler.java
 Mon Nov  6 11:56:26 2017
@@ -57,4 +57,5 @@ public interface IFDocumentNavigationHan
      */
     void addResolvedAction(AbstractAction action) throws IFException;
 
+    int getPageIndex();
 }

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=1814395&r1=1814394&r2=1814395&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
 Mon Nov  6 11:56:26 2017
@@ -918,6 +918,10 @@ implements IFConstants, IFPainter, IFDoc
         }
     }
 
+    public int getPageIndex() {
+        return -1;
+    }
+
     private void commitNavigation() throws IFException {
         Iterator iter = this.completeActions.iterator();
         while (iter.hasNext()) {

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=1814395&r1=1814394&r2=1814395&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
 Mon Nov  6 11:56:26 2017
@@ -123,6 +123,12 @@ public class DocumentNavigationHandler e
                     if (pageIndex < 0) {
                         location = null;
                     } else {
+                        if (hasNavigation()) {
+                            int currentPageIndex = navHandler.getPageIndex();
+                            if (currentPageIndex >= 0) {
+                                pageIndex = currentPageIndex;
+                            }
+                        }
                         final int x = XMLUtil
                                 .getAttributeAsInt(attributes, "x");
                         final int y = XMLUtil

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java?rev=1814395&r1=1814394&r2=1814395&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
 Mon Nov  6 11:56:26 2017
@@ -139,6 +139,10 @@ public class PDFDocumentNavigationHandle
         }
     }
 
+    public int getPageIndex() {
+        return documentHandler.getCurrentPage().getPageIndex();
+    }
+
     private PDFAction getAction(AbstractAction action) throws IFException {
         if (action == null) {
             return null;

Added: 
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=1814395&view=auto
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
 (added)
+++ 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
 Mon Nov  6 11:56:26 2017
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.extensions;
+
+import java.awt.Dimension;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.xmlgraphics.util.QName;
+
+import org.apache.fop.accessibility.StructureTreeElement;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
+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.DocumentNavigationExtensionConstants;
+import org.apache.fop.render.intermediate.extensions.DocumentNavigationHandler;
+import org.apache.fop.render.intermediate.extensions.GoToXYAction;
+import org.apache.fop.render.pdf.PDFDocumentHandler;
+import org.apache.fop.render.pdf.PDFDocumentNavigationHandler;
+
+public class DocumentNavigationHandlerTestCase {
+    @Test
+    public void testGotoXY() 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<GoToXYAction> goToXYActions = new ArrayList<GoToXYAction>();
+        PDFDocumentNavigationHandler pdfDocumentNavigationHandler = new 
PDFDocumentNavigationHandler(documentHandler) {
+            public void addResolvedAction(AbstractAction action) throws 
IFException {
+                super.addResolvedAction(action);
+                goToXYActions.add((GoToXYAction) action);
+            }
+        };
+        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");
+        navigationHandler.startElement(xy.getNamespaceURI(), 
xy.getLocalName(), null, attributes);
+        navigationHandler.endElement(xy.getNamespaceURI(), xy.getLocalName(), 
null);
+        documentHandler.endPage();
+
+        //Since user may merge IF files we want to use current page
+        Assert.assertEquals(goToXYActions.get(0).getPageIndex(), currentPage);
+    }
+}

Propchange: 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
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