KnuthSequence sequence = (KnuthSequence) seqIter.next();
ListIterator listIter = sequence.listIterator();
while (listIter.hasNext()) {
returnedElement = (KnuthElement) listIter.next();
returnedElement.setPosition
(notifyPos(new NonLeafPosition(this,
returnedElement.getPosition())));
}
if (!sequence.isInlineSequence()) {
if (lastSequence != null && lastSequence.isInlineSequence()) {
// log.error("Last inline sequence should be closed before"
// + " a block sequence");
lastSequence.add(new KnuthPenalty(0, -KnuthElement.INFINITE,
false, null, false));
lastSequence = null;
if (log.isTraceEnabled()) {
trace.append(" ]");
}
}
returnList.add(sequence);
if (log.isTraceEnabled()) {
trace.append(" B");
}
} else {
if (lastSequence == null) {
lastSequence = new KnuthSequence(true);
returnList.add(lastSequence);
if (!borderAdded) {
addKnuthElementsForBorderPaddingStart(lastSequence);
borderAdded = true;
}
if (log.isTraceEnabled()) {
trace.append(" [");
}
} else {
if (log.isTraceEnabled()) {
trace.append(" +");
}
}
lastSequence.addAll(sequence);
if (log.isTraceEnabled()) {
trace.append(" I");
}
// finish last paragraph if it was closed with a linefeed
KnuthElement lastElement = (KnuthElement) sequence.getLast();
if (lastElement.isPenalty()
&& ((KnuthPenalty) lastElement).getP()
== -KnuthPenalty.INFINITE) {
// a penalty item whose value is -inf
// represents a preserved linefeed,
// wich forces a line break
lastSequence = null;
if (log.isTraceEnabled()) {
trace.append(" ]");
}
}
}
}
} else { // A block LM
// close the last inline sequence
if (lastSequence != null && lastSequence.isInlineSequence()) {
lastSequence.add(new KnuthPenalty(0, -KnuthElement.INFINITE,
false, null, false));
lastSequence = null;
if (log.isTraceEnabled()) {
trace.append(" ]");
}
}
if (curLM != lastLM) {
// close the last block sequence
if (lastSequence != null && !lastSequence.isInlineSequence()) {
lastSequence = null;
if (log.isTraceEnabled()) {
trace.append(" ]");
}
}
lastLM = curLM;
}
if (lastSequence == null) {
lastSequence = new KnuthSequence(false);
returnList.add(lastSequence);
if (log.isTraceEnabled()) {
trace.append(" [");
}
if (!borderAdded) {
addKnuthElementsForBorderPaddingStart(lastSequence);
borderAdded = true;
}
} else {
if (log.isTraceEnabled()) {
trace.append(" +");
}
}
ListIterator iter = returnedList.listIterator();
while (iter.hasNext()) {
KnuthElement element = (KnuthElement) iter.next();
element.setPosition
(notifyPos(new NonLeafPosition(this,
element.getPosition())));
}
lastSequence.addAll(returnedList);
if (log.isTraceEnabled()) {
trace.append(" L");