prev_inline.rightPadding = prev_inline.totalRightPadding(c.getCurrentStyle()); prev_inline.width += prev_inline.rightPadding; pendingRightPadding -= prev_inline.rightPadding;
int rp = prev_inline.totalRightPadding(c.getCurrentStyle()); prev_inline.rightPadding += rp; prev_inline.width += rp; pendingRightPadding -= rp; remaining_width -= rp;
    public static void layoutContent(Context 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;        Border border = c.getCurrentStyle().getBorderWidth(c.getBlockFormattingContext().getWidth(), c.getBlockFormattingContext().getHeight());        Border margin = c.getCurrentStyle().getMarginWidth(c.getBlockFormattingContext().getWidth(), c.getBlockFormattingContext().getHeight());        Border padding = c.getCurrentStyle().getPaddingWidth(c.getBlockFormattingContext().getWidth(), c.getBlockFormattingContext().getHeight());        //below should maybe be done somewhere else?        bounds.width -= margin.left + border.left + padding.left +                padding.right + border.right + margin.right;        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        c.pushStyle(new CascadedStyle());        int blockLineHeight = FontUtil.lineHeight(c);        LineMetrics blockLineMetrics = c.getTextRenderer().getLineMetrics(c.getGraphics(),                FontUtil.getFont(c), "thequickbrownfoxjumpedoverthelazydogTHEQUICKBROWNFOXJUMPEDOVERTHELAZYDOG");        // prepare remaining width and first linebox        int remaining_width = bounds.width;        LineBox curr_line = newLine(box, bounds, null);        c.setFirstLine(true);        LinkedList pushedOnFirstLine = null;        // account for text-indent        CalculatedStyle parentStyle = c.getCurrentStyle();        remaining_width = TextIndent.doTextIndent(parentStyle, remaining_width, curr_line);        // more setup        LineBox prev_line = new LineBox();        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        remaining_width = FloatUtil.adjustForTab(c, prev_line, remaining_width);        CalculatedStyle currentStyle = parentStyle;        boolean isFirstLetter = true;        List pendingPushStyles = null;        int pendingLeftPadding = 0;        int pendingRightPadding = 0;        InlineBox helper = new InlineTextBox();        // loop until no more nodes        while (contentList.size() > 0) {            Object o = contentList.get(0);            contentList.remove(0);            if (o instanceof FirstLineStyle) {//can actually only be the first object in list                box.firstLineStyle = ((FirstLineStyle) o).getStyle();                pushedOnFirstLine = new LinkedList();                c.pushStyle(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 style;                StylePush sp = (StylePush) o;                if (sp.getPseudoElement() != null) {                    style = c.getCss().getPseudoElementStyle(sp.getElement(), sp.getPseudoElement());                } else {                    style = c.getCss().getCascadedStyle(sp.getElement(), false);//already restyled by ContentUtil                }                c.pushStyle(style);                if (pendingPushStyles == null) {                    pendingPushStyles = new LinkedList();                }                pendingPushStyles.add((StylePush) o);                Relative.translateRelative(c);                if (pushedOnFirstLine != null) {                    pushedOnFirstLine.addLast(style);                }                pendingLeftPadding += helper.totalLeftPadding(c.getCurrentStyle());                pendingRightPadding += helper.totalRightPadding();                continue;            }            if (o instanceof StylePop) {                if (pendingPushStyles != null && pendingPushStyles.size() != 0) {                    pendingPushStyles.remove(pendingPushStyles.size() - 1);//was a redundant one                } else {                    //can't happen unless it's a bad error somewhere: if (prev_inline != null) {                    //CHECK: not sure this is where the padding really goes, always                    prev_inline.rightPadding = prev_inline.totalRightPadding(c.getCurrentStyle());                    prev_inline.width += prev_inline.rightPadding;                    pendingRightPadding -= prev_inline.rightPadding;                    if (prev_inline.popstyles == null) {                        prev_inline.popstyles = new LinkedList();                    }                    prev_inline.popstyles.add(o);                    //}                }                if (pushedOnFirstLine != null) {                    pushedOnFirstLine.removeLast();                }                Relative.untranslateRelative(c);                c.popStyle();                continue;            }            Content currentContent = (Content) o;            if (currentContent.getStyle() != null) {                c.pushStyle(currentContent.getStyle());            }            // loop until no more text in this node            InlineBox new_inline = null;            int start = 0;            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.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);                }                currentStyle = c.getCurrentStyle();                // 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;                new_inline = calculateInline(c, currentContent, remaining_width - fit, bounds.width,                        prev_align_inline, isFirstLetter, box.firstLetterStyle,                        curr_line, start);                // Uu.p("got back inline: " + new_inline);                // 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;                    if (pushedOnFirstLine != null) {                        for (int i = 0; i < pushedOnFirstLine.size(); i++) c.popStyle();                        c.popStyle();//the firstLineStyle                        //reinstate                        for (Iterator i = pushedOnFirstLine.iterator(); i.hasNext();) {                            c.pushStyle((CascadedStyle) i.next());                        }                        pushedOnFirstLine = null;                    }                    saveLine(curr_line, currentStyle, prev_line, bounds.width, bounds.x, c, box, false, blockLineHeight);                    bounds.height += curr_line.height;                    prev_line = curr_line;                    curr_line = newLine(box, bounds, prev_line);                    remaining_width = FloatUtil.adjustForTab(c, curr_line, remaining_width);                                        //have to discard it and recalculate, particularly if this was the first line                    //HACK: is my thinking straight? - tobe                    prev_align_inline.break_after = true;                    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(c, 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.width += pendingLeftPadding;                pendingLeftPadding = 0;                // calc new height of the line                // don't count floats and absolutes                if (!new_inline.floated && !new_inline.absolute) {                    adjustLineHeight(c, curr_line, new_inline, blockLineHeight, blockLineMetrics);                }                if (!(currentContent instanceof FloatedBlockContent)) {                    // calc new width of the line                    curr_line.width += new_inline.width;                }                // reduce the available width                remaining_width = remaining_width - new_inline.width;                // 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                    if (pushedOnFirstLine != null) {                        for (int i = 0; i < pushedOnFirstLine.size(); i++) c.popStyle();                        c.popStyle();//the firstLineStyle                        //reinstate                        for (Iterator i = pushedOnFirstLine.iterator(); i.hasNext();) {                            c.pushStyle((CascadedStyle) i.next());                        }                        pushedOnFirstLine = null;                    }                    saveLine(curr_line, currentStyle, prev_line, bounds.width, bounds.x, c, box, false, blockLineHeight);                    // 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);                    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 (new_inline == null || !new_inline.isEndOfParentContent());            if (currentContent.getStyle() != null) {                c.popStyle();            }        }        // save the final line        if (pushedOnFirstLine != null) {            for (int i = 0; i < pushedOnFirstLine.size(); i++) c.popStyle();            c.popStyle();//the firstLineStyle            //reinstate            for (Iterator i = pushedOnFirstLine.iterator(); i.hasNext();) {                c.pushStyle((CascadedStyle) i.next());            }            pushedOnFirstLine = null;        }        saveLine(curr_line, currentStyle, prev_line, bounds.width, bounds.x, c, box, true, blockLineHeight);        finishBlock(box, curr_line, bounds);        // Uu.p("- InlineLayout.layoutContent(): " + box);        //pop the dummy style        c.popStyle();    }