Search in sources :

Example 1 with HtmlInsets

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

the class BaseElementRenderable method getDeclaredWidthImpl.

private int getDeclaredWidthImpl(RenderState renderState, int availWidth) {
    Object rootNode = this.modelNode;
    if (rootNode instanceof HTMLElementImpl) {
        HTMLElementImpl element = (HTMLElementImpl) rootNode;
        HTMLDocumentImpl doc = (HTMLDocumentImpl) element.getDocumentNode();
        CSS3Properties props = element.getCurrentStyle();
        if (props == null) {
            return -1;
        }
        String widthText = props.getWidth();
        final String textContent = element.getTextContent();
        if ("inherit".equalsIgnoreCase(widthText)) {
            widthText = element.getParentStyle().getWidth();
        } else if ("initial".equalsIgnoreCase(widthText)) {
            widthText = "100%";
        }
        int width = -1;
        if (widthText != null) {
            width = HtmlValues.getPixelSize(widthText, renderState, doc.getDefaultView(), -1, availWidth);
        }
        if (width == -1 && Strings.isNotBlank(textContent) && renderState.getDisplay() == RenderState.DISPLAY_INLINE_BLOCK) {
            HtmlInsets paddingInsets = renderState.getPaddingInsets();
            HtmlInsets marginInsets = renderState.getMarginInsets();
            int right = 0;
            int left = 0;
            if (paddingInsets != null) {
                right = right + paddingInsets.right;
                left = left + paddingInsets.left;
            }
            if (marginInsets != null) {
                right = right + marginInsets.right;
                left = left + marginInsets.left;
            }
            final int multi = (right == 0 && left == 0) ? 12 : 4;
            width = (textContent.length() + right + left) * multi;
        }
        if (props.getMaxWidth() != null) {
            int maxWidth = HtmlValues.getPixelSize(props.getMaxWidth(), renderState, doc.getDefaultView(), -1, availWidth);
            if (width == -1 || width > maxWidth) {
                width = maxWidth;
            }
        }
        if (props.getMinWidth() != null) {
            int minWidth = HtmlValues.getPixelSize(props.getMinWidth(), element.getRenderState(), doc.getDefaultView(), 0, availWidth);
            if (width == 0 || width < minWidth) {
                width = minWidth;
            }
        }
        return width;
    } else {
        return -1;
    }
}
Also used : HTMLElementImpl(org.loboevolution.html.dom.domimpl.HTMLElementImpl) HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) HtmlInsets(org.loboevolution.html.style.HtmlInsets) CSS3Properties(org.loboevolution.html.node.css.CSS3Properties)

Example 2 with HtmlInsets

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

the class BaseElementRenderable method marginInsets.

private Insets marginInsets(RenderState rs, int availWidth, int availHeight) {
    Insets ins;
    HtmlInsets html = rs.getMarginInsets();
    if (html == null) {
        ins = RBlockViewport.ZERO_INSETS;
    } else {
        ins = html.getAWTInsets(availWidth, availHeight, 0, 0);
    }
    return ins;
}
Also used : HtmlInsets(org.loboevolution.html.style.HtmlInsets) BorderInsets(org.loboevolution.html.style.BorderInsets) HtmlInsets(org.loboevolution.html.style.HtmlInsets)

Example 3 with HtmlInsets

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

the class TableRenderState method getBorderInfo.

/**
 * {@inheritDoc}
 */
@Override
public BorderInfo getBorderInfo() {
    BorderInfo binfo = this.borderInfo;
    if (binfo != INVALID_BORDER_INFO) {
        return binfo;
    }
    binfo = super.getBorderInfo();
    if (binfo == null || binfo.getTopStyle() == BorderInsets.BORDER_STYLE_NONE && binfo.getBottomStyle() == BorderInsets.BORDER_STYLE_NONE && binfo.getLeftStyle() == BorderInsets.BORDER_STYLE_NONE && binfo.getRightStyle() == BorderInsets.BORDER_STYLE_NONE) {
        if (binfo == null) {
            binfo = new BorderInfo();
        }
        final HTMLElementImpl element = this.element;
        if (element != null) {
            String border = element.getAttribute("border");
            if (border != null) {
                border = border.trim();
                int value;
                int valueType;
                if (border.endsWith("%")) {
                    valueType = HtmlInsets.TYPE_PERCENT;
                    try {
                        value = Integer.parseInt(border.substring(0, border.length() - 1));
                    } catch (final NumberFormatException nfe) {
                        value = 0;
                    }
                } else {
                    valueType = HtmlInsets.TYPE_PIXELS;
                    try {
                        value = Integer.parseInt(border);
                    } catch (final NumberFormatException nfe) {
                        value = 0;
                    }
                }
                final HtmlInsets borderInsets = new HtmlInsets();
                borderInsets.top = borderInsets.left = borderInsets.right = borderInsets.bottom = value;
                borderInsets.topType = borderInsets.leftType = borderInsets.rightType = borderInsets.bottomType = valueType;
                binfo.setInsets(borderInsets);
                if (binfo.getTopColor() == null) {
                    binfo.setTopColor(Color.DARK_GRAY);
                }
                if (binfo.getLeftColor() == null) {
                    binfo.setLeftColor(Color.DARK_GRAY);
                }
                if (binfo.getRightColor() == null) {
                    binfo.setRightColor(Color.LIGHT_GRAY);
                }
                if (binfo.getBottomColor() == null) {
                    binfo.setBottomColor(Color.LIGHT_GRAY);
                }
                if (value != 0) {
                    binfo.setTopStyle(BorderInsets.BORDER_STYLE_SOLID);
                    binfo.setLeftStyle(BorderInsets.BORDER_STYLE_SOLID);
                    binfo.setRightStyle(BorderInsets.BORDER_STYLE_SOLID);
                    binfo.setBottomStyle(BorderInsets.BORDER_STYLE_SOLID);
                }
            }
        }
    }
    this.borderInfo = binfo;
    return binfo;
}
Also used : HTMLElementImpl(org.loboevolution.html.dom.domimpl.HTMLElementImpl) HtmlInsets(org.loboevolution.html.style.HtmlInsets) BorderInfo(org.loboevolution.info.BorderInfo)

Example 4 with HtmlInsets

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

the class ParagraphRenderState method getDefaultMarginInsets.

/**
 * {@inheritDoc}
 */
@Override
protected HtmlInsets getDefaultMarginInsets() {
    final HtmlInsets insets = new HtmlInsets();
    final int topBottom = HtmlValues.getPixelSize("1rem", null, element.getDocumentNode().getDefaultView(), -1);
    insets.top = topBottom;
    insets.bottom = topBottom;
    insets.topType = HtmlInsets.TYPE_PIXELS;
    insets.bottomType = HtmlInsets.TYPE_PIXELS;
    return insets;
}
Also used : HtmlInsets(org.loboevolution.html.style.HtmlInsets)

Example 5 with HtmlInsets

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

the class TableCellRenderState method getPaddingInsets.

/**
 * {@inheritDoc}
 */
@Override
public HtmlInsets getPaddingInsets() {
    HtmlInsets insets = this.paddingInsets;
    if (insets != INVALID_INSETS) {
        return insets;
    } else {
        final HTMLTableElement tableElement = getTableElement();
        if (tableElement == null) {
            // Return without caching
            return null;
        }
        String cellPaddingText = tableElement.getAttribute("cellpadding");
        if (Strings.isNotBlank(cellPaddingText)) {
            cellPaddingText = cellPaddingText.trim();
            HTMLDocumentImpl doc = (HTMLDocumentImpl) tableElement.getOwnerDocument();
            int cellPadding = HtmlValues.getPixelSize(cellPaddingText, this, doc.getDefaultView(), 0);
            int cellPaddingType = HtmlInsets.TYPE_PIXELS;
            if (cellPaddingText.endsWith("%")) {
                cellPaddingType = HtmlInsets.TYPE_PERCENT;
            }
            insets = new HtmlInsets();
            insets.top = insets.left = insets.right = insets.bottom = cellPadding;
            insets.topType = insets.leftType = insets.rightType = insets.bottomType = cellPaddingType;
        } else {
            insets = super.getPaddingInsets();
        }
    }
    this.paddingInsets = insets;
    return insets;
}
Also used : HtmlInsets(org.loboevolution.html.style.HtmlInsets) HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) HTMLTableElement(org.loboevolution.html.dom.HTMLTableElement)

Aggregations

HtmlInsets (org.loboevolution.html.style.HtmlInsets)31 HTMLElementImpl (org.loboevolution.html.dom.domimpl.HTMLElementImpl)4 BorderInsets (org.loboevolution.html.style.BorderInsets)4 BorderInfo (org.loboevolution.info.BorderInfo)4 HTMLDocumentImpl (org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)2 FontMetrics (java.awt.FontMetrics)1 HTMLTableElement (org.loboevolution.html.dom.HTMLTableElement)1 CSS3Properties (org.loboevolution.html.node.css.CSS3Properties)1 RenderState (org.loboevolution.html.renderstate.RenderState)1 AbstractCSSProperties (org.loboevolution.html.style.AbstractCSSProperties)1