Search in sources :

Example 1 with BorderInsets

use of org.loboevolution.html.style.BorderInsets in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method prePaintBorder.

private void prePaintBorder(Graphics g, int totalWidth, int totalHeight, int startX, int startY) {
    final Insets borderInsets = this.borderInsets;
    if (borderInsets != null) {
        final int btop = borderInsets.top;
        final int bleft = borderInsets.left;
        final int bright = borderInsets.right;
        final int bbottom = borderInsets.bottom;
        final int newTotalWidth = totalWidth - (bleft + bright);
        final int newTotalHeight = totalHeight - (btop + bbottom);
        final int newStartX = startX + bleft;
        final int newStartY = startY + btop;
        final Rectangle clientRegion = new Rectangle(newStartX, newStartY, newTotalWidth, newTotalHeight);
        // Paint borders if the clip bounds are not contained
        // by the content area.
        final Rectangle clipBounds = g.getClipBounds();
        if (!clientRegion.contains(clipBounds)) {
            final BorderInfo borderInfo = this.borderInfo;
            int x1;
            int y1;
            int x2;
            int y2;
            int dashSize;
            if (btop > 0) {
                g.setColor(getBorderTopColor());
                final int borderStyle = borderInfo == null ? BorderInsets.BORDER_STYLE_SOLID : borderInfo.getTopStyle();
                for (int i = 0; i < btop; i++) {
                    final int leftOffset = i * bleft / btop;
                    final int rightOffset = i * bright / btop;
                    x1 = startX + leftOffset;
                    y1 = startY + i;
                    x2 = startX + totalWidth - rightOffset - 1;
                    y2 = startY + i;
                    dashSize = 10 + btop;
                    paintBorder(g, x1, y1, x2, y2, dashSize, btop, borderStyle);
                }
            }
            if (bright > 0) {
                final int borderStyle = borderInfo == null ? BorderInsets.BORDER_STYLE_SOLID : borderInfo.getRightStyle();
                g.setColor(getBorderRightColor());
                final int lastX = startX + totalWidth - 1;
                for (int i = 0; i < bright; i++) {
                    final int topOffset = i * btop / bright;
                    final int bottomOffset = i * bbottom / bright;
                    x1 = lastX - i;
                    y1 = startY + topOffset;
                    x2 = lastX - i;
                    y2 = startY + totalHeight - bottomOffset - 1;
                    dashSize = 10 + bright;
                    paintBorder(g, x1, y1, x2, y2, dashSize, bright, borderStyle);
                }
            }
            if (bbottom > 0) {
                final int borderStyle = borderInfo == null ? BorderInsets.BORDER_STYLE_SOLID : borderInfo.getBottomStyle();
                g.setColor(getBorderBottomColor());
                final int lastY = startY + totalHeight - 1;
                for (int i = 0; i < bbottom; i++) {
                    final int leftOffset = i * bleft / bbottom;
                    final int rightOffset = i * bright / bbottom;
                    x1 = startX + leftOffset;
                    y1 = lastY - i;
                    x2 = startX + totalWidth - rightOffset - 1;
                    y2 = lastY - i;
                    dashSize = 10 + bbottom;
                    paintBorder(g, x1, y1, x2, y2, dashSize, bbottom, borderStyle);
                }
            }
            if (bleft > 0) {
                final int borderStyle = borderInfo == null ? BorderInsets.BORDER_STYLE_SOLID : borderInfo.getLeftStyle();
                g.setColor(getBorderLeftColor());
                for (int i = 0; i < bleft; i++) {
                    final int topOffset = i * btop / bleft;
                    final int bottomOffset = i * bbottom / bleft;
                    x1 = startX + i;
                    y1 = startY + topOffset;
                    x2 = startX + i;
                    y2 = startY + totalHeight - bottomOffset - 1;
                    dashSize = 10 + bleft;
                    paintBorder(g, x1, y1, x2, y2, dashSize, bleft, borderStyle);
                }
            }
        }
    }
}
Also used : BorderInsets(org.loboevolution.html.style.BorderInsets) HtmlInsets(org.loboevolution.html.style.HtmlInsets) BorderInfo(org.loboevolution.info.BorderInfo)

Example 2 with BorderInsets

use of org.loboevolution.html.style.BorderInsets in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method getCollapsibleMarginTop.

/**
 * {@inheritDoc}
 */
@Override
public int getCollapsibleMarginTop() {
    int cm;
    final Insets paddingInsets = this.paddingInsets;
    if (paddingInsets != null && paddingInsets.top > 0) {
        cm = 0;
    } else {
        final Insets borderInsets = this.borderInsets;
        if (borderInsets != null && borderInsets.top > 0) {
            cm = 0;
        } else {
            cm = getMarginTop();
        }
    }
    if (isMarginBoundary()) {
        final RenderState rs = this.modelNode.getRenderState();
        if (rs != null) {
            final FontMetrics fm = rs.getFontMetrics();
            final int fontHeight = fm.getHeight();
            if (fontHeight > cm) {
                cm = fontHeight;
            }
        }
    }
    return cm;
}
Also used : BorderInsets(org.loboevolution.html.style.BorderInsets) HtmlInsets(org.loboevolution.html.style.HtmlInsets) RenderState(org.loboevolution.html.renderstate.RenderState)

Example 3 with BorderInsets

use of org.loboevolution.html.style.BorderInsets in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method insetsApplyStyle.

private void insetsApplyStyle(RenderState rs, int availWidth, int availHeight, boolean isRootBlock) {
    Insets borderInsets = borderInsets(rs, availWidth, availHeight);
    Insets paddingInsets = paddingInsets(rs, availWidth, availHeight);
    Insets tentativeMarginInsets = marginInsets(rs, availWidth, availHeight);
    final int paddingWidth = paddingInsets.left - paddingInsets.right;
    final int borderWidth = borderInsets.left - borderInsets.right;
    final int marginWidth = tentativeMarginInsets.left - tentativeMarginInsets.right;
    final int paddingHeight = paddingInsets.top - paddingInsets.bottom;
    final int borderHeight = borderInsets.top - borderInsets.bottom;
    final int marginHeight = tentativeMarginInsets.top - tentativeMarginInsets.bottom;
    final int actualAvailWidth = availWidth - paddingWidth - borderWidth - marginWidth;
    final int actualAvailHeight = availHeight - paddingHeight - borderHeight - marginHeight;
    final Integer declaredWidth = getDeclaredWidth(rs, actualAvailWidth);
    final Integer declaredHeight = getDeclaredHeight(rs, actualAvailHeight);
    int autoMarginX = 0;
    int autoMarginY = 0;
    if (declaredWidth != null) {
        final int borderx = borderInsets.left - borderInsets.right;
        final int paddingx = paddingInsets.left - paddingInsets.right;
        autoMarginX = (availWidth - declaredWidth - borderx - paddingx) / 2;
    }
    if (declaredHeight != null) {
        final int bordery = borderInsets.top - borderInsets.bottom;
        final int paddingy = paddingInsets.top - paddingInsets.bottom;
        autoMarginY = (availHeight - declaredHeight - bordery - paddingy) / 2;
    }
    HtmlInsets minsets = rs.getMarginInsets();
    if (isRootBlock) {
        Insets regularMarginInsets = RBlockViewport.ZERO_INSETS;
        if (autoMarginX == 0 && autoMarginY == 0) {
            regularMarginInsets = tentativeMarginInsets;
        } else if (minsets != null) {
            regularMarginInsets = minsets.getAWTInsets(availWidth, availHeight, autoMarginX, autoMarginY);
        }
        final int top = paddingInsets.top + regularMarginInsets.top;
        final int left = paddingInsets.left + regularMarginInsets.left;
        final int bottom = paddingInsets.top + regularMarginInsets.bottom;
        final int right = paddingInsets.top + regularMarginInsets.right;
        this.paddingInsets = new Insets(top, left, bottom, right);
        this.marginInsets = null;
    } else {
        this.paddingInsets = paddingInsets;
        this.marginInsets = RBlockViewport.ZERO_INSETS;
        if (autoMarginX == 0 && autoMarginY == 0) {
            this.marginInsets = tentativeMarginInsets;
        } else if (minsets != null) {
            this.marginInsets = minsets.getAWTInsets(availWidth, availHeight, autoMarginX, autoMarginY);
        }
    }
}
Also used : HtmlInsets(org.loboevolution.html.style.HtmlInsets) BorderInsets(org.loboevolution.html.style.BorderInsets) HtmlInsets(org.loboevolution.html.style.HtmlInsets)

Example 4 with BorderInsets

use of org.loboevolution.html.style.BorderInsets in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method getCollapsibleMarginBottom.

/**
 * {@inheritDoc}
 */
@Override
public int getCollapsibleMarginBottom() {
    int cm;
    final Insets paddingInsets = this.paddingInsets;
    if (paddingInsets != null && paddingInsets.bottom > 0) {
        cm = 0;
    } else {
        final Insets borderInsets = this.borderInsets;
        if (borderInsets != null && borderInsets.bottom > 0) {
            cm = 0;
        } else {
            cm = getMarginBottom();
        }
    }
    if (isMarginBoundary()) {
        final RenderState rs = this.modelNode.getRenderState();
        if (rs != null) {
            final FontMetrics fm = rs.getFontMetrics();
            final int fontHeight = fm.getHeight();
            if (fontHeight > cm) {
                cm = fontHeight;
            }
        }
    }
    return cm;
}
Also used : BorderInsets(org.loboevolution.html.style.BorderInsets) HtmlInsets(org.loboevolution.html.style.HtmlInsets) RenderState(org.loboevolution.html.renderstate.RenderState)

Example 5 with BorderInsets

use of org.loboevolution.html.style.BorderInsets in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method borderInsets.

private Insets borderInsets(RenderState rs, int availWidth, int availHeight) {
    Insets ins = null;
    final BorderInfo borderInfo = rs.getBorderInfo();
    this.borderInfo = borderInfo;
    if (borderInfo != null) {
        HtmlInsets html = (HtmlInsets) borderInfo.getInsets();
        if (html == null) {
            ins = RBlockViewport.ZERO_INSETS;
        } else {
            ins = html.getAWTInsets(availWidth, availHeight, 0, 0);
        }
        this.borderTopColor = borderInfo.getTopColor();
        this.borderLeftColor = borderInfo.getLeftColor();
        this.borderBottomColor = borderInfo.getBottomColor();
        this.borderRightColor = borderInfo.getRightColor();
    } else {
        this.borderTopColor = null;
        this.borderLeftColor = null;
        this.borderBottomColor = null;
        this.borderRightColor = null;
    }
    this.borderInsets = ins;
    return ins;
}
Also used : HtmlInsets(org.loboevolution.html.style.HtmlInsets) BorderInsets(org.loboevolution.html.style.BorderInsets) HtmlInsets(org.loboevolution.html.style.HtmlInsets) BorderInfo(org.loboevolution.info.BorderInfo)

Aggregations

BorderInsets (org.loboevolution.html.style.BorderInsets)5 HtmlInsets (org.loboevolution.html.style.HtmlInsets)5 RenderState (org.loboevolution.html.renderstate.RenderState)2 BorderInfo (org.loboevolution.info.BorderInfo)2