git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1360665 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
protected void addAreas(PageBreakingAlgorithm alg, int startPart, int partCount, | protected void addAreas(PageBreakingAlgorithm alg, int startPart, int partCount, | ||||
BlockSequence originalList, BlockSequence effectiveList) { | BlockSequence originalList, BlockSequence effectiveList) { | ||||
LayoutContext childLC; | LayoutContext childLC; | ||||
// add areas | |||||
int startElementIndex = 0; | int startElementIndex = 0; | ||||
int endElementIndex = 0; | int endElementIndex = 0; | ||||
int lastBreak = -1; | int lastBreak = -1; | ||||
// ignore KnuthGlue and KnuthPenalty objects | // ignore KnuthGlue and KnuthPenalty objects | ||||
// at the beginning of the line | // 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 (startElementIndex <= endElementIndex) { | ||||
if (log.isDebugEnabled()) { | if (log.isDebugEnabled()) { | ||||
&& p < (partCount - 1)) { | && p < (partCount - 1)) { | ||||
// count the boxes whose width is not 0 | // count the boxes whose width is not 0 | ||||
int boxCount = 0; | int boxCount = 0; | ||||
effectiveListIterator = effectiveList.listIterator(startElementIndex); | |||||
@SuppressWarnings("unchecked") | |||||
ListIterator<KnuthElement> effectiveListIterator = effectiveList | |||||
.listIterator(startElementIndex); | |||||
while (effectiveListIterator.nextIndex() <= endElementIndex) { | while (effectiveListIterator.nextIndex() <= endElementIndex) { | ||||
KnuthElement tempEl = effectiveListIterator.next(); | KnuthElement tempEl = effectiveListIterator.next(); | ||||
if (tempEl.isBox() && tempEl.getWidth() > 0) { | if (tempEl.isBox() && tempEl.getWidth() > 0) { |
// index of the first KnuthBox in the sequence, in case of non-centered | // index of the first KnuthBox in the sequence, in case of non-centered | ||||
// alignment. For centered alignment, we need to take into account preceding | // alignment. For centered alignment, we need to take into account preceding | ||||
// penalties+glues used for the filler spaces | // penalties+glues used for the filler spaces | ||||
int firstBoxIndex = startIndex; | |||||
int previousPosition = startIndex; | |||||
if (alignment != Constants.EN_CENTER) { | 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 | // 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); | KnuthNode lastForced = getNode(0); | ||||
if (log.isTraceEnabled()) { | if (log.isTraceEnabled()) { |
package org.apache.fop.layoutmgr; | package org.apache.fop.layoutmgr; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.ListIterator; | import java.util.ListIterator; | ||||
: (ListElement) get(index); | : (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) { | protected int getFirstBoxIndex(int startIndex) { | ||||
if (isEmpty() || startIndex < 0 || startIndex >= size()) { | |||||
return -1; | |||||
if (startIndex < 0 || startIndex >= size()) { | |||||
return startIndex; | |||||
} else { | } 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; | |||||
} | } | ||||
} | } | ||||
//Get page break from which we restart | //Get page break from which we restart | ||||
PageBreakPosition pbp = (PageBreakPosition) | PageBreakPosition pbp = (PageBreakPosition) | ||||
alg.getPageBreaks().get(restartPoint - 1); | 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 | //Handle page break right here to avoid any side-effects | ||||
if (newStartPos > 0) { | if (newStartPos > 0) { | ||||
handleBreakTrait(Constants.EN_PAGE); | handleBreakTrait(Constants.EN_PAGE); |
documents. Example: the fix of marks layering will be such a case when it's done. | documents. Example: the fix of marks layering will be such a case when it's done. | ||||
--> | --> | ||||
<release version="FOP Trunk" date="TBD"> | <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"> | <action context="Test" dev="GA" type="fix"> | ||||
Fix errors and warnings in example files. Add build.xml for documentation examples. | Fix errors and warnings in example files. Add build.xml for documentation examples. | ||||
</action> | </action> |
@RunWith(Parameterized.class) | @RunWith(Parameterized.class) | ||||
public class IFParserTestCase extends AbstractIFTest { | 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 | * Gets the parameters for this test | ||||
* | * | ||||
*/ | */ | ||||
@Parameters | @Parameters | ||||
public static Collection<File[]> getParameters() throws IOException { | 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(); | |||||
} | } | ||||
/** | /** |
*/ | */ | ||||
public final class LayoutEngineTestUtils { | 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() { | private LayoutEngineTestUtils() { | ||||
} | } | ||||
} | } | ||||
Collection<File[]> parametersForJUnit4 = new ArrayList<File[]>(); | Collection<File[]> parametersForJUnit4 = new ArrayList<File[]>(); | ||||
int index = 0; | |||||
for (File f : files) { | for (File f : files) { | ||||
parametersForJUnit4.add(new File[] { f }); | parametersForJUnit4.add(new File[] { f }); | ||||
if (DEBUG) { | |||||
System.out.println(String.format("%3d %s", index++, f)); | |||||
} | |||||
} | } | ||||
return parametersForJUnit4; | return parametersForJUnit4; |