Skip to content

Commit 3fef612

Browse files
FOP-3242: Copy footnote data when page breaking restarted
1 parent a9ed4bd commit 3fef612

File tree

5 files changed

+201
-16
lines changed

5 files changed

+201
-16
lines changed

fop-core/src/main/java/org/apache/fop/layoutmgr/AbstractBreaker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public boolean doLayout(int flowBPD, boolean autoHeight) {
406406
PageBreakingAlgorithm alg = new PageBreakingAlgorithm(getTopLevelLM(),
407407
getPageProvider(), createLayoutListener(),
408408
alignment, alignmentLast, footnoteSeparatorLength,
409-
isPartOverflowRecoveryActivated(), autoHeight, isSinglePartFavored());
409+
isPartOverflowRecoveryActivated(), autoHeight, isSinglePartFavored(), childLC);
410410

411411
alg.setConstantLineWidth(flowBPD);
412412
int optimalPageCount = alg.findBreakingPoints(blockList, 1, true,

fop-core/src/main/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM,
4444
int columnCount) {
4545
super(topLevelLM, pageProvider, layoutListener,
4646
alignment, alignmentLast,
47-
footnoteSeparatorLength, partOverflowRecovery, false, false);
47+
footnoteSeparatorLength, partOverflowRecovery, false, false, null);
4848
this.columnCount = columnCount;
4949
this.considerTooShort = true; //This is important!
5050
}

fop-core/src/main/java/org/apache/fop/layoutmgr/PageBreaker.java

+22-11
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ private void redoLayout(PageBreakingAlgorithm alg, int partCount,
444444
getTopLevelLM(), getPageProvider(), createLayoutListener(),
445445
alg.getAlignment(), alg.getAlignmentLast(),
446446
footnoteSeparatorLength,
447-
isPartOverflowRecoveryActivated(), false, false);
447+
isPartOverflowRecoveryActivated(), false, false, null);
448448
log.debug("===================================================");
449449
}
450450

@@ -959,16 +959,27 @@ public void retrieveFootones(PageBreakingAlgorithm alg) {
959959
relayedFirstNewFootnoteIndex, relayedFootnoteListIndex, relayedFootnoteElementIndex,
960960
relayedFootnoteSeparatorLength, previousFootnoteListIndex,
961961
previousFootnoteElementIndex);
962-
relayedFootnotesList = null;
963-
relayedLengthList = null;
964-
relayedTotalFootnotesLength = 0;
965-
relayedInsertedFootnotesLength = 0;
966-
relayedFootnotesPending = false;
967-
relayedNewFootnotes = false;
968-
relayedFirstNewFootnoteIndex = 0;
969-
relayedFootnoteListIndex = 0;
970-
relayedFootnoteElementIndex = -1;
971-
relayedFootnoteSeparatorLength = null;
962+
if (alg.handlingFloat()) {
963+
relayedFootnotesList = null;
964+
relayedLengthList = null;
965+
relayedTotalFootnotesLength = 0;
966+
relayedInsertedFootnotesLength = 0;
967+
relayedFootnotesPending = false;
968+
relayedNewFootnotes = false;
969+
relayedFirstNewFootnoteIndex = 0;
970+
relayedFootnoteListIndex = 0;
971+
relayedFootnoteElementIndex = -1;
972+
relayedFootnoteSeparatorLength = null;
973+
}
974+
}
975+
}
976+
977+
protected void addAreas(PageBreakingAlgorithm alg, int startPart, int partCount,
978+
BlockSequence originalList, BlockSequence effectiveList, final LayoutContext childLC) {
979+
super.addAreas(alg, startPart, partCount, originalList, effectiveList, childLC);
980+
if (!alg.handlingFloat()) {
981+
PageSequenceLayoutManager pslm = (PageSequenceLayoutManager) getTopLevelLM();
982+
alg.relayFootnotes(pslm);
972983
}
973984
}
974985
}

fop-core/src/main/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
110110
private int previousFootnoteListIndex = -2;
111111
private int previousFootnoteElementIndex = -2;
112112
private boolean relayingFootnotes;
113+
private LayoutContext childLC;
113114

114115
/**
115116
* Construct a page breaking algorithm.
@@ -136,7 +137,7 @@ public PageBreakingAlgorithm(LayoutManager topLevelLM,
136137
int alignment, int alignmentLast,
137138
MinOptMax footnoteSeparatorLength,
138139
boolean partOverflowRecovery, boolean autoHeight,
139-
boolean favorSinglePart) {
140+
boolean favorSinglePart, LayoutContext childLC) {
140141
super(alignment, alignmentLast, true, partOverflowRecovery, 0);
141142
this.topLevelLM = topLevelLM;
142143
this.pageProvider = pageProvider;
@@ -145,6 +146,7 @@ public PageBreakingAlgorithm(LayoutManager topLevelLM,
145146
this.footnoteSeparatorLength = footnoteSeparatorLength;
146147
this.autoHeight = autoHeight;
147148
this.favorSinglePart = favorSinglePart;
149+
this.childLC = childLC;
148150
}
149151

150152
/**
@@ -249,14 +251,17 @@ protected void initialize() {
249251
footnoteElementIndex = -1;
250252
if (topLevelLM instanceof PageSequenceLayoutManager) {
251253
PageSequenceLayoutManager pslm = (PageSequenceLayoutManager) topLevelLM;
252-
if (pslm.handlingStartOfFloat() || pslm.handlingEndOfFloat()) {
254+
boolean spanAll = childLC != null && childLC.getCurrentSpan() == Constants.EN_ALL;
255+
if (pslm.handlingStartOfFloat() || pslm.handlingEndOfFloat() || spanAll) {
253256
pslm.retrieveFootnotes(this);
254257
}
255258
if (pslm.handlingStartOfFloat()) {
256259
floatHeight = Math.min(pslm.getFloatHeight(), lineWidth - pslm.getFloatYOffset());
257260
}
258261
if (pslm.handlingEndOfFloat()) {
259262
totalWidth += pslm.getOffsetDueToFloat() + insertedFootnotesLength;
263+
} else if (spanAll) {
264+
totalWidth += insertedFootnotesLength;
260265
}
261266
}
262267
}
@@ -1362,7 +1367,7 @@ public void loadFootnotes(List fl, List<Integer> ll, int tfl, int ifl, boolean f
13621367
}
13631368

13641369
public void relayFootnotes(PageSequenceLayoutManager pslm) {
1365-
if (!relayingFootnotes) {
1370+
if (!relayingFootnotes && bestFloatEdgeNode != null) {
13661371
previousFootnoteListIndex = ((KnuthPageNode) bestFloatEdgeNode.previous).footnoteListIndex;
13671372
previousFootnoteElementIndex = ((KnuthPageNode) bestFloatEdgeNode.previous).footnoteElementIndex;
13681373
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<!-- $Id$ -->
19+
<testcase>
20+
<info>
21+
<p>
22+
This test checks footnotes.
23+
</p>
24+
</info>
25+
<fo>
26+
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Helvetica">
27+
<fo:layout-master-set>
28+
<fo:simple-page-master margin-right="1in" margin-left="1in" margin-bottom="1in" margin-top="1in" page-width="8.5in" page-height="11in" master-name="Page">
29+
<fo:region-body column-count="2" margin-right="0in" margin-bottom="0in" margin-left="0in" margin-top="0in" region-name="Body"/>
30+
</fo:simple-page-master>
31+
</fo:layout-master-set>
32+
<fo:page-sequence format="1" id="th_default_sequence1" master-reference="Page">
33+
<fo:flow flow-name="Body">
34+
<fo:block-container>
35+
<fo:block>
36+
<fo:block font-size="10pt" line-height="16pt" space-before="2pt">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.<fo:footnote><fo:inline font-size="70%" baseline-shift="super">1</fo:inline>
37+
<fo:footnote-body start-indent="0">
38+
<fo:list-block provisional-distance-between-starts="18pt">
39+
<fo:list-item>
40+
<fo:list-item-label end-indent="label-end()" font-size="70%" baseline-shift="super">
41+
<fo:block>1</fo:block>
42+
</fo:list-item-label>
43+
<fo:list-item-body start-indent="body-start()">
44+
<fo:block font-size="10pt" line-height="16pt" space-before="2pt">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</fo:block>
45+
</fo:list-item-body>
46+
</fo:list-item>
47+
</fo:list-block>
48+
</fo:footnote-body>
49+
</fo:footnote>
50+
</fo:block>
51+
</fo:block>
52+
</fo:block-container>
53+
<fo:block-container break-before="column">
54+
<fo:block>
55+
<fo:block font-size="10pt" line-height="16pt" space-before="2pt">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</fo:block>
56+
</fo:block>
57+
</fo:block-container>
58+
<fo:block-container span="all">
59+
<fo:block>
60+
<fo:list-block line-height="16pt" space-after="3pt">
61+
<fo:list-item space-before="0pt">
62+
<fo:list-item-label font-family="ZapfDingbats" font-size="7pt">
63+
<fo:block>
64+
<fo:inline>&#x25CF;</fo:inline>
65+
</fo:block>
66+
</fo:list-item-label>
67+
<fo:list-item-body font-size="10pt" start-indent="body-start()">
68+
<fo:block>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </fo:block>
69+
</fo:list-item-body>
70+
</fo:list-item>
71+
<fo:list-item space-before="0pt">
72+
<fo:list-item-label font-family="ZapfDingbats" font-size="7pt">
73+
<fo:block>
74+
<fo:inline>&#x25CF;</fo:inline>
75+
</fo:block>
76+
</fo:list-item-label>
77+
<fo:list-item-body font-size="10pt" start-indent="body-start()">
78+
<fo:block>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </fo:block>
79+
</fo:list-item-body>
80+
</fo:list-item>
81+
<fo:list-item space-before="0pt">
82+
<fo:list-item-label font-family="ZapfDingbats" font-size="7pt">
83+
<fo:block>
84+
<fo:inline>&#x25CF;</fo:inline>
85+
</fo:block>
86+
</fo:list-item-label>
87+
<fo:list-item-body font-size="10pt" start-indent="body-start()">
88+
<fo:block>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </fo:block>
89+
</fo:list-item-body>
90+
</fo:list-item>
91+
<fo:list-item space-before="0pt">
92+
<fo:list-item-label font-family="ZapfDingbats" font-size="7pt">
93+
<fo:block>
94+
<fo:inline>&#x25CF;</fo:inline>
95+
</fo:block>
96+
</fo:list-item-label>
97+
<fo:list-item-body font-size="10pt" start-indent="body-start()">
98+
<fo:block>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </fo:block>
99+
</fo:list-item-body>
100+
</fo:list-item>
101+
<fo:list-item space-before="0pt">
102+
<fo:list-item-label font-family="ZapfDingbats" font-size="7pt">
103+
<fo:block>
104+
<fo:inline>&#x25CF;</fo:inline>
105+
</fo:block>
106+
</fo:list-item-label>
107+
<fo:list-item-body font-size="10pt" start-indent="body-start()">
108+
<fo:block>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</fo:block>
109+
</fo:list-item-body>
110+
</fo:list-item>
111+
<fo:list-item space-before="0pt">
112+
<fo:list-item-label font-family="ZapfDingbats" font-size="7pt">
113+
<fo:block>
114+
<fo:inline>&#x25CF;</fo:inline>
115+
</fo:block>
116+
</fo:list-item-label>
117+
<fo:list-item-body font-size="10pt" start-indent="body-start()">
118+
<fo:block>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </fo:block>
119+
</fo:list-item-body>
120+
</fo:list-item>
121+
<fo:list-item space-before="0pt">
122+
<fo:list-item-label font-family="ZapfDingbats" font-size="7pt">
123+
<fo:block>
124+
<fo:inline>&#x25CF;</fo:inline>
125+
</fo:block>
126+
</fo:list-item-label>
127+
<fo:list-item-body font-size="10pt" start-indent="body-start()">
128+
<fo:block>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </fo:block>
129+
</fo:list-item-body>
130+
</fo:list-item>
131+
<fo:list-item space-before="0pt">
132+
<fo:list-item-label font-family="ZapfDingbats" font-size="7pt">
133+
<fo:block>
134+
<fo:inline>&#x25CF;</fo:inline>
135+
</fo:block>
136+
</fo:list-item-label>
137+
<fo:list-item-body font-size="10pt" start-indent="body-start()">
138+
<fo:block>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. <fo:footnote><fo:inline font-size="70%" baseline-shift="super">2</fo:inline>
139+
<fo:footnote-body start-indent="0">
140+
<fo:list-block provisional-distance-between-starts="18pt">
141+
<fo:list-item>
142+
<fo:list-item-label end-indent="label-end()" font-size="70%" baseline-shift="super">
143+
<fo:block>2</fo:block>
144+
</fo:list-item-label>
145+
<fo:list-item-body start-indent="body-start()">
146+
<fo:block font-size="10pt" line-height="16pt" space-before="2pt">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</fo:block>
147+
</fo:list-item-body>
148+
</fo:list-item>
149+
</fo:list-block>
150+
</fo:footnote-body>
151+
</fo:footnote>
152+
</fo:block>
153+
</fo:list-item-body>
154+
</fo:list-item>
155+
</fo:list-block>
156+
</fo:block>
157+
</fo:block-container>
158+
</fo:flow>
159+
</fo:page-sequence>
160+
</fo:root>
161+
</fo>
162+
<checks>
163+
<eval expected="2" xpath="count(//pageViewport)"/>
164+
<eval expected="1" xpath="//pageViewport[1]//footnote//word"/>
165+
<eval expected="2" xpath="//pageViewport[2]//footnote//word"/>
166+
<eval expected="Lorem" xpath="//pageViewport[1]//word"/>
167+
<eval expected="ipsum." xpath="//pageViewport[2]//word"/>
168+
</checks>
169+
</testcase>

0 commit comments

Comments
 (0)