aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas L. Delmelle <adelmelle@apache.org>2011-01-07 21:14:33 +0000
committerAndreas L. Delmelle <adelmelle@apache.org>2011-01-07 21:14:33 +0000
commit4de3abbc235c7e7d8efa0bc9bfd2bfa701e1767b (patch)
tree97f7a4194b3ae1006436920be2af886219e253b9
parent7c5be87cdb9d68effe8e968773b9159f02db06d1 (diff)
downloadxmlgraphics-fop-4de3abbc235c7e7d8efa0bc9bfd2bfa701e1767b.tar.gz
xmlgraphics-fop-4de3abbc235c7e7d8efa0bc9bfd2bfa701e1767b.zip
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
-rw-r--r--src/java/org/apache/fop/layoutmgr/ElementListUtils.java80
-rw-r--r--status.xml3
-rw-r--r--test/layoutengine/standard-testcases/fox_widow-content-limit_bug48380.xml61
3 files changed, 97 insertions, 47 deletions
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.
-->
<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>
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 @@
+<?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