LinkedList returnedList;
KnuthElement returnedElement;
// the list which will be returned to the parent LM
LinkedList returnList = new LinkedList();
KnuthSequence lastSequence = null;
SpaceSpecifier leadingSpace = context.getLeadingSpace();
alignmentContext = new AlignmentContext(font
, lineHeight.getOptimum(this).getLength().getValue(this)
, alignmentAdjust
, alignmentBaseline
, baselineShift
, dominantBaseline
, context.getAlignmentContext());
childLC = new LayoutContext(context);
childLC.setAlignmentContext(alignmentContext);
if (context.startsNewArea()) {
// First call to this LM in new parent "area", but this may
// not be the first area created by this inline
if (getSpaceStart() != null) {
context.getLeadingSpace().addSpace(new SpaceVal(getSpaceStart(), this));
}
// Check for "fence"
if (hasLeadingFence(!context.isFirstArea())) {
// Reset leading space sequence for child areas
leadingSpace = new SpaceSpecifier(false);
}
// Reset state variables
clearPrevIPD(); // Clear stored prev content dimensions
}
StringBuffer trace = new StringBuffer("InlineLM:");
// We'll add the border to the first inline sequence created.
// This flag makes sure we do it only once.
boolean borderAdded = false;
if (borderProps != null) {
childLC.setLineStartBorderAndPaddingWidth(context.getLineStartBorderAndPaddingWidth()
+ borderProps.getPaddingStart(true, this)
+ borderProps.getBorderStartWidth(true)
);
childLC.setLineEndBorderAndPaddingWidth(context.getLineEndBorderAndPaddingWidth()
+ borderProps.getPaddingEnd(true, this)
+ borderProps.getBorderEndWidth(true)
);
}
while ((curLM = (LayoutManager) getChildLM()) != null) {
if (!(curLM instanceof InlineLevelLayoutManager)) {
// A block LM
// Leave room for start/end border and padding
if (borderProps != null) {
childLC.setRefIPD(childLC.getRefIPD()
- borderProps.getPaddingStart(lastChildLM != null, this)
- borderProps.getBorderStartWidth(lastChildLM != null)
- borderProps.getPaddingEnd(hasNextChildLM(), this)
- borderProps.getBorderEndWidth(hasNextChildLM()));
}
}
// get KnuthElements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment);
if (returnedList == null) {
// curLM returned null because it finished;
// just iterate once more to see if there is another child
continue;
}
if (curLM instanceof InlineLevelLayoutManager) {
// close the last block sequence
if (lastSequence != null && !lastSequence.isInlineSequence()) {
lastSequence = null;
if (log.isTraceEnabled()) {
trace.append(" ]");
}
}
// "wrap" the Position stored in each element of returnedList
ListIterator seqIter = returnedList.listIterator();
while (seqIter.hasNext()) {
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) {