]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2664: Use page-position=only if there is enough space
authorSimon Steiner <ssteiner@apache.org>
Tue, 8 Nov 2016 14:34:28 +0000 (14:34 +0000)
committerSimon Steiner <ssteiner@apache.org>
Tue, 8 Nov 2016 14:34:28 +0000 (14:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1768702 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/layoutmgr/AbstractBreaker.java
fop-core/src/main/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java
fop-core/src/main/java/org/apache/fop/layoutmgr/Page.java
fop-core/src/main/java/org/apache/fop/layoutmgr/PageBreaker.java
fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java
fop-core/src/main/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
fop/test/layoutengine/standard-testcases/page-position_only_2.xml [new file with mode: 0644]

index 36dd6f407dd581ce731b1cf8f9fe6c9113f51bc9..25fa3588520eed22176e763c190680f935be1276 100644 (file)
@@ -45,6 +45,7 @@ public abstract class AbstractBreaker {
     private LayoutManager originalRestartAtLM;
     private Position positionAtBreak;
     private List firstElementsForRestart;
+    protected PageSequenceLayoutManager pslm;
 
     /**
      * A page break position.
@@ -368,7 +369,7 @@ public abstract class AbstractBreaker {
      * @param autoHeight true if warnings about overflows should be disabled because the
      *                   the BPD is really undefined (for footnote-separators, for example)
      */
-    public void doLayout(int flowBPD, boolean autoHeight) {
+    public boolean doLayout(int flowBPD, boolean autoHeight) {
         LayoutContext childLC = createLayoutContext();
         childLC.setStackLimitBP(MinOptMax.getInstance(flowBPD));
         alignment = Constants.EN_START;
@@ -418,6 +419,10 @@ public abstract class AbstractBreaker {
                     onLastPageAndIPDChanges = (lastPageHasIPDChange() && !thereIsANonRestartableLM(alg)
                             && (shouldRedoLayout() || (wasLayoutRedone() && optimalPageCount > 1)));
                 }
+                if ((ipdChangesOnNextPage || hasMoreContent() || optimalPageCount > 1)
+                        && pslm != null && pslm.getCurrentPage().isPagePositionOnly) {
+                    return false;
+                }
                 if (alg.handlingFloat()) {
                     nextSequenceStartsOn = handleFloatLayout(alg, optimalPageCount, blockList, childLC);
                 } else if (ipdChangesOnNextPage || onLastPageAndIPDChanges) {
@@ -457,6 +462,7 @@ public abstract class AbstractBreaker {
 
         // done
         blockLists = null;
+        return true;
     }
 
     private LayoutManager getRestartAtLM(PageBreakingAlgorithm alg, boolean ipdChangesOnNextPage,
index 8435ad0938fc801152a7ec9c5a0b0a9d1685e5fe..64f87757a793e4f1b076b83974ad52aba4ed70cf 100644 (file)
@@ -111,6 +111,7 @@ public abstract class AbstractPageSequenceLayoutManager extends AbstractLayoutMa
     public void initialize() {
         startPageNum = pageSeq.getStartingPageNumber();
         currentPageNum = startPageNum - 1;
+        curPage = null;
     }
 
     /**
index d8ec66e82284b43f398d770cc5f4dac9a01cb7e4..6f3b97cd401803852e82bd3d8d24527203b29c39 100644 (file)
@@ -34,6 +34,7 @@ public class Page {
 
     private SimplePageMaster spm;
     private PageViewport pageViewport;
+    protected boolean isPagePositionOnly;
 
     /**
      * Main constructor
@@ -44,9 +45,10 @@ public class Page {
      * @param spanAll true if the first span area spans all columns
      */
     public Page(SimplePageMaster spm, int pageNumber, String pageNumberStr,
-            boolean blank, boolean spanAll) {
+            boolean blank, boolean spanAll, boolean isPagePositionOnly) {
         this.spm = spm;
         this.pageViewport = new PageViewport(spm, pageNumber, pageNumberStr, blank, spanAll);
+        this.isPagePositionOnly = isPagePositionOnly;
     }
 
     /**
index 9c1315640da483bafce458028d158be9655d364d..43fca99a2c26d2fe13bc6394445684a9dbd3ace9 100644 (file)
@@ -43,7 +43,6 @@ import org.apache.fop.traits.MinOptMax;
  */
 public class PageBreaker extends AbstractBreaker {
 
-    private PageSequenceLayoutManager pslm;
     private boolean firstPart = true;
     private boolean pageBreakHandled;
     private boolean needColumnBalancing;
@@ -109,8 +108,8 @@ public class PageBreaker extends AbstractBreaker {
      * Starts the page breaking process.
      * @param flowBPD the constant available block-progression-dimension (used for every part)
      */
-    void doLayout(int flowBPD) {
-        doLayout(flowBPD, false);
+    boolean doLayout(int flowBPD) {
+        return doLayout(flowBPD, false);
     }
 
     /** {@inheritDoc} */
index ca41c8c1e34d3fd4565d35bef077615191724a51..ff6a277c7a041c7a2d11ac419cf91f396b1cdc1a 100644 (file)
@@ -75,6 +75,8 @@ public class PageProvider implements Constants {
      */
     private PageSequence pageSeq;
 
+    protected boolean skipPagePositionOnly;
+
     /**
      * Main constructor.
      * @param ath the area tree handler
@@ -86,6 +88,10 @@ public class PageProvider implements Constants {
         this.startPageOfPageSequence = ps.getStartingPageNumber();
     }
 
+    public void initialize() {
+        cachedPages.clear();
+    }
+
     /**
      * The page breaker notifies the provider about the page number an element list starts
      * on so it can later retrieve PageViewports relative to this first page.
@@ -346,7 +352,11 @@ public class PageProvider implements Constants {
         boolean isFirstPage = (startPageOfPageSequence == index);
         SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
                 index, isFirstPage, isLastPage, isBlank);
-        Page page = new Page(spm, index, pageNumberString, isBlank, spanAll);
+        boolean isPagePositionOnly = pageSeq.hasPagePositionOnly() && !skipPagePositionOnly;
+        if (isPagePositionOnly) {
+            spm = pageSeq.getNextSimplePageMaster(index, isFirstPage, true, isBlank);
+        }
+        Page page = new Page(spm, index, pageNumberString, isBlank, spanAll, isPagePositionOnly);
         //Set unique key obtained from the AreaTreeHandler
         page.getPageViewport().setKey(areaTreeHandler.generatePageViewportKey());
         page.getPageViewport().setForeignAttributes(spm.getForeignAttributes());
@@ -372,7 +382,7 @@ public class PageProvider implements Constants {
         int index = this.cachedPages.size();
         boolean isFirstPage = (startPageOfPageSequence == index);
         SimplePageMaster spm = pageSeq.getLastSimplePageMaster(index, isFirstPage, false);
-        Page page = new Page(spm, index, "", false, false);
+        Page page = new Page(spm, index, "", false, false, false);
         if (pageSeq.getRoot().getLastSeq() != null && pageSeq.getRoot().getLastSeq() != pageSeq) {
             return -1;
         }
index 0ee7121aff0b34944b75fb72c8ef100d37e48b6f..cfcaabb33e0161430ec45eacf19bcd385d76213a 100644 (file)
@@ -131,15 +131,25 @@ public class PageSequenceLayoutManager extends AbstractPageSequenceLayoutManager
             log.debug("Starting layout");
         }
 
-        curPage = makeNewPage(false);
-
-        pageBreaker = new PageBreaker(this);
-        int flowBPD = getCurrentPV().getBodyRegion().getRemainingBPD();
-        pageBreaker.doLayout(flowBPD);
+        boolean finished = false;
+        while (!finished) {
+            initialize();
+            curPage = makeNewPage(false);
+
+            pageBreaker = new PageBreaker(this);
+            int flowBPD = getCurrentPV().getBodyRegion().getRemainingBPD();
+            finished = pageBreaker.doLayout(flowBPD);
+            pageProvider.skipPagePositionOnly = true;
+        }
 
         finishPage();
     }
 
+    public void initialize() {
+        super.initialize();
+        pageProvider.initialize();
+    }
+
     /** {@inheritDoc} */
     public void finishPageSequence() {
         if (pageSeq.hasId()) {
diff --git a/fop/test/layoutengine/standard-testcases/page-position_only_2.xml b/fop/test/layoutengine/standard-testcases/page-position_only_2.xml
new file mode 100644 (file)
index 0000000..08a485a
--- /dev/null
@@ -0,0 +1,80 @@
+<?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">
+  <fo:layout-master-set>
+    <fo:simple-page-master margin-left="20mm" margin-right="20mm" page-height="297mm" page-width="210mm" master-name="OnlyPage" margin-bottom="5mm" margin-top="12mm">
+      <fo:region-body region-name="Body" margin-bottom="30mm" margin-top="105mm" background-color="red" />
+    </fo:simple-page-master>
+    <fo:simple-page-master page-height="297mm" page-width="210mm" master-name="FrontPage" margin-bottom="5mm" margin-left="20mm" margin-right="20mm" margin-top="12mm">
+      <fo:region-body region-name="Body" margin-bottom="70mm" margin-top="105mm" background-color="green" />
+    </fo:simple-page-master>
+    <fo:simple-page-master page-height="297mm" page-width="210mm" master-name="BackPage" margin-bottom="5mm" margin-left="20mm" margin-right="20mm" margin-top="15mm">
+      <fo:region-body region-name="Body" margin-bottom="30mm" margin-top="20mm" background-color="transparent" />
+    </fo:simple-page-master>
+    <fo:page-sequence-master master-name="LetterPages">
+      <fo:repeatable-page-master-alternatives>
+        <fo:conditional-page-master-reference master-reference="OnlyPage" page-position="only" />
+        <fo:conditional-page-master-reference master-reference="FrontPage" page-position="first" />
+        <fo:conditional-page-master-reference master-reference="BackPage" page-position="rest" />
+        <fo:conditional-page-master-reference master-reference="BackPage" page-position="last" />
+      </fo:repeatable-page-master-alternatives>
+    </fo:page-sequence-master>
+  </fo:layout-master-set>
+  <fo:page-sequence master-reference="LetterPages" force-page-count="auto" initial-page-number="auto">
+
+    <fo:flow flow-name="Body">
+      <fo:block>
+        <fo:block>1test</fo:block>
+        <fo:block>2test</fo:block>
+        <fo:block>3test</fo:block>
+        <fo:block>4test</fo:block>
+        <fo:block>5test</fo:block>
+        <fo:block>6test</fo:block>
+        <fo:block>7test</fo:block>
+        <fo:block>8test</fo:block>
+        <fo:block>9test</fo:block>
+        <fo:block>10test</fo:block>
+        <fo:block>11test</fo:block>
+        <fo:block>12test</fo:block>
+        <fo:block>13test</fo:block>
+        <fo:block>14test</fo:block>
+        <fo:block>15test</fo:block>
+        <fo:block>16test</fo:block>
+        <fo:block>17test</fo:block>
+        <fo:block>18test</fo:block>
+        <fo:block>19test</fo:block>
+        <fo:block>20test</fo:block>
+        <fo:block>21test</fo:block>
+      </fo:block>
+
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
+  </fo>
+  <checks>
+    <eval expected="21test" xpath="//pageViewport[1]//flow/block/block[21]/lineArea[1]/text/word[1]"/>
+  </checks>
+</testcase>