diff options
Diffstat (limited to 'src/java')
4 files changed, 26 insertions, 48 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java b/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java index 5fa411101..0f7dda3e7 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java @@ -492,7 +492,6 @@ public abstract class AbstractBreaker { protected void addAreas(PageBreakingAlgorithm alg, int startPart, int partCount, BlockSequence originalList, BlockSequence effectiveList) { LayoutContext childLC; - // add areas int startElementIndex = 0; int endElementIndex = 0; int lastBreak = -1; @@ -550,12 +549,7 @@ public abstract class AbstractBreaker { // ignore KnuthGlue and KnuthPenalty objects // at the beginning of the line - ListIterator<KnuthElement> effectiveListIterator - = effectiveList.listIterator(startElementIndex); - while (effectiveListIterator.hasNext() - && !(effectiveListIterator.next()).isBox()) { - startElementIndex++; - } + startElementIndex = alg.par.getFirstBoxIndex(startElementIndex); if (startElementIndex <= endElementIndex) { if (log.isDebugEnabled()) { @@ -576,7 +570,9 @@ public abstract class AbstractBreaker { && p < (partCount - 1)) { // count the boxes whose width is not 0 int boxCount = 0; - effectiveListIterator = effectiveList.listIterator(startElementIndex); + @SuppressWarnings("unchecked") + ListIterator<KnuthElement> effectiveListIterator = effectiveList + .listIterator(startElementIndex); while (effectiveListIterator.nextIndex() <= endElementIndex) { KnuthElement tempEl = effectiveListIterator.next(); if (tempEl.isBox() && tempEl.getWidth() > 0) { diff --git a/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java index 7e55c31f6..3830878fe 100644 --- a/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java +++ b/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java @@ -532,14 +532,15 @@ public abstract class BreakingAlgorithm { // index of the first KnuthBox in the sequence, in case of non-centered // alignment. For centered alignment, we need to take into account preceding // penalties+glues used for the filler spaces - int firstBoxIndex = startIndex; + int previousPosition = startIndex; if (alignment != Constants.EN_CENTER) { - firstBoxIndex = par.getFirstBoxIndex(startIndex); + int firstBoxIndex = par.getFirstBoxIndex(startIndex); + previousPosition = (firstBoxIndex >= par.size()) ? startIndex : firstBoxIndex - 1; } - firstBoxIndex = (firstBoxIndex < 0) ? 0 : firstBoxIndex; + previousPosition = (previousPosition < 0) ? 0 : previousPosition; // create an active node representing the starting point - addNode(0, createNode(firstBoxIndex, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, null)); + addNode(0, createNode(previousPosition, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, null)); KnuthNode lastForced = getNode(0); if (log.isTraceEnabled()) { diff --git a/src/java/org/apache/fop/layoutmgr/KnuthSequence.java b/src/java/org/apache/fop/layoutmgr/KnuthSequence.java index d568da45e..8d5e77ae0 100644 --- a/src/java/org/apache/fop/layoutmgr/KnuthSequence.java +++ b/src/java/org/apache/fop/layoutmgr/KnuthSequence.java @@ -20,6 +20,7 @@ package org.apache.fop.layoutmgr; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -159,46 +160,26 @@ public abstract class KnuthSequence extends ArrayList { : (ListElement) get(index); } - /** @return the position index of the first box in this sequence */ - protected int getFirstBoxIndex() { - if (isEmpty()) { - return -1; - } else { - return getFirstBoxIndex(0); - } - } - /** - * Get the position index of the first box in this sequence, - * starting at the given index. If there is no box after the - * passed {@code startIndex}, the starting index itself is returned. - * @param startIndex the starting index for the lookup - * @return the absolute position index of the next box element + * Returns the position index of the first box in this sequence, starting at the given + * index. If {@code startIndex} is outside the bounds of this sequence, it is + * returned. + * + * @param startIndex the index from which to start the lookup + * @return the index of the next box element, {@link #size()} if there is no such + * element, {@code startIndex} if {@code (startIndex < 0 || startIndex >= size())} */ protected int getFirstBoxIndex(int startIndex) { - if (isEmpty() || startIndex < 0 || startIndex >= size()) { - return -1; + if (startIndex < 0 || startIndex >= size()) { + return startIndex; } else { - ListElement element = null; - int posIndex = startIndex; - int lastIndex = size(); - while ( posIndex < lastIndex ) { - element = getElement(posIndex); - if ( !element.isBox() ) { - posIndex++; - } else { - break; - } - } - if ( posIndex != startIndex ) { - if ( ( element != null ) && element.isBox() ) { - return posIndex - 1; - } else { - return startIndex; - } - } else { - return startIndex; + int boxIndex = startIndex; + @SuppressWarnings("unchecked") + Iterator<ListElement> iter = listIterator(startIndex); + while (iter.hasNext() && !iter.next().isBox()) { + boxIndex++; } + return boxIndex; } } diff --git a/src/java/org/apache/fop/layoutmgr/PageBreaker.java b/src/java/org/apache/fop/layoutmgr/PageBreaker.java index 8fd131a73..777180c55 100644 --- a/src/java/org/apache/fop/layoutmgr/PageBreaker.java +++ b/src/java/org/apache/fop/layoutmgr/PageBreaker.java @@ -330,7 +330,7 @@ public class PageBreaker extends AbstractBreaker { //Get page break from which we restart PageBreakPosition pbp = (PageBreakPosition) alg.getPageBreaks().get(restartPoint - 1); - newStartPos = pbp.getLeafPos() + 1; + newStartPos = alg.par.getFirstBoxIndex(pbp.getLeafPos() + 1); //Handle page break right here to avoid any side-effects if (newStartPos > 0) { handleBreakTrait(Constants.EN_PAGE); |