Search in sources :

Example 1 with CSS3Properties

use of org.loboevolution.html.node.css.CSS3Properties 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 CSS3Properties

use of org.loboevolution.html.node.css.CSS3Properties in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method hasDeclaredWidth.

/**
 * <p>hasDeclaredWidth.</p>
 *
 * @return a boolean.
 */
public final boolean hasDeclaredWidth() {
    final Integer dw = this.declaredWidth;
    if (INVALID_SIZE.equals(dw)) {
        final Object rootNode = this.modelNode;
        if (rootNode instanceof HTMLElementImpl) {
            final HTMLElementImpl element = (HTMLElementImpl) rootNode;
            final CSS3Properties props = element.getCurrentStyle();
            if (props == null) {
                return false;
            }
            return !Strings.isBlank(props.getWidth());
        }
        return false;
    }
    return true;
}
Also used : HTMLElementImpl(org.loboevolution.html.dom.domimpl.HTMLElementImpl) CSS3Properties(org.loboevolution.html.node.css.CSS3Properties)

Example 3 with CSS3Properties

use of org.loboevolution.html.node.css.CSS3Properties in project LoboEvolution by LoboEvolution.

the class StyleSheetRenderState method getAlignXPercent.

/**
 * {@inheritDoc}
 */
@Override
public int getAlignXPercent() {
    int axp = this.alignXPercent;
    if (axp != -1) {
        return axp;
    }
    final CSS3Properties props = getCssProperties();
    String textAlign = props == null ? null : props.getTextAlign();
    if (textAlign == null || textAlign.length() == 0) {
        // Fall back to align attribute.
        final HTMLElement element = this.element;
        if (element != null) {
            textAlign = element.getAttribute("align");
            if (textAlign == null || textAlign.length() == 0) {
                final RenderState prs = this.prevRenderState;
                if (prs != null) {
                    return prs.getAlignXPercent();
                }
                textAlign = null;
            }
        }
    }
    CSSValues aling = CSSValues.get(textAlign);
    switch(aling) {
        case CENTER:
            axp = 50;
            break;
        case RIGHT:
            axp = 100;
            break;
        case INHERIT:
            axp = this.getPreviousRenderState().getAlignXPercent();
            break;
        case INITIAL:
        default:
            axp = 0;
            break;
    }
    this.alignXPercent = axp;
    return axp;
}
Also used : HTMLElement(org.loboevolution.html.dom.HTMLElement) CSS3Properties(org.loboevolution.html.node.css.CSS3Properties) CSSValues(org.loboevolution.html.CSSValues)

Example 4 with CSS3Properties

use of org.loboevolution.html.node.css.CSS3Properties in project LoboEvolution by LoboEvolution.

the class TableCellRenderState method getAlignYPercent.

/**
 * {@inheritDoc}
 */
@Override
public int getAlignYPercent() {
    int ayp = this.alignYPercent;
    if (ayp != -1) {
        return ayp;
    }
    final CSS3Properties props = getCssProperties();
    if (props != null) {
        final String textAlign = props.getVerticalAlign();
        if (textAlign != null && textAlign.length() != 0) {
            return super.getAlignYPercent();
        }
    }
    String valign = this.element.getAttribute("valign");
    final HTMLElement element = this.element;
    HTMLElement rowElement = null;
    final Object parent = element.getParentNode();
    if (parent instanceof HTMLElement) {
        rowElement = (HTMLElement) parent;
    }
    if (valign == null || valign.length() == 0) {
        if (rowElement != null) {
            valign = rowElement.getAttribute("valign");
            if (valign != null && valign.length() == 0) {
                valign = null;
            }
        } else {
            valign = null;
        }
    }
    if (valign == null) {
        ayp = 50;
    } else if ("top".equalsIgnoreCase(valign)) {
        ayp = 0;
    } else if ("middle".equalsIgnoreCase(valign) || "center".equalsIgnoreCase(valign)) {
        ayp = 50;
    } else if ("bottom".equalsIgnoreCase(valign)) {
        ayp = 100;
    } else {
        // TODO: baseline, etc.
        ayp = 50;
    }
    this.alignYPercent = ayp;
    return ayp;
}
Also used : HTMLElement(org.loboevolution.html.dom.HTMLElement) CSS3Properties(org.loboevolution.html.node.css.CSS3Properties)

Example 5 with CSS3Properties

use of org.loboevolution.html.node.css.CSS3Properties in project LoboEvolution by LoboEvolution.

the class TableCellRenderState method getFont.

@Override
public Font getFont() {
    if ("TH".equals(element.getNodeName())) {
        final CSS3Properties props = element.getCurrentStyle();
        final String fontSize = props == null ? null : props.getFontSize();
        final String fSize = Strings.isNotBlank(fontSize) ? fontSize : "1.2rem";
        FontKey key = FontValues.getDefaultFontKey();
        key.setFontWeight(CSSValues.BOLD.getValue());
        key.setFontSize(FontValues.getFontSize(fSize, element.getDocumentNode().getDefaultView(), prevRenderState));
        return FontFactory.getInstance().getFont(FontValues.getFontKey(key, element, props, prevRenderState));
    }
    return super.getFont();
}
Also used : FontKey(org.loboevolution.laf.FontKey) CSS3Properties(org.loboevolution.html.node.css.CSS3Properties)

Aggregations

CSS3Properties (org.loboevolution.html.node.css.CSS3Properties)9 HTMLElement (org.loboevolution.html.dom.HTMLElement)3 HTMLElementImpl (org.loboevolution.html.dom.domimpl.HTMLElementImpl)3 CSSValues (org.loboevolution.html.CSSValues)2 HTMLDocumentImpl (org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)2 FontKey (org.loboevolution.laf.FontKey)2 RFlex (org.loboevolution.html.renderer.RFlex)1 HtmlInsets (org.loboevolution.html.style.HtmlInsets)1