From: Simon Pepping Date: Fri, 6 Jan 2006 21:31:02 +0000 (+0000) Subject: Implementation of force-page-count property, patch by Gerhard Oettl, X-Git-Tag: fop-0_92-beta~223 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5c359c10e6131572e46745dfe46c4c556e361ea0;p=xmlgraphics-fop.git Implementation of force-page-count property, patch by Gerhard Oettl, somewhat rearranged by me. See bug 38087. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@366569 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java index 09d8cb80b..9fdc17870 100644 --- a/src/java/org/apache/fop/area/AreaTreeHandler.java +++ b/src/java/org/apache/fop/area/AreaTreeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,6 +98,8 @@ public class AreaTreeHandler extends FOEventHandler { // The formatting results to be handed back to the caller. private FormattingResults results = new FormattingResults(); + private PageSequenceLayoutManager prevPageSeqLM; + private static Log log = LogFactory.getLog(AreaTreeHandler.class); /** @@ -266,7 +268,15 @@ public class AreaTreeHandler extends FOEventHandler { /** @see org.apache.fop.fo.FOEventHandler */ public void startPageSequence(PageSequence pageSequence) { rootFObj = pageSequence.getRoot(); - + // finish the previous pageSequence (handle force-page-count) + if (prevPageSeqLM != null) { + prevPageSeqLM.doForcePageCount(pageSequence.getInitialPageNumber()); + prevPageSeqLM.finishPageSequence(); + prevPageSeqLM = null; + // recalc pagenumber for the case that a new page is + // inserted by checkForcePageCount + } + pageSequence.initPageNumber(); //extension attachments from fo:root wrapAndAddExtensionAttachments(rootFObj.getExtensionAttachments()); //extension attachments from fo:declarations @@ -303,6 +313,9 @@ public class AreaTreeHandler extends FOEventHandler { pageSLM = getLayoutManagerMaker().makePageSequenceLayoutManager( this, pageSequence); pageSLM.activateLayout(); + // preserve the current PageSequenceLayoutManger for the + // force-page-count check at the beginning of the next PageSequence + prevPageSeqLM = pageSLM; } } diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java index 1066b67e1..80006da30 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,7 +139,6 @@ public class PageSequence extends FObj { new PageNumberGenerator(format, groupingSeparator, groupingSize, letterValue); checkId(id); - initPageNumber(); getFOEventHandler().startPageSequence(this); } @@ -235,7 +234,7 @@ public class PageSequence extends FObj { /** * Initialize the current page number for the start of the page sequence. */ - private void initPageNumber() { + public void initPageNumber() { int pageNumberType = 0; if (initialPageNumber.getEnum() != 0) { @@ -511,4 +510,17 @@ public class PageSequence extends FObj { public int getNameId() { return FO_PAGE_SEQUENCE; } + /** + * get the forcePageCount value + */ + public int getForcePageCount() { + return forcePageCount; + } + + /** + * get the initial pagenumber property value + */ + public Numeric getInitialPageNumber() { + return initialPageNumber; + } } diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index b5f69f613..a7c6c7b6a 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ package org.apache.fop.layoutmgr; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.Numeric; import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.area.AreaTreeModel; @@ -145,8 +146,11 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { PageBreaker breaker = new PageBreaker(this); int flowBPD = (int)getCurrentPV().getBodyRegion().getRemainingBPD(); breaker.doLayout(flowBPD); - + finishPage(); + } + + public void finishPageSequence() { pageSeq.getRoot().notifyPageSequenceFinished(currentPageNum, (currentPageNum - startPageNum) + 1); areaTreeHandler.notifyPageSequenceFinished(pageSeq, @@ -888,4 +892,72 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { } } + + /* + * check if the page-number of the last page suits to the force-page-count property + */ + public void doForcePageCount(Numeric nextPageSeqInitialPageNumber) { + + int forcePageCount = pageSeq.getForcePageCount(); + + // xsl-spec version 1.0 (15.oct 2001) + // auto | even | odd | end-on-even | end-on-odd | no-force | inherit + // auto: + // Force the last page in this page-sequence to be an odd-page + // if the initial-page-number of the next page-sequence is even. + // Force it to be an even-page + // if the initial-page-number of the next page-sequence is odd. + // If there is no next page-sequence + // or if the value of its initial-page-number is "auto" do not force any page. + + + // if force-page-count is auto then set the value of forcePageCount + // depending on the initial-page-number of the next page-sequence + if (forcePageCount == Constants.EN_AUTO) { + if (nextPageSeqInitialPageNumber.getEnum() != 0) { + // auto | auto-odd | auto-even + int nextPageSeqPageNumberType = nextPageSeqInitialPageNumber.getEnum(); + if (nextPageSeqPageNumberType == Constants.EN_AUTO_ODD) { + forcePageCount = Constants.EN_END_ON_EVEN; + } else if (nextPageSeqPageNumberType == Constants.EN_AUTO_EVEN) { + forcePageCount = Constants.EN_END_ON_ODD; + } else { // auto + forcePageCount = Constants.EN_NO_FORCE; + } + } else { // for explicit page number + int nextPageSeqPageStart = nextPageSeqInitialPageNumber.getValue(); + // spec rule + nextPageSeqPageStart = (nextPageSeqPageStart > 0) ? nextPageSeqPageStart : 1; + if (nextPageSeqPageStart % 2 == 0) { // explicit even startnumber + forcePageCount = Constants.EN_END_ON_ODD; + } else { // explicit odd startnumber + forcePageCount = Constants.EN_END_ON_EVEN; + } + } + } + + if (forcePageCount == Constants.EN_EVEN) { + if ((currentPageNum - startPageNum + 1) % 2 != 0) { // we have a odd number of pages + curPage = makeNewPage(true, false); + } + } else if (forcePageCount == Constants.EN_ODD) { + if ((currentPageNum - startPageNum + 1) % 2 == 0) { // we have a even number of pages + curPage = makeNewPage(true, false); + } + } else if (forcePageCount == Constants.EN_END_ON_EVEN) { + if (currentPageNum % 2 != 0) { // we are now on a odd page + curPage = makeNewPage(true, false); + } + } else if (forcePageCount == Constants.EN_END_ON_ODD) { + if (currentPageNum % 2 == 0) { // we are now on a even page + curPage = makeNewPage(true, false); + } + } else if (forcePageCount == Constants.EN_NO_FORCE) { + // i hope: nothing special at all + } + + if (curPage != null) { + finishPage(); + } + } } diff --git a/test/layoutengine/standard-testcases/page-sequence_force-page-count_1.xml b/test/layoutengine/standard-testcases/page-sequence_force-page-count_1.xml new file mode 100644 index 000000000..526d6d366 --- /dev/null +++ b/test/layoutengine/standard-testcases/page-sequence_force-page-count_1.xml @@ -0,0 +1,397 @@ + + + + + +

+ This test checks the force-page-count property. See bug 38087. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1. Pageseq: ends odd, [#] / auto / next is auto-even -> nothing + + + expl: ends on {odd|even}, {odd,even} number of pages # / force-page-count / initial-page-number -> action + + + + + + + + + + + + + 2. Pageseq: ends even, [#] / auto / next is auto-even -> addpage + + + + + + + + + + + + + 3. Pageseq: ends even, [#] / auto / next is auto-odd -> nothing + + + + + + + + + + + + + 4. Pageseq: ends odd, [#] / auto / next is auto-odd -> addpage + + + + + + + + + + + + + 5. Pageseq: ends odd, [#] / auto / next is auto-even -> nothing + + + + + + + + + + + + + 6. Pageseq: ends even, [#] / auto / next is numeric even -> addpage + + + + + + + + + + + + + 5. Pageseq: ends even, [#] / auto / next is numeric even -> addpage + + + + + + + + + + + + + 6. Pageseq: ends even, [#] / auto / next is numeric odd -> nothing + + + + + + + + + + + + + 7. Pageseq: ends odd, [#] / auto / next is numeric odd -> addpage + + + + + + + + + + + + + 101. Pageseq: ends odd, [#] / end-on-even/ [next is auto] -> addpage + + + + + + + + + + + + + 102a. Pageseq: see next page + + + 102b. Pageseq: ends even, [#] / end-on-even/ [next is auto] -> nothing + + + + + + + + + + + + + 103. Pageseq: ends odd, [#] / end-on-odd/ [next is auto] -> nothing + + + + + + + + + + + + + 104. Pageseq: ends even, [#] / end-on-odd/ [next is auto] -> addpage + + + + + + + + + + + + + 201. Pageseq: [ends], odd # / even / [next is auto] -> addpage + + + + + + + + + + + + + 202a. Pageseq: see next page + + + 13b. Pageseq: [ends], even # / even / [next is auto] -> nothing + + + + + + + + + + + + + 203. Pageseq: [ends], odd # / odd / [next is auto] -> nothing + + + + + + + + + + + + + 204a. Pageseq: see next page + + + 204b. Pageseq: [ends], even # / odd / [next is auto] -> addpage + + + + + + + + + + + + + 301. Pageseq: ends even, [#] / no-force / next is auto-even -> nothing + + + Only to show the possibility of missing pagenumbers for + force-page-count="no-force". + + + + + + + + + + + + + 302. Pageseq: dont matter, dont matter # / auto / next is auto -> nothing + + + + + + + + + + + + + 999. Pageseq: dont matter, auto / no next + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +