git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1360665 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
@@ -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) { |
@@ -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()) { |
@@ -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; | |||
} | |||
} | |||
@@ -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); |
@@ -63,6 +63,10 @@ | |||
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="VH" type="fix"> | |||
When restarting layout for the last page, discard glues and penalties at the beginning of | |||
the restarted Knuth sequence. | |||
</action> | |||
<action context="Test" dev="GA" type="fix"> | |||
Fix errors and warnings in example files. Add build.xml for documentation examples. | |||
</action> |
@@ -48,9 +48,6 @@ import org.apache.fop.render.intermediate.IFSerializer; | |||
@RunWith(Parameterized.class) | |||
public class IFParserTestCase extends AbstractIFTest { | |||
/** Set this to true to get the correspondence between test number and test file. */ | |||
private static final boolean DEBUG = false; | |||
/** | |||
* Gets the parameters for this test | |||
* | |||
@@ -59,19 +56,7 @@ public class IFParserTestCase extends AbstractIFTest { | |||
*/ | |||
@Parameters | |||
public static Collection<File[]> getParameters() throws IOException { | |||
Collection<File[]> testFiles = LayoutEngineTestUtils.getLayoutTestFiles(); | |||
if (DEBUG) { | |||
printFiles(testFiles); | |||
} | |||
return testFiles; | |||
} | |||
private static void printFiles(Collection<File[]> files) { | |||
int index = 0; | |||
for (File[] file : files) { | |||
assert file.length == 1; | |||
System.out.println(String.format("%3d %s", index++, file[0])); | |||
} | |||
return LayoutEngineTestUtils.getLayoutTestFiles(); | |||
} | |||
/** |
@@ -51,6 +51,9 @@ import org.apache.commons.io.filefilter.TrueFileFilter; | |||
*/ | |||
public final class LayoutEngineTestUtils { | |||
/** Set this to true to get the correspondence between test number and test file. */ | |||
private static final boolean DEBUG = false; | |||
private LayoutEngineTestUtils() { | |||
} | |||
@@ -157,8 +160,12 @@ public final class LayoutEngineTestUtils { | |||
} | |||
Collection<File[]> parametersForJUnit4 = new ArrayList<File[]>(); | |||
int index = 0; | |||
for (File f : files) { | |||
parametersForJUnit4.add(new File[] { f }); | |||
if (DEBUG) { | |||
System.out.println(String.format("%3d %s", index++, f)); | |||
} | |||
} | |||
return parametersForJUnit4; |