From: Andreas L. Delmelle Date: Fri, 7 Jan 2011 21:14:33 +0000 (+0000) Subject: Bugzilla 48380: Avoid ClassCastException when using fox:widow-content-limit X-Git-Tag: fop-1_1rc1old~385 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4de3abbc235c7e7d8efa0bc9bfd2bfa701e1767b;p=xmlgraphics-fop.git Bugzilla 48380: Avoid ClassCastException when using fox:widow-content-limit git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1056513 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/layoutmgr/ElementListUtils.java b/src/java/org/apache/fop/layoutmgr/ElementListUtils.java index 6a843ac63..2bd6f429a 100644 --- a/src/java/org/apache/fop/layoutmgr/ElementListUtils.java +++ b/src/java/org/apache/fop/layoutmgr/ElementListUtils.java @@ -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(); } /** diff --git a/status.xml b/status.xml index 2f2608cfd..16ef4dfe6 100644 --- a/status.xml +++ b/status.xml @@ -58,6 +58,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Bugfix: avoid ClassCastException when using fox:widow-content-limit + Bugfix: content after forced break in block-container is not rendered. diff --git a/test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml b/test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml new file mode 100644 index 000000000..7dab0b3af --- /dev/null +++ b/test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml @@ -0,0 +1,61 @@ + + + + + +

+ Check for bug 48380: ClassCastException when using fox:widow-content-limit. +

+
+ + + + + + + + + + + + + + + + + + . + + + test + + + + + + + + + + + + + + + +
\ No newline at end of file