aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2018-10-23 11:56:21 +0000
committerSimon Steiner <ssteiner@apache.org>2018-10-23 11:56:21 +0000
commit6066ae5d664b120eb321ffa5dd9da1c06595d083 (patch)
tree4f54669dccae02c2570b0b8fdf9313b0569a665b /fop-core
parent7951774f1754564fb27f775ce3eccbdf71e3e062 (diff)
downloadxmlgraphics-fop-6066ae5d664b120eb321ffa5dd9da1c06595d083.tar.gz
xmlgraphics-fop-6066ae5d664b120eb321ffa5dd9da1c06595d083.zip
FOP-2823: page-index-relative not added when forwards link used to same location
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1844636 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java2
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java10
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/PageIndexContext.java26
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java20
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java19
5 files changed, 52 insertions, 25 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java
index aa94abef0..6f5163a11 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFContext.java
@@ -38,7 +38,7 @@ import org.apache.fop.apps.FOUserAgent;
* implementations will just ignore all foreign attributes for most elements. That's why the
* main IF interfaces are not burdened with this.
*/
-public class IFContext {
+public class IFContext implements PageIndexContext {
private FOUserAgent userAgent;
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java
index aeafc45a9..471068370 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFRenderer.java
@@ -396,7 +396,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
this.documentMetadata = metadata.getMetadata();
}
- private GoToXYAction getGoToActionForID(String targetID, final int pageIndex) {
+ private GoToXYAction getGoToActionForID(String targetID, int pageIndex) {
// Already a GoToXY present for this target? If not, create.
GoToXYAction action = (GoToXYAction)actionSet.get(targetID);
//GoToXYAction action = (GoToXYAction)idGoTos.get(targetID);
@@ -407,14 +407,10 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
Point position = (Point)idPositions.get(targetID);
// can the GoTo already be fully filled in?
if (pageIndex >= 0 && position != null) {
- action = new GoToXYAction(targetID, pageIndex, position, new GoToXYAction.PageIndexRelative() {
- public int getPageIndexRelative() {
- return pageIndex - documentHandler.getContext().getPageIndex();
- }
- });
+ action = new GoToXYAction(targetID, pageIndex, position, documentHandler.getContext());
} else {
// Not complete yet, can't use getPDFGoTo:
- action = new GoToXYAction(targetID, pageIndex, null, null);
+ action = new GoToXYAction(targetID, pageIndex, null, documentHandler.getContext());
unfinishedGoTos.add(action);
}
action = (GoToXYAction)actionSet.put(action);
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/PageIndexContext.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/PageIndexContext.java
new file mode 100644
index 000000000..09c42c4a5
--- /dev/null
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/PageIndexContext.java
@@ -0,0 +1,26 @@
+/*
+ * 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.intermediate;
+
+/**
+ * Interface to get the page index
+ */
+public interface PageIndexContext {
+ int getPageIndex();
+}
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 c0b78d977..69743708d 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
@@ -35,6 +35,7 @@ import org.apache.fop.accessibility.StructureTreeElement;
import org.apache.fop.fo.extensions.InternalElementMapping;
import org.apache.fop.render.intermediate.IFDocumentNavigationHandler;
import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.PageIndexContext;
import org.apache.fop.util.XMLUtil;
/**
@@ -119,7 +120,7 @@ public class DocumentNavigationHandler extends DefaultHandler
} else {
String id = attributes.getValue("id");
int pageIndex = XMLUtil.getAttributeAsInt(attributes, "page-index");
- final int pageIndexRelative = XMLUtil.getAttributeAsInt(attributes, "page-index-relative", 0);
+ int pageIndexRelative = XMLUtil.getAttributeAsInt(attributes, "page-index-relative", 0);
final Point location;
if (pageIndex < 0) {
location = null;
@@ -136,11 +137,8 @@ public class DocumentNavigationHandler extends DefaultHandler
.getAttributeAsInt(attributes, "y");
location = new Point(x, y);
}
- action = new GoToXYAction(id, pageIndex, location, new GoToXYAction.PageIndexRelative() {
- public int getPageIndexRelative() {
- return pageIndexRelative;
- }
- });
+ action = new GoToXYAction(id, pageIndex, location,
+ new PageIndexRelative(pageIndex, pageIndexRelative));
}
if (structureTreeElement != null) {
action.setStructureTreeElement(structureTreeElement);
@@ -175,6 +173,16 @@ public class DocumentNavigationHandler extends DefaultHandler
}
}
+ static class PageIndexRelative implements PageIndexContext {
+ private int pageIndex;
+ PageIndexRelative(int pageIndex, int pageIndexRelative) {
+ this.pageIndex = (pageIndexRelative * -1) + pageIndex;
+ }
+ public int getPageIndex() {
+ return pageIndex;
+ }
+ }
+
private boolean inBookmark() {
return !objectStack.empty() && objectStack.peek() instanceof Bookmark;
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java
index 6fdee58da..9c7176ab6 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java
@@ -25,6 +25,7 @@ import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import org.apache.fop.render.intermediate.PageIndexContext;
import org.apache.fop.util.XMLUtil;
/**
@@ -33,7 +34,7 @@ import org.apache.fop.util.XMLUtil;
public class GoToXYAction extends AbstractAction implements DocumentNavigationExtensionConstants {
private int pageIndex = -1;
- private PageIndexRelative pageIndexRelative;
+ private PageIndexContext ifContext;
private Point targetLocation;
/**
@@ -52,7 +53,7 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx
* @param targetLocation the absolute location on the page (coordinates in millipoints),
* or null, if the position isn't known, yet
*/
- public GoToXYAction(String id, int pageIndex, Point targetLocation, PageIndexRelative pageIndexRelative) {
+ public GoToXYAction(String id, int pageIndex, Point targetLocation, PageIndexContext ifContext) {
setID(id);
if (pageIndex < 0 && targetLocation != null) {
throw new IllegalArgumentException(
@@ -60,11 +61,7 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx
}
setPageIndex(pageIndex);
setTargetLocation(targetLocation);
- this.pageIndexRelative = pageIndexRelative;
- }
-
- public interface PageIndexRelative {
- int getPageIndexRelative();
+ this.ifContext = ifContext;
}
/**
@@ -153,11 +150,11 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx
atts.addAttribute("", "id", "id", XMLUtil.CDATA, getID());
atts.addAttribute("", "page-index", "page-index",
XMLUtil.CDATA, Integer.toString(pageIndex));
- if (pageIndexRelative != null) {
- int pageIndexRelativeInt = pageIndexRelative.getPageIndexRelative();
- if (pageIndexRelativeInt < 0) {
+ if (ifContext != null && pageIndex >= 0) {
+ int pageIndexRelative = pageIndex - ifContext.getPageIndex();
+ if (pageIndexRelative < 0) {
atts.addAttribute("", "page-index-relative", "page-index-relative",
- XMLUtil.CDATA, Integer.toString(pageIndexRelativeInt));
+ XMLUtil.CDATA, Integer.toString(pageIndexRelative));
}
}
atts.addAttribute("", "x", "x", XMLUtil.CDATA,