boolean signalKeepWithNext = false;
int laststep = 0;
int step;
int addedBoxLen = 0;
TableContentPosition lastTCPos = null;
LinkedList returnList = new LinkedList();
while ((step = getNextStep(laststep)) >= 0) {
int normalRow = activeRow;
if (rowBacktrackForLastStep) {
//Even though we've already switched to the next row, we have to
//calculate as if we were still on the previous row
activeRow--;
}
int increase = step - laststep;
int penaltyLen = step + getMaxRemainingHeight() - totalHeight;
int boxLen = step - addedBoxLen - penaltyLen;
addedBoxLen += boxLen;
//Put all involved grid units into a list
List gridUnitParts = new java.util.ArrayList(maxColumnCount);
for (int i = 0; i < start.length; i++) {
if (end[i] >= start[i]) {
PrimaryGridUnit pgu = rowGroup[startRow[i]].getGridUnit(i).getPrimary();
if (start[i] == 0 && end[i] == 0
&& elementLists[i].size() == 1
&& elementLists[i].get(0) instanceof KnuthBoxCellWithBPD) {
//Special case: Cell with fixed BPD
gridUnitParts.add(new GridUnitPart(pgu,
0, pgu.getElements().size() - 1));
} else {
gridUnitParts.add(new GridUnitPart(pgu, start[i], end[i]));
}
if (end[i] + 1 == elementLists[i].size()) {
if (pgu.getFlag(GridUnit.KEEP_WITH_NEXT_PENDING)) {
log.debug("PGU has pending keep-with-next");
keepWithNextSignals[i] = true;
}
if (pgu.getRow() != null && pgu.getRow().mustKeepWithNext()) {
log.debug("table-row causes keep-with-next");
keepWithNextSignals[i] = true;
}
}
if (start[i] == 0 && end[i] >= 0) {
if (pgu.getFlag(GridUnit.KEEP_WITH_PREVIOUS_PENDING)) {
log.debug("PGU has pending keep-with-previous");
if (returnList.size() == 0) {
context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
}
}
if (pgu.getRow() != null && pgu.getRow().mustKeepWithPrevious()) {
log.debug("table-row causes keep-with-previous");
if (returnList.size() == 0) {
context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
}
}
}
}
}
//log.debug(">>> guPARTS: " + gridUnitParts);
//Create elements for step
int effPenaltyLen = penaltyLen;
TableContentPosition tcpos = new TableContentPosition(getTableLM(),
gridUnitParts, rowGroup[normalRow]);
if (returnList.size() == 0) {
tcpos.setFlag(TableContentPosition.FIRST_IN_ROWGROUP, true);
}
lastTCPos = tcpos;
if (log.isDebugEnabled()) {
log.debug(" - backtrack=" + rowBacktrackForLastStep
+ " - row=" + activeRow + " - " + tcpos);