From 25d268f166c66aa8ac5ffb102ab49ec9f88d667c Mon Sep 17 00:00:00 2001 From: Peter Hancock Date: Tue, 11 Oct 2011 08:44:08 +0000 Subject: [PATCH] Bugzilla#51962: Bugfix for when the last simple-page-master referenced in a page-sequence-master is not chosen when force-page-count=odd. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1181660 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/layoutmgr/PageBreaker.java | 11 +- .../layoutmgr/PageSequenceLayoutManager.java | 21 ++++ status.xml | 4 + .../page-sequence-force-page-count-odd.xml | 108 ++++++++++++++++++ 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 test/layoutengine/standard-testcases/page-sequence-force-page-count-odd.xml diff --git a/src/java/org/apache/fop/layoutmgr/PageBreaker.java b/src/java/org/apache/fop/layoutmgr/PageBreaker.java index 3a41eb191..ea2d09268 100644 --- a/src/java/org/apache/fop/layoutmgr/PageBreaker.java +++ b/src/java/org/apache/fop/layoutmgr/PageBreaker.java @@ -367,7 +367,9 @@ public class PageBreaker extends AbstractBreaker { // Handle special page-master for last page BodyRegion currentBody = pageProvider.getPage(false, currentPageNum) .getPageViewport().getBodyRegion(); - pageProvider.setLastPageIndex(currentPageNum); + + setLastPageIndex(currentPageNum); + BodyRegion lastBody = pageProvider.getPage(false, currentPageNum) .getPageViewport().getBodyRegion(); lastBody.getMainReference().setSpans(currentBody.getMainReference().getSpans()); @@ -410,7 +412,7 @@ public class PageBreaker extends AbstractBreaker { //Add areas now... addAreas(alg, restartPoint, partCount - restartPoint, originalList, effectiveList); //...and add a blank last page - pageProvider.setLastPageIndex(currentPageNum + 1); + setLastPageIndex(currentPageNum + 1); pslm.setCurrentPage(pslm.makeNewPage(true, true)); return; } @@ -419,6 +421,11 @@ public class PageBreaker extends AbstractBreaker { addAreas(algRestart, optimalPageCount, originalList, effectiveList); } + private void setLastPageIndex(int currentPageNum) { + int lastPageIndex = pslm.getForcedLastPageNum(currentPageNum); + pageProvider.setLastPageIndex(lastPageIndex); + } + /** {@inheritDoc} */ protected void startPart(BlockSequence list, int breakClass) { AbstractBreaker.log.debug("startPart() breakClass=" + getBreakClassName(breakClass)); diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index 67c41ccf0..2e09166c7 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.area.AreaTreeModel; import org.apache.fop.area.LineArea; +import org.apache.fop.fo.Constants; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.PageSequenceMaster; import org.apache.fop.fo.pagination.SideRegion; @@ -167,4 +168,24 @@ public class PageSequenceLayoutManager extends AbstractPageSequenceLayoutManager super.finishPage(); } + /** + * The last page number of the sequence may be incremented, as determined by the + * force-page-count formatting property semantics + * @param lastPageNum number of sequence + * @return the forced last page number of sequence + */ + protected int getForcedLastPageNum(final int lastPageNum) { + int forcedLastPageNum = lastPageNum; + if ( lastPageNum % 2 != 0 + && ( getPageSequence().getForcePageCount() == Constants.EN_EVEN + || getPageSequence().getForcePageCount() == Constants.EN_END_ON_EVEN )) { + forcedLastPageNum++; + } else if ( lastPageNum % 2 == 0 && ( + getPageSequence().getForcePageCount() == Constants.EN_ODD + || getPageSequence().getForcePageCount() == Constants.EN_END_ON_ODD )) { + forcedLastPageNum++; + } + return forcedLastPageNum; + } + } diff --git a/status.xml b/status.xml index af5535d63..117594b79 100644 --- a/status.xml +++ b/status.xml @@ -60,6 +60,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Bugfix for when the last simple-page-master referenced in a page-sequence-master is not + chosen when force-page-count=odd. + Upgraded all tests to JUnit 4. diff --git a/test/layoutengine/standard-testcases/page-sequence-force-page-count-odd.xml b/test/layoutengine/standard-testcases/page-sequence-force-page-count-odd.xml new file mode 100644 index 000000000..d75f9ba45 --- /dev/null +++ b/test/layoutengine/standard-testcases/page-sequence-force-page-count-odd.xml @@ -0,0 +1,108 @@ + + + + + +

+ This checks that when force-page-count that the last simple- + page-master is used when a single page overflows to a second + page and the page count is forced to odd. +

+
+ + ../../resources/images/bgimg300dpi.jpg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + line 1 + line 2 + + + + + + + + + + + + +
-- 2.39.5