int remainingWidth = maxAvailableWidth;
LineBox currentLine = newLine(c, initialY, box);
LineBox previousLine = null;
InlineLayoutBox currentIB = null;
InlineLayoutBox previousIB = null;
int contentStart = 0;
List openInlineBoxes = null;
Map iBMap = new HashMap();
if (box instanceof AnonymousBlockBox) {
openInlineBoxes = ((AnonymousBlockBox)box).getOpenInlineBoxes();
if (openInlineBoxes != null) {
openInlineBoxes = new ArrayList(openInlineBoxes);
currentIB = addOpenInlineBoxes(
c, currentLine, openInlineBoxes, maxAvailableWidth, iBMap);
}
}
if (openInlineBoxes == null) {
openInlineBoxes = new ArrayList();
}
remainingWidth -= c.getBlockFormattingContext().getFloatDistance(c, currentLine, remainingWidth);
CalculatedStyle parentStyle = box.getStyle();
int minimumLineHeight = (int) parentStyle.getLineHeight(c);
int indent = (int) parentStyle.getFloatPropertyProportionalWidth(CSSName.TEXT_INDENT, maxAvailableWidth, c);
remainingWidth -= indent;
contentStart += indent;
MarkerData markerData = c.getCurrentMarkerData();
if (markerData != null && box.getStyle().isListMarkerInside()) {
remainingWidth -= markerData.getLayoutWidth();
contentStart += markerData.getLayoutWidth();
}
c.setCurrentMarkerData(null);
List pendingFloats = new ArrayList();
int pendingLeftMBP = 0;
int pendingRightMBP = 0;
boolean hasFirstLinePEs = false;
List pendingInlineLayers = new ArrayList();
if (c.getFirstLinesTracker().hasStyles()) {
box.styleText(c, c.getFirstLinesTracker().deriveAll(box.getStyle()));
hasFirstLinePEs = true;
}
boolean needFirstLetter = c.getFirstLettersTracker().hasStyles();
boolean zeroWidthInlineBlock = false;
int lineOffset = 0;
for (Iterator i = box.getInlineContent().iterator(); i.hasNext(); ) {
Styleable node = (Styleable)i.next();
if (node.getStyle().isInline()) {
InlineBox iB = (InlineBox)node;
CalculatedStyle style = iB.getStyle();
if (iB.isStartsHere()) {
previousIB = currentIB;
currentIB = new InlineLayoutBox(c, iB.getElement(), style, maxAvailableWidth);
openInlineBoxes.add(iB);
iBMap.put(iB, currentIB);
if (previousIB == null) {
currentLine.addChildForLayout(c, currentIB);
} else {
previousIB.addInlineChild(c, currentIB);
}
if (currentIB.getElement() != null) {
String name = c.getNamespaceHandler().getAnchorName(currentIB.getElement());
if (name != null) {
c.addBoxId(name, currentIB);
}
String id = c.getNamespaceHandler().getID(currentIB.getElement());
if (id != null) {
c.addBoxId(id, currentIB);
}
}
//To break the line well, assume we don't just want to paint padding on next line
pendingLeftMBP += style.getMarginBorderPadding(
c, maxAvailableWidth, CalculatedStyle.LEFT);
pendingRightMBP += style.getMarginBorderPadding(
c, maxAvailableWidth, CalculatedStyle.RIGHT);
}
LineBreakContext lbContext = new LineBreakContext();
lbContext.setMaster(iB.getText());
lbContext.setTextNode(iB.getTextNode());
if (iB.isDynamicFunction()) {
lbContext.setMaster(iB.getContentFunction().getLayoutReplacementText());
}
do {
lbContext.reset();
int fit = 0;
if (lbContext.getStart() == 0) {
fit += pendingLeftMBP + pendingRightMBP;
}
boolean trimmedLeadingSpace = false;
if (hasTrimmableLeadingSpace(
currentLine, style, lbContext, zeroWidthInlineBlock)) {
trimmedLeadingSpace = true;
trimLeadingSpace(lbContext);
}
lbContext.setEndsOnNL(false);
zeroWidthInlineBlock = false;
if (lbContext.getStartSubstring().length() == 0) {
break;
}
if (needFirstLetter && !lbContext.isFinished()) {
InlineLayoutBox firstLetter =
addFirstLetterBox(c, currentLine, currentIB, lbContext,
maxAvailableWidth, remainingWidth);
remainingWidth -= firstLetter.getInlineWidth();
if (currentIB.isStartsHere()) {
pendingLeftMBP -= currentIB.getStyle().getMarginBorderPadding(
c, maxAvailableWidth, CalculatedStyle.LEFT);
}