git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1844636 13f79535-47bb-0310-9956-ffa450edef68pull/13/head
@@ -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; | |||
@@ -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); |
@@ -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(); | |||
} |
@@ -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; | |||
} |
@@ -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, |
@@ -0,0 +1,54 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!-- | |||
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$ --> | |||
<testcase> | |||
<info> | |||
<p> | |||
This test checks a same page internal-destination on a fo:basic-link which references a prior block. | |||
</p> | |||
</info> | |||
<fo> | |||
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> | |||
<fo:layout-master-set> | |||
<fo:simple-page-master margin-right="1cm" margin-left="1cm" margin-bottom="0.3cm" margin-top="1cm" page-width="21cm" page-height="29.7cm" master-name="all"> | |||
<fo:region-body/> | |||
</fo:simple-page-master> | |||
</fo:layout-master-set> | |||
<fo:page-sequence format="1" id="th_default_sequence1" master-reference="all"> | |||
<fo:flow flow-name="xsl-region-body"> | |||
<fo:block> | |||
<fo:block> | |||
<fo:basic-link internal-destination="N1004A">1 Cross-references </fo:basic-link> | |||
</fo:block> | |||
<fo:block id="N1004A"> | |||
<fo:block id="c1001"/>1 Cross-references</fo:block> | |||
<fo:block break-before="page"> | |||
<fo:basic-link color="blue" internal-destination="c1001">STATIC SECTION 1 reference </fo:basic-link> | |||
</fo:block> | |||
</fo:block> | |||
</fo:flow> | |||
</fo:page-sequence> | |||
</fo:root> | |||
</fo> | |||
<if-checks xmlns:if="http://xmlgraphics.apache.org/fop/intermediate" xmlns:n="http://xmlgraphics.apache.org/fop/intermediate/document-navigation"> | |||
<eval expected="0" xpath="//if:page[@index=0]/if:page-trailer/n:link/n:goto-xy/@page-index"/> | |||
<eval expected="" xpath="//if:page[@index=0]/if:page-trailer/n:link/n:goto-xy/@page-index-relative"/> | |||
<eval expected="0" xpath="//if:page[@index=1]/if:page-trailer/n:link/n:goto-xy/@page-index"/> | |||
<eval expected="-1" xpath="//if:page[@index=1]/if:page-trailer/n:link/n:goto-xy/@page-index-relative"/> | |||
</if-checks> | |||
</testcase> |