tableBox.rightPadding = border.right + (int)margin.right();
tableBox.rightPadding = (int)border.right() + (int)margin.right();
    public static Box layout(Context c, BlockBox outerBox, Content content) {        boolean set_bfc = false;        if (content instanceof TableContent) {            // install a block formatting context for the body,            // ie. if it's null.            // set up the outtermost bfc            if (c.getBlockFormattingContext() == null) {                outerBox.setParent(c.getCtx().getRootBox());                BlockFormattingContext bfc = new BlockFormattingContext(outerBox, c);                c.pushBFC(bfc);                set_bfc = true;                bfc.setWidth((int) c.getExtents().getWidth());            }        } else {            XRLog.layout(Level.WARNING, "Unsupported table type " + content.getClass().getName());            return null;        }        // copy the extents        Rectangle oe = c.getExtents();        c.setExtents(new Rectangle(oe));        //outerBox.x = c.getExtents().x;        //outerBox.y = c.getExtents().y;        //HACK: for now        outerBox.contentWidth = c.getExtents().width;        outerBox.height = c.getExtents().height;        c.pushStyle(CascadedStyle.emptyCascadedStyle);        outerBox.setStyle(new Style(c.getCurrentStyle(), 0, c.getCtx()));        c.popStyle();        TableBox tableBox = new TableBox();        outerBox.addChild(tableBox);        tableBox.element = content.getElement();        //OK, first set up the current style. All depends on this...        CascadedStyle pushed = content.getStyle();        if (pushed != null) {            c.pushStyle(pushed);        } else {            c.pushStyle(CascadedStyle.emptyCascadedStyle);        }        tableBox.setStyle(new Style(c.getCurrentStyle(), (float) oe.getWidth(), c.getCtx()));        VerticalMarginCollapser.collapseVerticalMargins(c, tableBox, content, (float) oe.getWidth());        TableContent tableContent = (TableContent) content;        if (tableContent.isTopMarginCollapsed()) {            tableBox.getStyle().setMarginTopOverride(0f);        }        if (tableContent.isBottomMarginCollapsed()) {            tableBox.getStyle().setMarginBottomOverride(0f);        }        tableBox.setStyle(new Style(c.getCurrentStyle(), (float) oe.getWidth(), c.getCtx()));        Border border = c.getCurrentStyle().getBorderWidth(c.getCtx());        //note: percentages here refer to width of containing block        RectPropertySet margin = tableBox.getStyle().getMarginWidth();        RectPropertySet padding = c.getCurrentStyle().getPaddingRect((float) oe.getWidth(), (float) oe.getWidth(), c.getCtx());        // CLEAN: cast to int        int tx = (int)margin.left() + border.left + (int)padding.left();        int ty = (int)margin.top() + border.top + (int)padding.top();        tableBox.tx = tx;        tableBox.ty = ty;        c.translate(tx, ty);        c.shrinkExtents(tx + (int)margin.right() + border.right + (int)padding.right(), ty + (int)margin.bottom() + border.bottom + (int)padding.bottom());        IdentValue borderStyle = c.getCurrentStyle().getIdent(CSSName.BORDER_COLLAPSE);        int borderSpacingHorizontal = (int) c.getCurrentStyle().getFloatPropertyProportionalWidth(CSSName.FS_BORDER_SPACING_HORIZONTAL, 0, c.getCtx());        int borderSpacingVertical = (int) c.getCurrentStyle().getFloatPropertyProportionalWidth(CSSName.FS_BORDER_SPACING_VERTICAL, 0, c.getCtx());        layoutChildren(c, tableBox, content, false, borderSpacingHorizontal, borderSpacingVertical);        c.unshrinkExtents();        c.translate(-tx, -ty);        //OK, now we basically have the maximum cell widths, is that a smart order?        //TODO: percentages?        if (c.getCurrentStyle().isIdent(CSSName.WIDTH, IdentValue.AUTO)) {            //we're normally fine, unless the maximum width is greater than the extents            fixWidths(tableBox, borderSpacingHorizontal);        } else {//if the algorithm is fixed, we need to do something else from the start            int givenWidth = (int) c.getCurrentStyle().getFloatPropertyProportionalWidth(CSSName.WIDTH, c.getExtents().width, c.getCtx());            //also fine, if the total calculated is less than the extents and the width            if (tableBox.contentWidth < givenWidth) {                tableBox.contentWidth = givenWidth;                fixWidths(tableBox, borderSpacingHorizontal);            } else {                c.getExtents().width = 1;                c.translate(tx, ty);                int[] preferredColumns = tableBox.columns;                tableBox.columns = null;                tableBox.removeAllChildren();                tableBox.contentWidth = 0;                tableBox.height = 0;                layoutChildren(c, tableBox, content, false, borderSpacingHorizontal, borderSpacingVertical);                c.translate(-tx, -ty);                //here the table is layed out with minimum column widths                if (tableBox.contentWidth < givenWidth) {                    //do it right                    tableBox.contentWidth = givenWidth;                    tableBox.removeAllChildren();                    fixWidths(tableBox, borderSpacingHorizontal, preferredColumns);                    c.translate(tx, ty);                    tableBox.contentWidth = 0;                    tableBox.height = 0;                    layoutChildren(c, tableBox, content, true, borderSpacingHorizontal, borderSpacingVertical);                    c.translate(-tx, -ty);                }            }        }        //now the width is settled, fix vertical alignment        for (Iterator i = tableBox.getChildIterator(); i.hasNext();) {            Object o = i.next();            if (o instanceof RowBox) {                fixVerticalAlign(c, (RowBox) o);            }        }        //TODO: margins go on the outer box        tableBox.leftPadding = border.left + (int)padding.left();        // CLEAN: cast to int        tableBox.leftPadding += (int)margin.left();        tableBox.rightPadding = border.right + (int)margin.right();        tableBox.rightPadding += (int)margin.right();        tableBox.height = (int)margin.top() + border.top + (int)padding.top() + tableBox.height + (int)padding.bottom() + border.bottom + (int)margin.bottom();        c.popStyle();        //restore the extents        c.setExtents(oe);        // remove the outtermost bfc        if (set_bfc) {            c.getBlockFormattingContext().doFinalAdjustments();            c.popBFC();        }        outerBox.height = 0;        for (Iterator i = outerBox.getChildIterator(); i.hasNext();) {            Box child = (Box) i.next();            outerBox.height += child.height;            outerBox.adjustWidthForChild(child.getWidth());        }        tableBox.setState(Box.DONE);        outerBox.propagateChildProperties(tableBox);        outerBox.setState(Box.DONE);        return outerBox;    }