]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
b49835
authorAndreas L. Delmelle <adelmelle@apache.org>
Mon, 7 Mar 2011 23:04:03 +0000 (23:04 +0000)
committerAndreas L. Delmelle <adelmelle@apache.org>
Mon, 7 Mar 2011 23:04:03 +0000 (23:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1079013 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
src/java/org/apache/fop/layoutmgr/KnuthPenalty.java
test/layoutengine/standard-testcases/fox_disable-column-balancing.xml
test/layoutengine/standard-testcases/keep-together_overflow-recovery_bug49835.xml [new file with mode: 0644]

index edea3aa7943af4c7b49a3c7e8a72254cb9816381..f05efb40f968cdbf8449ff7f27e81afc570bed92 100644 (file)
@@ -542,7 +542,6 @@ public abstract class BreakingAlgorithm {
         addNode(0, createNode(firstBoxIndex, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, null));
         KnuthNode lastForced = getNode(0);
 
-
         if (log.isTraceEnabled()) {
             log.trace("Looping over " + (par.size() - startIndex) + " elements");
             log.trace(par);
@@ -631,6 +630,17 @@ public abstract class BreakingAlgorithm {
             log.debug("Recovering from too long: " + lastTooLong);
         }
 
+        // if lastTooLong would be the very first break in the blockList, and
+        // the first element in the paragraph is not a penalty, add an auxiliary
+        // penalty now to make it possible to create a genuine 'empty' node that
+        // represents a break before the first box/glue
+        if (lastTooLong.previous.previous == null) {
+            ListElement el = (ListElement)this.par.get(0);
+            if (!el.isPenalty()) {
+                this.par.add(0, KnuthPenalty.DUMMY_ZERO_PENALTY);
+            }
+        }
+        
         // content would overflow, insert empty line/page and try again
         return createNode(
                 lastTooLong.previous.position, lastTooLong.previous.line + 1, 1,
@@ -873,6 +883,7 @@ public abstract class BreakingAlgorithm {
         if (log.isDebugEnabled()) {
             log.debug("Restarting at node " + restartingNode);
         }
+
         restartingNode.totalDemerits = 0;
         addNode(restartingNode.line, restartingNode);
         startLine = restartingNode.line;
index c17e9c7a22daa9586b9f26a6039b2d37b81b7999..22a74485ee20a802511ed10570299f40673e3067 100644 (file)
@@ -43,6 +43,9 @@ public class KnuthPenalty extends KnuthElement {
 
     /** Used for flagged penalties. See Knuth algorithm. */
     public static final int FLAGGED_PENALTY = 50;
+    /** Dummy, zero-width penalty */
+    public static final KnuthPenalty DUMMY_ZERO_PENALTY
+            = new KnuthPenalty(0, 0, false, null, true);
 
     private int penalty;
     private boolean penaltyFlagged;
index 888de0394d2cc7fd92753d56234852d108fd9570..ffb300d820f1c8f1d0f7eb274992d239bc94a3bd 100644 (file)
   <checks>
     <eval expected="0" xpath="//pageSequence[1]/pageViewport[2]//span[1]/flow[2]/@bpd"/>
     <eval expected="0" xpath="//pageSequence[1]/pageViewport[2]//span[1]/flow[2]/@bpd"/>
-    <eval expected="12000" xpath="//pageSequence[1]/pageViewport[3]//span[2]/@bpd"/>
-    <!-- TODO Replace with the following test once bugs affecting multiple columns have been 
-    corrected
-        <eval expected="0" xpath="count(//pageSequence[1]/pageViewport[3]//block[@prod-id='span2'])"/>
-    -->
+    <eval expected="0" xpath="count(//pageSequence[1]/pageViewport[3]//block[@prod-id='span2'])"/>
 
     <eval expected="24000" xpath="//pageSequence[2]/pageViewport[2]//span[1]/flow[2]/@bpd"/>
     <eval expected="84000" xpath="//pageSequence[2]/pageViewport[3]//span[1]/flow[2]/@bpd"/>
diff --git a/test/layoutengine/standard-testcases/keep-together_overflow-recovery_bug49835.xml b/test/layoutengine/standard-testcases/keep-together_overflow-recovery_bug49835.xml
new file mode 100644 (file)
index 0000000..50ed365
--- /dev/null
@@ -0,0 +1,161 @@
+<?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 an issue with overflow recovery if there is no 
+    previous break. See also Bugzilla 49835. The test checks behavior both
+    in single- and multi-column layout. 
+    Expected behavior: in case the next page does not have more space available, 
+    content should just overflow on the first page. Otherwise, the entire block 
+    should be deferred to the next page, but only if it can be kept together there.
+    </p>
+  </info>
+  <fo>
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+      <fo:layout-master-set>
+        <fo:simple-page-master master-name="master-short-single" page-width="10cm" page-height="2cm">
+          <fo:region-body />
+        </fo:simple-page-master>
+        <fo:simple-page-master master-name="master-longer-single" page-width="10cm" page-height="2.5cm">
+          <fo:region-body />
+        </fo:simple-page-master>
+        <fo:simple-page-master master-name="master-long-single" page-width="10cm" page-height="5cm">
+          <fo:region-body />
+        </fo:simple-page-master>
+        <fo:simple-page-master master-name="master-short-multi" page-width="10cm" page-height="2cm">
+          <fo:region-body column-count="3"/>
+        </fo:simple-page-master>
+        <fo:simple-page-master master-name="master-longer-multi" page-width="10cm" page-height="2.5cm">
+          <fo:region-body column-count="3"/>
+        </fo:simple-page-master>
+        <fo:simple-page-master master-name="master-long-multi" page-width="10cm" page-height="5cm">
+          <fo:region-body column-count="3"/>
+        </fo:simple-page-master>
+        <fo:page-sequence-master master-name="master-one">
+          <fo:single-page-master-reference master-reference="master-short-single"/>
+        </fo:page-sequence-master>
+        <fo:page-sequence-master master-name="master-two">
+          <fo:single-page-master-reference master-reference="master-short-single"/>
+          <fo:single-page-master-reference master-reference="master-long-single"/>
+        </fo:page-sequence-master>
+        <fo:page-sequence-master master-name="master-three">
+          <fo:single-page-master-reference master-reference="master-short-multi"/>
+        </fo:page-sequence-master>
+        <fo:page-sequence-master master-name="master-four">
+          <fo:single-page-master-reference master-reference="master-short-multi"/>
+          <fo:single-page-master-reference master-reference="master-long-multi"/>
+        </fo:page-sequence-master>
+        <fo:page-sequence-master master-name="master-five">
+          <fo:single-page-master-reference master-reference="master-short-single"/>
+          <fo:single-page-master-reference master-reference="master-longer-single"/>
+        </fo:page-sequence-master>
+        <fo:page-sequence-master master-name="master-six">
+          <fo:single-page-master-reference master-reference="master-short-multi"/>
+          <fo:single-page-master-reference master-reference="master-longer-multi"/>
+        </fo:page-sequence-master>
+      </fo:layout-master-set>
+      <fo:page-sequence master-reference="master-one">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:block id="block-1" keep-together.within-column="always">
+            <fo:block>Line 1</fo:block>
+            <fo:block>Line 2</fo:block>
+            <fo:block>Line 3</fo:block>
+            <fo:block>Line 4</fo:block>
+            <fo:block>Line 5</fo:block>
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+      <fo:page-sequence master-reference="master-two">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:block id="block-2" keep-together.within-column="always">
+            <fo:block>Line 1</fo:block>
+            <fo:block>Line 2</fo:block>
+            <fo:block>Line 3</fo:block>
+            <fo:block>Line 4</fo:block>
+            <fo:block>Line 5</fo:block>
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+      <fo:page-sequence master-reference="master-three">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:block id="block-3" keep-together.within-column="always">
+            <fo:block>Line 1</fo:block>
+            <fo:block>Line 2</fo:block>
+            <fo:block>Line 3</fo:block>
+            <fo:block>Line 4</fo:block>
+            <fo:block>Line 5</fo:block>
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+      <fo:page-sequence master-reference="master-four">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:block id="block-4" keep-together.within-column="always">
+            <fo:block>Line 1</fo:block>
+            <fo:block>Line 2</fo:block>
+            <fo:block>Line 3</fo:block>
+            <fo:block>Line 4</fo:block>
+            <fo:block>Line 5</fo:block>
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+      <fo:page-sequence master-reference="master-five">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:block id="block-5" keep-together.within-column="always">
+            <fo:block>Line 1</fo:block>
+            <fo:block>Line 2</fo:block>
+            <fo:block>Line 3</fo:block>
+            <fo:block>Line 4</fo:block>
+            <fo:block>Line 5</fo:block>
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+      <fo:page-sequence master-reference="master-six">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:block id="block-6" keep-together.within-column="always">
+            <fo:block>Line 1</fo:block>
+            <fo:block>Line 2</fo:block>
+            <fo:block>Line 3</fo:block>
+            <fo:block>Line 4</fo:block>
+            <fo:block>Line 5</fo:block>
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <checks>
+    <!-- overflow on first page -->
+    <eval expected="1" xpath="count(//pageSequence[1]/pageViewport)" />
+    <eval expected="1" xpath="count(//pageSequence[1]//span[.//block[@prod-id='block-1']])" />
+    <!-- deferral to second page -->
+    <eval expected="2" xpath="count(//pageSequence[2]/pageViewport)" />
+    <eval expected="1" xpath="count(//pageSequence[2]//span[.//block[@prod-id='block-2']])" />
+    <!-- overflow on first page, first column -->
+    <eval expected="1" xpath="count(//pageSequence[3]/pageViewport)" />
+    <eval expected="1" xpath="count(//pageSequence[3]//span[.//block[@prod-id='block-3']])" />
+    <!-- deferral to second page, first column -->
+    <eval expected="2" xpath="count(//pageSequence[4]/pageViewport)" />
+    <eval expected="1" xpath="count(//pageSequence[4]//span[.//block[@prod-id='block-4']])" />
+    <!-- overflow on first page -->
+    <eval expected="1" xpath="count(//pageSequence[5]/pageViewport)" />
+    <eval expected="1" xpath="count(//pageSequence[5]//span[.//block[@prod-id='block-5']])" />
+    <!-- overflow on first page, first column -->
+    <eval expected="1" xpath="count(//pageSequence[6]/pageViewport)" />
+    <eval expected="1" xpath="count(//pageSequence[6]//span[.//block[@prod-id='block-6']])" />
+  </checks>
+</testcase>