From: Simon Steiner Date: Thu, 6 Jan 2022 14:18:11 +0000 (+0000) Subject: FOP-3046: Don't use page position only on redo of layout X-Git-Tag: fop-2_7~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=efc47f3d9090a19d668d3fcea634fe0cfa39b1ea;p=xmlgraphics-fop.git FOP-3046: Don't use page position only on redo of layout git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1896753 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java index 79955ff74..79481c400 100644 --- a/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java +++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java @@ -30,6 +30,7 @@ import org.xml.sax.Locator; import org.apache.fop.apps.FOPException; import org.apache.fop.complexscripts.bidi.DelimitedTextRange; import org.apache.fop.datatypes.Numeric; +import org.apache.fop.fo.Constants; import org.apache.fop.fo.FONode; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; @@ -280,7 +281,7 @@ public class PageSequence extends AbstractPageSequence implements WritingModeTra * @throws PageProductionException if there's a problem determining the page master */ public SimplePageMaster getNextSimplePageMaster( - int page, boolean isFirstPage, boolean isLastPage, boolean isBlank) + int page, boolean isFirstPage, boolean isLastPage, boolean isBlank, boolean skipPagePositionOnly) throws PageProductionException { if (pageSequenceMaster == null) { @@ -295,7 +296,8 @@ public class PageSequence extends AbstractPageSequence implements WritingModeTra + " isBlank=" + isBlank + ")"); } return pageSequenceMaster.getNextSimplePageMaster(isOddPage, - isFirstPage, isLastPage, isBlank, getMainFlow().getFlowName()); + isFirstPage, isLastPage, isBlank, getMainFlow().getFlowName(), + skipPagePositionOnly && forcePageCount != Constants.EN_ODD); } /** diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java index b9840e006..9e040d03d 100644 --- a/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -198,7 +198,8 @@ public class PageSequenceMaster extends FObj { boolean isFirstPage, boolean isLastPage, boolean isBlankPage, - String mainFlowName) + String mainFlowName, + boolean skipPagePositionOnly) throws PageProductionException { if (onlyTryInfinite && currentSubSequence != null && !currentSubSequence.isInfinite()) { throw new PageProductionException("Limited to infinite"); @@ -216,7 +217,7 @@ public class PageSequenceMaster extends FObj { } SimplePageMaster pageMaster = currentSubSequence - .getNextPageMaster(isOddPage, isFirstPage, isLastPage, isBlankPage); + .getNextPageMaster(isOddPage, isFirstPage, isLastPage, isBlankPage, skipPagePositionOnly); boolean canRecover = true; @@ -238,7 +239,7 @@ public class PageSequenceMaster extends FObj { } pageMaster = currentSubSequence - .getNextPageMaster(isOddPage, isFirstPage, isLastPage, isBlankPage); + .getNextPageMaster(isOddPage, isFirstPage, isLastPage, isBlankPage, skipPagePositionOnly); } return pageMaster; diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java index 2914fb9a8..4cc8647fc 100644 --- a/fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java +++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java @@ -116,11 +116,8 @@ public class RepeatablePageMasterAlternatives extends FObj } /** {@inheritDoc} */ - public SimplePageMaster getNextPageMaster(boolean isOddPage, - boolean isFirstPage, - boolean isLastPage, - boolean isBlankPage) { - + public SimplePageMaster getNextPageMaster(boolean isOddPage, boolean isFirstPage, boolean isLastPage, + boolean isBlankPage, boolean skipPagePositionOnly) { if (!isInfinite() && numberConsumed >= getMaximumRepeats()) { return null; } @@ -129,6 +126,9 @@ public class RepeatablePageMasterAlternatives extends FObj for (ConditionalPageMasterReference cpmr : conditionalPageMasterRefs) { if (cpmr.isValid(isOddPage, isFirstPage, isLastPage, isBlankPage)) { + if (cpmr.getPagePosition() == EN_ONLY && skipPagePositionOnly) { + continue; + } return cpmr.getMaster(); } } diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java index 5e43c02b1..5fc8bbd15 100644 --- a/fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java +++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java @@ -93,7 +93,7 @@ public class RepeatablePageMasterReference extends FObj public SimplePageMaster getNextPageMaster(boolean isOddPage, boolean isFirstPage, boolean isLastPage, - boolean isEmptyPage) { + boolean isEmptyPage, boolean skipPagePositionOnly) { if (getMaximumRepeats() != INFINITE && numberConsumed >= getMaximumRepeats()) { return null; } @@ -103,7 +103,7 @@ public class RepeatablePageMasterReference extends FObj public SimplePageMaster getLastPageMaster(boolean isOddPage, boolean isFirstPage, boolean isEmptyPage, BlockLevelEventProducer blockLevelEventProducer) { - return getNextPageMaster(isOddPage, isFirstPage, true, isEmptyPage); + return getNextPageMaster(isOddPage, isFirstPage, true, isEmptyPage, false); } /** diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java index 2600909cb..75d0785f1 100644 --- a/fop-core/src/main/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java +++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java @@ -91,7 +91,7 @@ public class SinglePageMasterReference extends FObj public SimplePageMaster getNextPageMaster(boolean isOddPage, boolean isFirstPage, boolean isLastPage, - boolean isBlankPage) { + boolean isBlankPage, boolean skipPagePositionOnly) { if (this.state == FIRST) { this.state = DONE; return master; @@ -102,7 +102,7 @@ public class SinglePageMasterReference extends FObj public SimplePageMaster getLastPageMaster(boolean isOddPage, boolean isFirstPage, boolean isBlankPage, BlockLevelEventProducer blockLevelEventProducer) { - return getNextPageMaster(isOddPage, isFirstPage, true, isBlankPage); + return getNextPageMaster(isOddPage, isFirstPage, true, isBlankPage, false); } /** {@inheritDoc} */ diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java index 0905ee8a8..12fe517e3 100644 --- a/fop-core/src/main/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java +++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java @@ -38,11 +38,8 @@ public interface SubSequenceSpecifier { * @return the page master name * @throws PageProductionException if there's a problem determining the next page master */ - SimplePageMaster getNextPageMaster(boolean isOddPage, - boolean isFirstPage, - boolean isLastPage, - boolean isBlankPage) - throws PageProductionException; + SimplePageMaster getNextPageMaster(boolean isOddPage, boolean isFirstPage, boolean isLastPage, boolean isBlankPage, + boolean skipPagePositionOnly) throws PageProductionException; SimplePageMaster getLastPageMaster(boolean isOddPage, boolean isFirstPage, boolean isBlankPage, BlockLevelEventProducer blockLevelEventProducer) diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java index 266a7d9b9..7926ba756 100644 --- a/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java +++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java @@ -359,10 +359,10 @@ public class PageProvider implements Constants { String pageNumberString = pageSeq.makeFormattedPageNumber(index); boolean isFirstPage = (startPageOfPageSequence == index); SimplePageMaster spm = pageSeq.getNextSimplePageMaster( - index, isFirstPage, isLastPage, isBlank); + index, isFirstPage, isLastPage, isBlank, skipPagePositionOnly); boolean isPagePositionOnly = pageSeq.hasPagePositionOnly() && !skipPagePositionOnly; if (isPagePositionOnly) { - spm = pageSeq.getNextSimplePageMaster(index, isFirstPage, true, isBlank); + spm = pageSeq.getNextSimplePageMaster(index, isFirstPage, true, isBlank, skipPagePositionOnly); } Page page = new Page(spm, index, pageNumberString, isBlank, spanAll, isPagePositionOnly); //Set unique key obtained from the AreaTreeHandler diff --git a/fop-core/src/main/java/org/apache/fop/render/rtf/RTFHandler.java b/fop-core/src/main/java/org/apache/fop/render/rtf/RTFHandler.java index a4a63afc6..3a2d80d5e 100644 --- a/fop-core/src/main/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/fop-core/src/main/java/org/apache/fop/render/rtf/RTFHandler.java @@ -219,8 +219,8 @@ public class RTFHandler extends FOEventHandler { PageSequenceMaster master = pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(reference); if (pageSeq.getMainFlow() != null) { - this.pagemaster = master.getNextSimplePageMaster( - false, false, false, false, pageSeq.getMainFlow().getFlowName()); + this.pagemaster = master.getNextSimplePageMaster(false, false, false, + false, pageSeq.getMainFlow().getFlowName(), false); } } } diff --git a/fop-core/src/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java b/fop-core/src/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java index d1f8433cf..584593e22 100644 --- a/fop-core/src/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java @@ -76,14 +76,14 @@ public class PageSequenceMasterTestCase { //Setup to mock the exhaustion of the last sub-sequence specifier when(mockSinglePageMasterReference.getNextPageMaster(anyBoolean(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(null, spm); + anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(null, spm); //Need this for the method to return normally when(mockSinglePageMasterReference.canProcess(nullable(String.class))).thenReturn(true); when(mockSinglePageMasterReference.isReusable()).thenReturn(canResume); - pageSequenceMaster.getNextSimplePageMaster(false, false, false, false, null); + pageSequenceMaster.getNextSimplePageMaster(false, false, false, false, null, false); verify(mockBlockLevelEventProducer).pageSequenceMasterExhausted(nullable(Object.class), nullable(String.class), eq(canResume), nullable(Locator.class)); @@ -116,7 +116,7 @@ public class PageSequenceMasterTestCase { when(mockRegion.getRegionName()).thenReturn(emptyFlowRegionName); when(mockSinglePageMasterReference.getNextPageMaster(anyBoolean(), anyBoolean(), - anyBoolean(), anyBoolean())) + anyBoolean(), anyBoolean(), anyBoolean())) .thenReturn(null, mockEmptySPM); PageSequenceMaster pageSequenceMaster = createPageSequenceMaster(mockLayoutMasterSet, @@ -127,7 +127,7 @@ public class PageSequenceMasterTestCase { try { pageSequenceMaster.getNextSimplePageMaster(false, false, false, false, - mainFlowRegionName); + mainFlowRegionName, false); fail("The next simple page master does not refer to the main flow"); } catch (PageProductionException ppe) { //Passed test diff --git a/fop/test/layoutengine/standard-testcases/page-position_only_too-small.xml b/fop/test/layoutengine/standard-testcases/page-position_only_too-small.xml index 589c3a21f..cded06e72 100644 --- a/fop/test/layoutengine/standard-testcases/page-position_only_too-small.xml +++ b/fop/test/layoutengine/standard-testcases/page-position_only_too-small.xml @@ -18,7 +18,7 @@ -

When the page-master for page-position="only" cannot accommodate the content, two default +

When the page-master for page-position="only" cannot accommodate the content, one default pages must be used instead.

@@ -51,8 +51,7 @@ - + -
diff --git a/test/layoutengine/standard-testcases/page-position_only_3.xml b/test/layoutengine/standard-testcases/page-position_only_3.xml new file mode 100644 index 000000000..bc3b33214 --- /dev/null +++ b/test/layoutengine/standard-testcases/page-position_only_3.xml @@ -0,0 +1,53 @@ + + + + + +

+ This test checks for the use of an 'only' conditional-page-master-reference (XSL 1.1) +

+
+ + + + + + + + + + + + + + + + + + + + + test test test test test test test test test test test test test test test test test test test test test test test test test test + + + + + + + +