int[] end = {-1, -1};
int totalHeight = Math.max(fullHeights[0], fullHeights[1]);
int step;
int addedBoxHeight = 0;
Keep keepWithNextActive = Keep.KEEP_AUTO;
LinkedList<ListElement> returnList = new LinkedList<ListElement>();
while ((step = getNextStep(elementLists, start, end, partialHeights)) > 0) {
if (end[0] + 1 == elementLists[0].size()) {
keepWithNextActive = keepWithNextActive.compare(keepWithNextPendingOnLabel);
}
if (end[1] + 1 == elementLists[1].size()) {
keepWithNextActive = keepWithNextActive.compare(keepWithNextPendingOnBody);
}
// compute penalty height and box height
int penaltyHeight = step
+ getMaxRemainingHeight(fullHeights, partialHeights)
- totalHeight;
//Additional penalty height from penalties in the source lists
int additionalPenaltyHeight = 0;
int stepPenalty = 0;
KnuthElement endEl = (KnuthElement)elementLists[0].get(end[0]);
if (endEl instanceof KnuthPenalty) {
additionalPenaltyHeight = endEl.getWidth();
stepPenalty = Math.max(stepPenalty, endEl.getPenalty());
}
endEl = (KnuthElement)elementLists[1].get(end[1]);
if (endEl instanceof KnuthPenalty) {
additionalPenaltyHeight = Math.max(
additionalPenaltyHeight, endEl.getWidth());
stepPenalty = Math.max(stepPenalty, endEl.getPenalty());
}
int boxHeight = step - addedBoxHeight - penaltyHeight;
penaltyHeight += additionalPenaltyHeight; //Add AFTER calculating boxHeight!
// collect footnote information
// TODO this should really not be done like this. ListItemLM should remain as
// footnote-agnostic as possible
LinkedList<FootnoteBodyLayoutManager> footnoteList = null;
ListElement el;
for (int i = 0; i < elementLists.length; i++) {
for (int j = start[i]; j <= end[i]; j++) {
el = (ListElement) elementLists[i].get(j);
if (el instanceof KnuthBlockBox && ((KnuthBlockBox) el).hasAnchors()) {
if (footnoteList == null) {
footnoteList = new LinkedList<FootnoteBodyLayoutManager>();
}
footnoteList.addAll(((KnuthBlockBox) el).getFootnoteBodyLMs());
}
}
}
// add the new elements
addedBoxHeight += boxHeight;
ListItemPosition stepPosition = new ListItemPosition(this,
start[0], end[0], start[1], end[1]);
if (footnoteList == null) {
returnList.add(new KnuthBox(boxHeight, stepPosition, false));
} else {
returnList.add(new KnuthBlockBox(boxHeight, footnoteList, stepPosition, false));
}
if (addedBoxHeight < totalHeight) {
Keep keep = keepWithNextActive.compare(getKeepTogether());
int p = stepPenalty;
if (p > -KnuthElement.INFINITE) {
p = Math.max(p, keep.getPenalty());
}
returnList.add(new BreakElement(stepPosition, penaltyHeight, p, keep.getContext(),
context));
}
}
return returnList;