pushedOnFirstLine = new LinkedList();
pushedOnFirstLine = new ArrayList();
    public static void layoutContent(LayoutContext c, Box box, List contentList) {        //Here we should always be inside something that corresponds to a block-level element        //for formatting purposes        Rectangle bounds = new Rectangle();        bounds.width = c.getExtents().width;        validateBounds(bounds);        bounds.x = 0;        bounds.y = 0;        bounds.height = 0;        //dummy style to make sure that text nodes don't get extra padding and such        //doesn't work here because blocks may be inside inlines, losing inline styling:        //c.pushStyle(CascadedStyle.emptyCascadedStyle);        int blockLineHeight = FontUtil.lineHeight(box, c.getTextRenderer(), c.getGraphics(), c, c.getBlockFormattingContext());        LineMetrics blockLineMetrics = c.getTextRenderer().getLineMetrics(c.getGraphics(),                box.getStyle().getFont(c), "thequickbrownfoxjumpedoverthelazydogTHEQUICKBROWNFOXJUMPEDOVERTHELAZYDOG");        // prepare remaining width and first linebox        int remaining_width = bounds.width;        LineBox curr_line = newLine(box, bounds, null, blockLineMetrics, c);        LinkedList pushedOnFirstLine = null;        // account for text-indent        CalculatedStyle parentStyle = c.getCurrentStyle();        float indent = parentStyle.getFloatPropertyProportionalWidth(CSSName.TEXT_INDENT, remaining_width, c);        remaining_width = remaining_width - (int) indent;        curr_line.x = curr_line.x + (int) indent;        // more setup        LineBox prev_line = new LineBox();        c.pushStyle(CascadedStyle.emptyCascadedStyle);        prev_line.setStyle(new Style(c.getCurrentStyle(), 0, c));        c.popStyle();        prev_line.setParent(box);        prev_line.y = bounds.y;        prev_line.height = 0;        InlineBox prev_inline = null;        InlineBox prev_align_inline = null;        // adjust the first line for float tabs        // skip adjusting for tabs if this box is cleared        if (!box.getStyle().isCleared()) {            remaining_width = FloatUtil.adjustForTab(c, prev_line, remaining_width);        }        boolean isFirstLetter = true;        LinkedList pendingPushStyles = null;        int pendingLeftPadding = 0;        int pendingRightPadding = 0;        // loop until no more nodes        Iterator contentIter = contentList.iterator();        while (contentIter.hasNext() && !c.shouldStop()) {            Object o = contentIter.next();            if (o instanceof FirstLineStyle) {//can actually only be the first object in list                box.firstLineStyle = ((FirstLineStyle) o).getStyle();                c.addFirstLineStyle(box.firstLineStyle);                continue;            }            if (o instanceof FirstLetterStyle) {//can actually only be the first or second object in list                box.firstLetterStyle = ((FirstLetterStyle) o).getStyle();                continue;            }            if (o instanceof StylePush) {                CascadedStyle cascaded;                StylePush sp = (StylePush) o;                if (sp.getElement() == null) {                    //anonymous inline box                    cascaded = CascadedStyle.emptyCascadedStyle;                } else if (sp.getPseudoElement() != null) {                    cascaded = c.getCss().getPseudoElementStyle(sp.getElement(), sp.getPseudoElement());                } else {                    cascaded = c.getCss().getCascadedStyle(sp.getElement(), false);//already restyled by ContentUtil                }                //first push first-line styles                if (c.hasFirstLineStyles()) {                    if (pushedOnFirstLine == null) {                        pushedOnFirstLine = new LinkedList();                        for (Iterator i = c.getFirstLineStyles().iterator(); i.hasNext();) {                            c.pushStyle((CascadedStyle) i.next());                        }                    }                    pushedOnFirstLine.addLast(cascaded);                }                c.pushStyle(cascaded);                if (pendingPushStyles == null) {                    pendingPushStyles = new LinkedList();                }                pendingPushStyles.addLast((StylePush) o);                Relative.translateRelative(c, c.getCurrentStyle(), false);                CalculatedStyle style = c.getCurrentStyle();                int parent_width = bounds.width;                BorderPropertySet border = style.getBorder(c);                //note: percentages here refer to width of containing block                RectPropertySet margin = style.getMarginRect(parent_width, parent_width, c);                RectPropertySet padding = style.getPaddingRect(parent_width, parent_width, c);                pendingLeftPadding += margin.left() + (int) border.left() + (int) padding.left();                pendingRightPadding += (int) padding.right() + (int) border.right() + margin.right();                continue;            }            if (o instanceof StylePop) {                if (pendingPushStyles != null && pendingPushStyles.size() != 0) {                    pendingPushStyles.removeLast();//was a redundant one                } else {                    if (prev_inline == null) {                        prev_inline = new InlineTextBox();//hope it is decently initialised as empty                        ((InlineTextBox) prev_inline).setMasterText("");                        ((InlineTextBox) prev_inline).start_index = 0;                        ((InlineTextBox) prev_inline).end_index = 0;                        curr_line.addChild(prev_inline);                    }                    prev_inline.popstyles++;                    int parent_width = bounds.width;                    CalculatedStyle style = c.getCurrentStyle();                    BorderPropertySet border = style.getBorder(c);                    //note: percentages here refer to width of containing block                    RectPropertySet margin = style.getMarginRect(parent_width, parent_width, c);                    RectPropertySet padding = style.getPaddingRect(parent_width, parent_width, c);                    // CLEAN: cast to int                    int rp = (int) padding.right() + (int) border.right() + (int) margin.right();                    //CHECK: not sure this is where the padding really goes, always                    prev_inline.rightPadding += rp;                    pendingRightPadding -= rp;                    remaining_width -= rp;                }                if (c.hasFirstLineStyles()) {                    pushedOnFirstLine.removeLast();                }                Relative.untranslateRelative(c, c.getCurrentStyle(), false);                c.popStyle();                continue;            }            Content currentContent = (Content) o;            if (currentContent.getStyle() != null) {                //first push first-line styles                if (c.hasFirstLineStyles()) {                    if (pushedOnFirstLine == null) {                        pushedOnFirstLine = new LinkedList();                        for (Iterator i = c.getFirstLineStyles().iterator(); i.hasNext();) {                            c.pushStyle((CascadedStyle) i.next());                        }                    }                    pushedOnFirstLine.addLast(currentContent.getStyle());                }                c.pushStyle(currentContent.getStyle());            }            // loop until no more text in this node            InlineBox new_inline = null;            int start = 0;            InlineBlockBox pendingBlockBox = null;            do {                new_inline = null;                if (currentContent instanceof AbsolutelyPositionedContent) {                    // Uu.p("this might be a problem, but it could just be an absolute block");                    //     result = new BoxLayout().layout(c,content);                    Box absolute = Absolute.generateAbsoluteBox(c, currentContent);                    curr_line.setChildrenExceedBounds(true);                    curr_line.addChild(absolute);                    break;                }                // debugging check                if (bounds.width < 0) {                    Uu.p("bounds width = " + bounds.width);                    Uu.dump_stack();                    System.exit(-1);                }                // the crash warning code                if (bounds.width < 1) {                    Uu.p("warning. width < 1 " + bounds.width);                }                // look at current inline                // break off the longest section that will fit                int fit = pendingRightPadding;//Note: this is not necessarily entirely correct                if (start == 0) fit += pendingLeftPadding;                start = trimLeadingSpace(c.getCurrentStyle(), prev_inline, currentContent, start);                new_inline = calculateInline(c, currentContent, remaining_width - fit, bounds.width,                        prev_align_inline, isFirstLetter, box.firstLetterStyle,                        curr_line, start, pendingBlockBox);                pendingBlockBox = null;                // if this inline needs to be on a new line                if (prev_align_inline != null && new_inline.break_before) {                    // Uu.p("break before");                    remaining_width = bounds.width;                    saveLine(curr_line, prev_line, bounds, c, box, blockLineHeight, pushedOnFirstLine);                    bounds.height += curr_line.height;                    prev_line = curr_line;                    curr_line = newLine(box, bounds, prev_line, blockLineMetrics, c);                    // skip adjusting for tabs if this box is cleared                    if (!box.getStyle().isCleared()) {                        remaining_width = FloatUtil.adjustForTab(c, curr_line, remaining_width);                    }                                        //have to discard it and recalculate, particularly if this was the first line                    prev_align_inline.break_after = true;                    if (new_inline instanceof InlineBlockBox) pendingBlockBox = (InlineBlockBox) new_inline;                    new_inline = null;                    continue;                }                // save the new inline to the list                // Uu.p("adding inline child: " + new_inline);                //the inline might be set to size 0,0 after this, if it is first whitespace on line.                // Cannot discard because it may contain style-pushes                curr_line.addInlineChild(new_inline);                // Uu.p("current line = " + curr_line);                if (new_inline instanceof InlineTextBox) {                    start = ((InlineTextBox) new_inline).end_index;                }                isFirstLetter = false;                new_inline.pushstyles = pendingPushStyles;                pendingPushStyles = null;                new_inline.leftPadding += pendingLeftPadding;                pendingLeftPadding = 0;                // calc new height of the line                // don't count floats and absolutes                if (!new_inline.getStyle().isFloated() && !new_inline.getStyle().isAbsolute()) {                    adjustLineHeight(c, curr_line, new_inline);                }                if (!(currentContent instanceof FloatedBlockContent)) {                    // calc new width of the line                    curr_line.contentWidth += new_inline.getWidth();                }                // reduce the available width                remaining_width = remaining_width - new_inline.getWidth();                // if the last inline was at the end of a line, then go to next line                if (new_inline.break_after) {                    // Uu.p("break after");                    // then remaining_width = max_width                    remaining_width = bounds.width;                    // save the line                    saveLine(curr_line, prev_line, bounds, c, box, blockLineHeight, pushedOnFirstLine);                    // increase bounds height to account for the new line                    bounds.height += curr_line.height;                    prev_line = curr_line;                    curr_line = newLine(box, bounds, prev_line, blockLineMetrics, c);                    if (!box.getStyle().isCleared()) {                        remaining_width = FloatUtil.adjustForTab(c, curr_line, remaining_width);                    }                }                // set the inline to use for left alignment                if (!isOutsideFlow(currentContent)) {                    prev_align_inline = new_inline;                }                prev_inline = new_inline;            } while (!c.shouldStop() && (new_inline == null || !new_inline.isEndOfParentContent()));            if (currentContent.getStyle() != null) {                c.popStyle();                if (c.hasFirstLineStyles()) {                    pushedOnFirstLine.removeLast();                }            }        }        // save the final line        saveLine(curr_line, prev_line, bounds, c, box, blockLineHeight, pushedOnFirstLine);        bounds.height += curr_line.height;        if (!c.shrinkWrap()) box.contentWidth = bounds.width;        box.height = bounds.height;        //box.x = 0;        //box.y = 0;        // Uu.p("- InlineLayout.layoutContent(): " + box);        //pop the dummy style, but no, see above        //c.popStyle();    }