]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3046: Don't use page position only on redo of layout
authorSimon Steiner <ssteiner@apache.org>
Thu, 6 Jan 2022 14:18:11 +0000 (14:18 +0000)
committerSimon Steiner <ssteiner@apache.org>
Thu, 6 Jan 2022 14:18:11 +0000 (14:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1896753 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java
fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
fop-core/src/main/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java
fop-core/src/main/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java
fop-core/src/main/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java
fop-core/src/main/java/org/apache/fop/render/rtf/RTFHandler.java
fop-core/src/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java
fop/test/layoutengine/standard-testcases/page-position_only_too-small.xml
test/layoutengine/standard-testcases/page-position_only_3.xml [new file with mode: 0644]

index 79955ff74e4dd57ab3998aef0ef370090059148f..79481c4006b8b1c7822e28175bccdc8fa2dbe60b 100644 (file)
@@ -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);
     }
 
     /**
index b9840e0063fcff1a4f9ad5c96dde8e2504a8fcfe..9e040d03df0d853f81e6a50c8faca5dbcc95b812 100644 (file)
@@ -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;
index 2914fb9a8f9412ffccc6aec7348432989e6fc827..4cc8647fc93081b30074a9f4290c22b280e6150b 100644 (file)
@@ -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();
             }
         }
index 5e43c02b1bb21d7dc822bd035877baba34fa02ee..5fc8bbd15ce05bdf8e7be55321b5255d324a11c4 100644 (file)
@@ -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);
     }
 
     /**
index 2600909cb4b09a0f53c7db1e03d0fca2a0e814be..75d0785f165c4ba66d064b103f2a3815df3c7737 100644 (file)
@@ -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} */
index 0905ee8a81b085e76b3a70de589d1b08ffd0419f..12fe517e3b5753d3091611c6e64ae531669facac 100644 (file)
@@ -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)
index 266a7d9b9530196ab365b2029430966fde8f7a7e..7926ba756de18dde2550b885f56084d8de821f63 100644 (file)
@@ -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
index a4a63afc6b5b6b9ea38d474c21eaa8b251ebdb9c..3a2d80d5e1f0ec28f31217b7cebed5d76790070a 100644 (file)
@@ -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);
                     }
                 }
             }
index d1f8433cfb1a29d93eabf8d76c141afc9a89c0e7..584593e228bb469fbeb7d62bc09ab6cea8182333 100644 (file)
@@ -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
index 589c3a21fea3a4e461b3c9a11cbc732051adb25d..cded06e728314e5f922f7f4dbdb32e524d721858 100644 (file)
@@ -18,7 +18,7 @@
 <!-- $Id$ -->
 <testcase>
   <info>
-    <p>When the page-master for page-position="only" cannot accommodate the content, two default 
+    <p>When the page-master for page-position="only" cannot accommodate the content, one default
       pages must be used instead.</p>
   </info>
   <fo>
@@ -51,8 +51,7 @@
     </fo:root>
   </fo>
   <checks>
-    <eval expected="2" xpath="count(//pageSequence[1]/pageViewport)"/>
+    <eval expected="1" xpath="count(//pageSequence[1]/pageViewport)"/>
     <eval expected="default" xpath="//pageSequence[1]/pageViewport[1]/@simple-page-master-name"/>
-    <eval expected="default" xpath="//pageSequence[1]/pageViewport[2]/@simple-page-master-name"/>
   </checks>
 </testcase>
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 (file)
index 0000000..bc3b332
--- /dev/null
@@ -0,0 +1,53 @@
+<?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 test checks for the use of an 'only' conditional-page-master-reference (XSL 1.1)
+    </p>
+  </info>
+  <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+  <fo:layout-master-set>
+    <fo:simple-page-master master-name="SinglePage" page-width="210mm" page-height="297mm">      
+      <fo:region-body margin-top="100mm"  region-name="Body"/>      
+    </fo:simple-page-master>
+    <fo:simple-page-master master-name="Page_Rest_Even" page-width="210mm" page-height="297mm" >      
+      <fo:region-body region-name="Body"  background-color="orange"/>      
+    </fo:simple-page-master>
+    <fo:page-sequence-master master-name="CertificatePagesMaster">
+      <fo:repeatable-page-master-alternatives>
+        <fo:conditional-page-master-reference master-reference="SinglePage" page-position="only"/>
+        <fo:conditional-page-master-reference page-position="first" master-reference="Page_Rest_Even"/>
+        <fo:conditional-page-master-reference page-position="rest" master-reference="Page_Rest_Even"/>
+        <fo:conditional-page-master-reference page-position="last" master-reference="Page_Rest_Even"/>        
+      </fo:repeatable-page-master-alternatives>
+    </fo:page-sequence-master>
+  </fo:layout-master-set>  
+  <fo:page-sequence master-reference="CertificatePagesMaster">  
+    <fo:flow flow-name="Body">    
+    <fo:block font-size="80pt">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 </fo:block>      
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
+  </fo>
+  <checks>
+    <eval expected="1" xpath="count(//page)"/>
+  </checks>
+</testcase>