}
boolean needToAddSpacing = true;
// do the merging ..
final FastStack contextStack = new FastStack(50);
RenderNode next = nextBox.getFirstChild();
MergeContext context = new MergeContext(lineBox, nextBox);
while (next != null)
{
// process next
final RenderBox writeContext = context.getWriteContext();
final StaticBoxLayoutProperties staticBoxLayoutProperties = writeContext.getStaticBoxLayoutProperties();
long spaceWidth = staticBoxLayoutProperties.getSpaceWidth();
if (spaceWidth == 0)
{
// Space has not been computed yet.
final FontMetrics fontMetrics = metaData.getFontMetrics(writeContext.getStyleSheet());
spaceWidth = fontMetrics.getCharWidth(' ');
staticBoxLayoutProperties.setSpaceWidth(spaceWidth);
}
if ((next.getNodeType() & LayoutNodeTypes.MASK_BOX) == LayoutNodeTypes.MASK_BOX)
{
final RenderBox nBox = (RenderBox) next;
final RenderNode firstChild = nBox.getFirstChild();
if (firstChild != null)
{
contextStack.push(context);
next = firstChild;
final RenderNode writeContextLastChild = writeContext.getLastChild();
if ((writeContextLastChild.getNodeType() & LayoutNodeTypes.MASK_BOX) == LayoutNodeTypes.MASK_BOX)
{
if (writeContextLastChild.getInstanceId() == nBox.getInstanceId())
{
context = new MergeContext((RenderBox) writeContextLastChild, nBox);
}
else
{
if (needToAddSpacing)
{
if (spaceWidth > 0)
{
// docmark: Used zero as new height
final SpacerRenderNode spacer = new SpacerRenderNode(spaceWidth, 0, false, 1);
spacer.setVirtualNode(true);
writeContext.addGeneratedChild(spacer);
}
needToAddSpacing = false;
}
final RenderBox newWriter = (RenderBox) nBox.derive(false);
newWriter.setVirtualNode(true);
writeContext.addGeneratedChild(newWriter);
context = new MergeContext(newWriter, nBox);
}
}
else
{
if (needToAddSpacing)
{
if (spaceWidth > 0)
{
// docmark: Used zero as new height
final SpacerRenderNode spacer = new SpacerRenderNode(spaceWidth, 0, false, 1);
spacer.setVirtualNode(true);
writeContext.addGeneratedChild(spacer);
}
needToAddSpacing = false;
}
final RenderBox newWriter = (RenderBox) nBox.derive(false);
newWriter.setVirtualNode(true);
writeContext.addGeneratedChild(newWriter);
context = new MergeContext(newWriter, nBox);
}
}
else
{
if (needToAddSpacing)
{
if (spaceWidth > 0)
{
// docmark: Used zero as new height
final SpacerRenderNode spacer = new SpacerRenderNode(spaceWidth, 0, false, 1);
spacer.setVirtualNode(true);
writeContext.addGeneratedChild(spacer);
}
needToAddSpacing = false;
}
final RenderNode box = nBox.derive(true);
box.setVirtualNode(true);
writeContext.addGeneratedChild(box);
next = nBox.getNext();
}
}
else
{
if (needToAddSpacing)
{
final RenderNode lastChild = writeContext.getLastChild();
if (spaceWidth > 0 && lastChild != null &&
(lastChild.getNodeType() != LayoutNodeTypes.TYPE_NODE_SPACER))
{
// docmark: Used zero as new height
final SpacerRenderNode spacer = new SpacerRenderNode(spaceWidth, 0, false, 1);
spacer.setVirtualNode(true);
writeContext.addGeneratedChild(spacer);
}
needToAddSpacing = false;
}
final RenderNode child = next.derive(true);
child.setVirtualNode(true);
writeContext.addGeneratedChild(child);
next = next.getNext();
}
while (next == null && contextStack.isEmpty() == false)
{
// Log.debug ("FINISH " + context.getReadContext());
next = context.getReadContext().getNext();
context = (MergeContext) contextStack.pop();
}
}
return rebuildLastLine(lineBox, (ParagraphPoolBox) nextBox.getNext());
}