]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla#51962: Bugfix for when the last simple-page-master referenced in a page...
authorPeter Hancock <phancock@apache.org>
Tue, 11 Oct 2011 08:44:08 +0000 (08:44 +0000)
committerPeter Hancock <phancock@apache.org>
Tue, 11 Oct 2011 08:44:08 +0000 (08:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1181660 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/PageBreaker.java
src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
status.xml
test/layoutengine/standard-testcases/page-sequence-force-page-count-odd.xml [new file with mode: 0644]

index 3a41eb191cf2d1c40a89d6c9a29be79af34762c4..ea2d0926879729cd2d2b1bce72e1d49d17249b7c 100644 (file)
@@ -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));
index 67c41ccf03b37b44286fc68c1729bbe4780e32ba..2e09166c732f1761f473d28f7dd48c6c5c240334 100644 (file)
@@ -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;
+    }
+
 }
index af5535d63b5825ef68abb391e1841d572a908238..117594b79dbd93b426b47b79176b1c0290ff6463 100644 (file)
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Code" dev="PH" type="add" fixes-bug="51962" due-to="Mehdi Houshmand">
+        Bugfix for when the last simple-page-master referenced in a page-sequence-master is not
+        chosen when force-page-count=odd.
+      </action>
       <action context="Code" dev="VH" type="add" fixes-bug="51928" due-to="Mehdi Houshmand">
         Upgraded all tests to JUnit 4.
       </action>
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 (file)
index 0000000..d75f9ba
--- /dev/null
@@ -0,0 +1,108 @@
+<?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 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.
+    </p>
+  </info>
+  <variables>
+    <img>../../resources/images/bgimg300dpi.jpg</img>
+  </variables>
+  <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+  <fo:layout-master-set>
+    <fo:simple-page-master master-name="simple-first" page-width="210mm" page-height="297mm" margin-bottom="0mm" margin-right="0mm" margin-top="0mm" margin-left="0mm">
+      <fo:region-body  region-name="body"/>
+      <fo:region-before region-name="first-before" extent="100mm"/>
+      <fo:region-after region-name="first-after" extent="23mm"/>
+    </fo:simple-page-master>
+    <fo:simple-page-master master-name="simple-first-space" page-width="210mm" page-height="297mm" margin-bottom="0mm" margin-right="0mm" margin-top="0mm" margin-left="0mm">
+      <fo:region-body margin-bottom="115mm" margin-right="20mm" margin-top="0mm" margin-left="23mm" region-name="body"/>
+      <fo:region-before background-position-horizontal="150mm" background-repeat="no-repeat" background-position-vertical="10mm" region-name="first-before" extent="70mm"/>
+      <fo:region-after region-name="first-after-space" extent="110mm"/>
+    </fo:simple-page-master>
+    <fo:simple-page-master master-name="simple-rest" page-width="210mm" page-height="297mm" margin-bottom="0mm" margin-right="0mm" margin-top="0mm" margin-left="0mm">
+      <fo:region-body background-color="green" margin-bottom="25mm" margin-right="20mm" margin-top="70mm" margin-left="23mm" region-name="body"/>
+      <fo:region-before background-position-horizontal="150mm" background-repeat="no-repeat" background-position-vertical="10mm" region-name="rest-before" extent="70mm"/>
+      <fo:region-after region-name="rest-after" extent="23mm"/>
+    </fo:simple-page-master>
+    <fo:simple-page-master master-name="simple-last" page-width="210mm" page-height="297mm" margin-bottom="0mm" margin-right="0mm" margin-top="0mm" margin-left="0mm">
+      <fo:region-body background-color="blue" margin-top="70mm" margin-bottom="115mm" margin-right="22mm" margin-left="25mm" region-name="body"/>
+      <fo:region-before background-position-horizontal="150mm" background-repeat="no-repeat" background-position-vertical="10mm" region-name="last-before" extent="70mm"/>
+      <fo:region-after extent="111mm" region-name="last-after"/>
+    </fo:simple-page-master>
+<fo:page-sequence-master master-name="psm">
+      <fo:repeatable-page-master-alternatives>
+        <fo:conditional-page-master-reference page-position="only" master-reference="simple-first-space"/>
+        <fo:conditional-page-master-reference page-position="first" master-reference="simple-first"/> 
+        <fo:conditional-page-master-reference page-position="rest" master-reference="simple-rest"/>
+       <fo:conditional-page-master-reference page-position="last" master-reference="simple-last"/>
+      </fo:repeatable-page-master-alternatives>
+    </fo:page-sequence-master>
+  </fo:layout-master-set>
+  <fo:page-sequence format="1" force-page-count="odd" master-reference="psm">
+    <fo:static-content flow-name="first-before">
+        <fo:block>
+        </fo:block>
+    </fo:static-content>
+    <fo:static-content flow-name="first-after-space">
+        <fo:block page-break-before="always" page-break-after="always">
+        </fo:block>
+    </fo:static-content>
+    <fo:static-content flow-name="first-after">
+      <fo:block margin-right="20mm" margin-left="23mm">
+      </fo:block>
+    </fo:static-content>
+    <fo:static-content flow-name="rest-before">
+        <fo:block>
+        </fo:block>
+    </fo:static-content>
+    <fo:static-content flow-name="last-before">
+        <fo:block>
+        </fo:block>
+    </fo:static-content>
+    <fo:static-content flow-name="rest-after">
+      <fo:block margin-right="20mm" margin-left="23mm">
+      </fo:block>
+    </fo:static-content>
+    <fo:static-content flow-name="last-after">
+        <fo:block>
+        </fo:block>
+    </fo:static-content>
+    <fo:flow flow-name="body">
+      <fo:block-container>
+        <fo:block margin-top="88mm">
+         <fo:block space-after="120mm">line 1</fo:block>
+         <fo:block space-after="60mm">line 2</fo:block>
+        </fo:block>
+      </fo:block-container>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
+  </fo>
+  <checks>
+    <eval expected="simple-first" xpath="//pageViewport[1]/@simple-page-master-name"/>
+    <eval expected="simple-rest" xpath="//pageViewport[2]/@simple-page-master-name"/>
+    <eval expected="simple-last" xpath="//pageViewport[3]/@simple-page-master-name"/>
+    <eval expected="3" xpath="count(//pageViewport)"/>
+  </checks>
+</testcase>