Browse Source

FOP-2465: Fix links to/from 'last' page

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1685165 13f79535-47bb-0310-9956-ffa450edef68
pull/39/head
Matthias Reischenbacher 9 years ago
parent
commit
15f61950c5

+ 18
- 0
src/java/org/apache/fop/area/IDTracker.java View File

@@ -238,4 +238,22 @@ public class IDTracker {
// add Resolvable object to this HashSet
todo.add(res);
}

/**
* Replace all id locations pointing to the old page view port with a new one. This is
* necessary when a layouted page is replaced with a new one (e.g. last page handling).
* @param oldPageViewPort old page view port
* @param newPageViewPort new page view port
*/
public void replacePageViewPort(PageViewport oldPageViewPort, PageViewport newPageViewPort) {

for (List<PageViewport> viewPortList : idLocations.values()) {
for (int i = 0, len = viewPortList.size(); i < len; i++) {
PageViewport currPV = viewPortList.get(i);
if (currPV == oldPageViewPort) {
viewPortList.set(i, newPageViewPort);
}
}
}
}
}

+ 13
- 0
src/java/org/apache/fop/area/PageViewport.java View File

@@ -277,6 +277,19 @@ public class PageViewport extends AreaTreeObject implements Resolvable {
return idFirsts.contains(id);
}

/**
* Replace the old view port. This copies all ID related fields from the old view port
* to the current one.
* @param oldViewPort old view port
*/
public void replace(PageViewport oldViewPort) {
this.idFirsts.addAll(oldViewPort.idFirsts);
this.unresolvedIDRefs.putAll(oldViewPort.unresolvedIDRefs);
if (oldViewPort.pendingResolved != null) {
this.pendingResolved.putAll(oldViewPort.pendingResolved);
}
}

/**
* Add an idref to this page.
* All idrefs found for child areas of this {@link PageViewport} are added

+ 5
- 0
src/java/org/apache/fop/layoutmgr/PageProvider.java View File

@@ -25,6 +25,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.fop.area.AreaTreeHandler;
import org.apache.fop.area.PageViewport;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.SimplePageMaster;
@@ -311,7 +312,11 @@ public class PageProvider implements Constants {
}
if (replace) {
discardCacheStartingWith(intIndex);
PageViewport oldPageVP = page.getPageViewport();
page = cacheNextPage(index, isBlank, isLastPage, this.spanAllForCurrentElementList);
PageViewport newPageVP = page.getPageViewport();
newPageVP.replace(oldPageVP);
this.areaTreeHandler.getIDTracker().replacePageViewPort(oldPageVP, newPageVP);
}
return page;
}

+ 80
- 0
test/layoutengine/standard-testcases/basic_link_to_last_page.xml View File

@@ -0,0 +1,80 @@
<?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 links to and from the last page.</p>
</info>
<fo>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master margin="2cm" master-name="odd" page-height="297mm" page-width="210mm">
<fo:region-body column-count="2" column-gap="28pt"/>
</fo:simple-page-master>
<fo:simple-page-master margin="2cm" master-name="even" page-height="297mm" page-width="210mm">
<fo:region-body column-count="2" column-gap="28pt"/>
</fo:simple-page-master>
<fo:simple-page-master margin="2cm" master-name="last" page-height="297mm" page-width="210mm">
<fo:region-body column-count="2" column-gap="28pt"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="basicPSM">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="last" odd-or-even="any" page-position="last"/>
<fo:conditional-page-master-reference master-reference="odd" odd-or-even="odd" page-position="any"/>
<fo:conditional-page-master-reference master-reference="even" odd-or-even="even" page-position="any"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:bookmark-tree>
<fo:bookmark internal-destination="title" starting-state="show">
<fo:bookmark-title>title</fo:bookmark-title>
</fo:bookmark>
</fo:bookmark-tree>
<fo:page-sequence id="lastpagesequence" master-reference="basicPSM">
<fo:flow flow-name="xsl-region-body">
<fo:block id="par" break-after="page">par</fo:block>
<fo:block id="par2" break-after="page">par2</fo:block>
<fo:block id="par3" break-after="page">par3</fo:block>
<fo:block>before-title</fo:block>
<fo:block id="title" keep-with-next="always">title</fo:block>
<fo:block>
<fo:basic-link internal-destination="par2">
siehe <fo:inline keep-together="always">
Seite <fo:page-number-citation ref-id="par2"/>
</fo:inline>
</fo:basic-link>
</fo:block>
<fo:block break-before="column">title2</fo:block>
<fo:block>
<fo:basic-link internal-destination="par3">
siehe <fo:inline keep-together="always">
Seite <fo:page-number-citation ref-id="par3"/>
</fo:inline>
</fo:basic-link>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</fo>
<checks>
<eval expected="(P2,par2)" xpath="((/areaTree/pageSequence/pageViewport)[4]//inlineparent[@internal-link])[1]/@internal-link"/>
<eval expected="(P3,par3)" xpath="((/areaTree/pageSequence/pageViewport)[4]//inlineparent[@internal-link])[2]/@internal-link"/>
<eval expected="(P5,title)" xpath="/areaTree/bookmarkTree/bookmark/@internal-link"/>
<eval expected="4" xpath="count(/areaTree/pageSequence/pageViewport)"/>
</checks>
</testcase>

Loading…
Cancel
Save