* @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);
}
/**
* @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;
KnuthElement kel = (KnuthElement)el;
len += kel.getWidth();
}
+
if (len >= constraint) {
return false;
}
}
+
return true;
}
* @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();
}
/**
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<!--\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+-->\r
+<!-- $Id$ -->\r
+<testcase>\r
+ <info>\r
+ <p>\r
+ Check for bug 48380: ClassCastException when using fox:widow-content-limit.\r
+ </p>\r
+ </info>\r
+ <fo>\r
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">\r
+ <fo:layout-master-set>\r
+ <fo:simple-page-master master-name="normal" page-width="210mm" page-height="297mm">\r
+ <fo:region-body/>\r
+ </fo:simple-page-master>\r
+ </fo:layout-master-set>\r
+ <fo:page-sequence master-reference="normal" white-space-collapse="true">\r
+ <fo:flow flow-name="xsl-region-body">\r
+ <fo:table fox:orphan-content-limit="4em" fox:widow-content-limit="4em" table-layout="fixed" width="100%">\r
+ <fo:table-body>\r
+ <fo:table-row>\r
+ <fo:table-cell>\r
+ <fo:block>\r
+ <fo:list-block space-after="6pt">\r
+ <fo:list-item>\r
+ <fo:list-item-label>\r
+ <fo:block>.</fo:block>\r
+ </fo:list-item-label>\r
+ <fo:list-item-body>\r
+ <fo:block start-indent="1cm">test</fo:block>\r
+ </fo:list-item-body>\r
+ </fo:list-item>\r
+ </fo:list-block>\r
+ </fo:block>\r
+ </fo:table-cell>\r
+ </fo:table-row>\r
+ </fo:table-body>\r
+ </fo:table>\r
+ </fo:flow>\r
+ </fo:page-sequence>\r
+ </fo:root>\r
+ </fo>\r
+ <checks>\r
+ <!-- Run only basic checks; should not throw a ClassCastException -->\r
+ </checks>\r
+</testcase>
\ No newline at end of file