Author: adelmelle
Date: Fri Jan  7 21:14:33 2011
New Revision: 1056513

URL: http://svn.apache.org/viewvc?rev=1056513&view=rev
Log:
Bugzilla 48380: Avoid ClassCastException when using fox:widow-content-limit

Added:
    
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml
Modified:
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ElementListUtils.java
    xmlgraphics/fop/trunk/status.xml

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ElementListUtils.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ElementListUtils.java?rev=1056513&r1=1056512&r2=1056513&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ElementListUtils.java 
(original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ElementListUtils.java 
Fri Jan  7 21:14:33 2011
@@ -55,43 +55,7 @@ public final class ElementListUtils {
      * @return true if the constraint is bigger than the list contents
      */
     public static boolean removeLegalBreaks(List elements, int constraint) {
-        int len = 0;
-        ListIterator iter = elements.listIterator();
-        while (iter.hasNext()) {
-            ListElement el = (ListElement)iter.next();
-            if (el.isPenalty()) {
-                KnuthPenalty penalty = (KnuthPenalty)el;
-                //Convert all penalties to break inhibitors
-                if (penalty.getPenalty() < KnuthPenalty.INFINITE) {
-                    iter.set(new KnuthPenalty(penalty.getWidth(), 
KnuthPenalty.INFINITE,
-                            penalty.isPenaltyFlagged(), penalty.getPosition(),
-                            penalty.isAuxiliary()));
-                }
-            } else if (el.isGlue()) {
-                KnuthGlue glue = (KnuthGlue)el;
-                len += glue.getWidth();
-                iter.previous();
-                el = (ListElement)iter.previous();
-                iter.next();
-                if (el.isBox()) {
-                    iter.add(new KnuthPenalty(0, KnuthPenalty.INFINITE, false,
-                            null, false));
-                }
-                iter.next();
-            } else if (el instanceof BreakElement) {
-                BreakElement breakEl = (BreakElement)el;
-                if (breakEl.getPenaltyValue() < KnuthPenalty.INFINITE) {
-                    breakEl.setPenaltyValue(KnuthPenalty.INFINITE);
-                }
-            } else {
-                KnuthElement kel = (KnuthElement)el;
-                len += kel.getWidth();
-            }
-            if (len >= constraint) {
-                return false;
-            }
-        }
-        return true;
+        return removeLegalBreaks(elements, constraint, false);
     }
 
     /**
@@ -103,27 +67,48 @@ public final class ElementListUtils {
      * @return true if the constraint is bigger than the list contents
      */
     public static boolean removeLegalBreaksFromEnd(List elements, int 
constraint) {
+        return removeLegalBreaks(elements, constraint, true);
+    }
+
+    private static boolean removeLegalBreaks(List elements, int constraint, 
boolean fromEnd) {
+
         int len = 0;
-        ListIterator i = elements.listIterator(elements.size());
-        while (i.hasPrevious()) {
-            ListElement el = (ListElement)i.previous();
+        ListElement el;
+
+        for (ListIterator iter = elements.listIterator(fromEnd ? 
elements.size() : 0);
+                (fromEnd ? iter.hasPrevious() : iter.hasNext());) {
+
+            if (fromEnd) {
+                el = (ListElement) iter.previous();
+            } else {
+                el = (ListElement) iter.next();
+            }
+
             if (el.isPenalty()) {
                 KnuthPenalty penalty = (KnuthPenalty)el;
-                //Convert all penalties to break inhibitors
+                //Convert penalty to break inhibitor
                 if (penalty.getPenalty() < KnuthPenalty.INFINITE) {
-                    i.set(new KnuthPenalty(penalty.getWidth(), 
KnuthPenalty.INFINITE,
+                    iter.set(new KnuthPenalty(penalty.getWidth(), 
KnuthPenalty.INFINITE,
                             penalty.isPenaltyFlagged(), penalty.getPosition(),
                             penalty.isAuxiliary()));
                 }
             } else if (el.isGlue()) {
                 KnuthGlue glue = (KnuthGlue)el;
                 len += glue.getWidth();
-                el = (ListElement)i.previous();
-                i.next();
+                //check if previous is a box
+                if (!fromEnd) {
+                    iter.previous();
+                }
+                el = (ListElement)iter.previous();
+                iter.next();
                 if (el.isBox()) {
-                    i.add(new KnuthPenalty(0, KnuthPenalty.INFINITE, false,
+                    //add break inhibitor
+                    iter.add(new KnuthPenalty(0, KnuthPenalty.INFINITE, false,
                             null, false));
                 }
+                if (!fromEnd) {
+                    iter.next();
+                }
             } else if (el.isUnresolvedElement()) {
                 if (el instanceof BreakElement) {
                     BreakElement breakEl = (BreakElement)el;
@@ -138,10 +123,12 @@ public final class ElementListUtils {
                 KnuthElement kel = (KnuthElement)el;
                 len += kel.getWidth();
             }
+
             if (len >= constraint) {
                 return false;
             }
         }
+
         return true;
     }
 
@@ -191,8 +178,7 @@ public final class ElementListUtils {
      * @return true if the list ends with a forced break
      */
     public static boolean endsWithForcedBreak(List elems) {
-        ListElement last = (ListElement) ListUtil.getLast(elems);
-        return last.isForcedBreak();
+        return ((ListElement) ListUtil.getLast(elems)).isForcedBreak();
     }
 
     /**

Modified: xmlgraphics/fop/trunk/status.xml
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1056513&r1=1056512&r2=1056513&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Fri Jan  7 21:14:33 2011
@@ -58,6 +58,9 @@
       documents. Example: the fix of marks layering will be such a case when 
it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Layout" dev="AD" type="fix" fixes-bug="48380">
+        Bugfix: avoid ClassCastException when using fox:widow-content-limit
+      </action>
       <action context="Layout" dev="VH" type="fix" fixes-bug="50089">
         Bugfix: content after forced break in block-container is not rendered.
       </action>

Added: 
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml?rev=1056513&view=auto
==============================================================================
--- 
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml
 (added)
+++ 
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml
 Fri Jan  7 21:14:33 2011
@@ -0,0 +1,61 @@
+<?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>
+      Check for bug 48380: ClassCastException when using 
fox:widow-content-limit.
+    </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="normal" page-width="210mm" 
page-height="297mm">
+          <fo:region-body/>
+        </fo:simple-page-master>
+      </fo:layout-master-set>
+      <fo:page-sequence master-reference="normal" white-space-collapse="true">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:table fox:orphan-content-limit="4em" 
fox:widow-content-limit="4em" table-layout="fixed" width="100%">
+            <fo:table-body>
+              <fo:table-row>
+                <fo:table-cell>
+                  <fo:block>
+                    <fo:list-block space-after="6pt">
+                      <fo:list-item>
+                        <fo:list-item-label>
+                          <fo:block>.</fo:block>
+                        </fo:list-item-label>
+                        <fo:list-item-body>
+                          <fo:block start-indent="1cm">test</fo:block>
+                        </fo:list-item-body>
+                      </fo:list-item>
+                    </fo:list-block>
+                  </fo:block>
+                </fo:table-cell>
+              </fo:table-row>
+            </fo:table-body>
+          </fo:table>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <checks>
+    <!-- Run only basic checks; should not throw a ClassCastException -->
+  </checks>
+</testcase>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to