Search in sources :

Example 1 with CSSValues

use of org.loboevolution.html.CSSValues in project LoboEvolution by LoboEvolution.

the class RFlex method flexAlign.

/**
 * <p>flexAlign.</p>
 *
 * @param markupElement a {@link org.loboevolution.html.dom.domimpl.HTMLElementImpl} object.
 */
protected void flexAlign(HTMLElementImpl markupElement) {
    final String justText = renderState.getJustifyContent();
    CSSValues flex = CSSValues.get(justText);
    if (CSSValues.FLEX_END.equals(flex)) {
        markupElement.getCurrentStyle().setTextAlign("right");
    }
    if (CSSValues.CENTER.equals(flex)) {
        markupElement.getCurrentStyle().setTextAlign("center");
    }
    if (CSSValues.SPACE_BETWEEN.equals(flex)) {
        markupElement.getCurrentStyle().setTextAlign("justify");
    }
}
Also used : CSSValues(org.loboevolution.html.CSSValues)

Example 2 with CSSValues

use of org.loboevolution.html.CSSValues in project LoboEvolution by LoboEvolution.

the class RFlexChild method isInlineBlock.

/**
 * <p>isInlineBlock.</p>
 *
 * @return a boolean.
 */
protected boolean isInlineBlock() {
    final RenderState previous = renderState.getPreviousRenderState();
    final String flexDirText = previous.getFlexDirection();
    final String flexWrapText = previous.getFlexWrap();
    final String justText = previous.getJustifyContent();
    final String alignItems = previous.getAlignItems();
    final String alignContent = previous.getAlignContent();
    boolean isInlineBlock = false;
    // flex-direction
    CSSValues flex = CSSValues.get(flexDirText);
    if (CSSValues.ROW.equals(flex) || CSSValues.ROW_REVERSE.equals(flex)) {
        isInlineBlock = true;
    }
    // flex-wrap
    flex = CSSValues.get(flexWrapText);
    if (CSSValues.WRAP.equals(flex) || CSSValues.WRAP_REVERSE.equals(flex)) {
        isInlineBlock = true;
    }
    // justify-content
    flex = CSSValues.get(justText);
    if (Strings.isNotBlank(justText)) {
        isInlineBlock = true;
    }
    // align-items
    flex = CSSValues.get(alignItems);
    if (CSSValues.FLEX_START.equals(flex) || CSSValues.STRETCH.equals(flex)) {
        isInlineBlock = true;
    }
    // align-content
    flex = CSSValues.get(alignContent);
    if (Strings.isNotBlank(alignContent)) {
        isInlineBlock = true;
    }
    return isInlineBlock;
}
Also used : RenderState(org.loboevolution.html.renderstate.RenderState) CSSValues(org.loboevolution.html.CSSValues)

Example 3 with CSSValues

use of org.loboevolution.html.CSSValues in project LoboEvolution by LoboEvolution.

the class RFlexChild method flexAlign.

/**
 * <p>flexAlign.</p>
 *
 * @param markupElement a {@link org.loboevolution.html.dom.domimpl.HTMLElementImpl} object.
 */
protected void flexAlign(HTMLElementImpl markupElement) {
    final RenderState previous = renderState.getPreviousRenderState();
    final String justText = previous.getJustifyContent();
    CSSValues flex = CSSValues.get(justText);
    if (CSSValues.SPACE_AROUND.equals(flex)) {
        markupElement.getCurrentStyle().setTextAlign("center");
    }
    if (CSSValues.STRETCH.equals(flex)) {
        markupElement.getCurrentStyle().setHeight("100%");
    }
}
Also used : RenderState(org.loboevolution.html.renderstate.RenderState) CSSValues(org.loboevolution.html.CSSValues)

Example 4 with CSSValues

use of org.loboevolution.html.CSSValues in project LoboEvolution by LoboEvolution.

the class ComputedCSSStyleDeclaration method getDisplay.

public String getDisplay() {
    final String cssDisplay = style.getDisplay();
    if (Strings.isNotBlank(cssDisplay) && !"null".equals(cssDisplay)) {
        return cssDisplay;
    } else {
        final RenderState rs = element.getRenderState();
        CSSValues display;
        if (rs == null) {
            return null;
        } else {
            switch(rs.getDefaultDisplay()) {
                case RenderState.DISPLAY_BLOCK:
                    display = CSSValues.BLOCK;
                    break;
                case RenderState.DISPLAY_NONE:
                    display = CSSValues.NONE;
                    break;
                case RenderState.DISPLAY_LIST_ITEM:
                    display = CSSValues.LIST_ITEM;
                    break;
                case RenderState.DISPLAY_TABLE:
                    display = CSSValues.TABLE;
                    break;
                case RenderState.DISPLAY_TABLE_CELL:
                    display = CSSValues.TABLE_CELL;
                    break;
                case RenderState.DISPLAY_TABLE_ROW:
                    display = CSSValues.TABLE_ROW;
                    break;
                case RenderState.DISPLAY_TABLE_CAPTION:
                    display = CSSValues.TABLE_CAPTION;
                    break;
                case RenderState.DISPLAY_TABLE_COLUMN:
                    display = CSSValues.TABLE_COLUMN;
                    break;
                case RenderState.DISPLAY_TABLE_COLUMN_GROUP:
                    display = CSSValues.TABLE_COLUMN_GROUP;
                    break;
                case RenderState.DISPLAY_INLINE_BLOCK:
                    display = CSSValues.INLINE_BLOCK;
                    break;
                case RenderState.DISPLAY_INLINE_TABLE:
                    display = CSSValues.INLINE_TABLE;
                    break;
                case RenderState.DISPLAY_FLEX_BOX:
                    display = CSSValues.FLEX;
                    break;
                default:
                    display = CSSValues.INLINE;
                    break;
            }
        }
        return display.getValue();
    }
}
Also used : RenderState(org.loboevolution.html.renderstate.RenderState) CSSValues(org.loboevolution.html.CSSValues)

Example 5 with CSSValues

use of org.loboevolution.html.CSSValues in project LoboEvolution by LoboEvolution.

the class FontValues method getFontSize.

/**
 * Gets the font size.
 *
 * @param spec              the spec
 * @param parentRenderState the parent render state
 * @return the font size
 */
public static float getFontSize(String spec, Window window, RenderState parentRenderState) {
    final float defaultSize = laf.getFontSize();
    if (Strings.isBlank(spec)) {
        float parentFontSize = parentRenderState == null ? defaultSize : parentRenderState.getFont().getSize();
        if (parentFontSize > 0 && parentFontSize != defaultSize) {
            return parentFontSize;
        } else {
            return defaultSize;
        }
    }
    String units;
    String text;
    final String specTL = spec.toLowerCase();
    if (specTL.endsWith("q") || (specTL.endsWith("%"))) {
        units = specTL.substring(specTL.length() - 1);
        text = specTL.substring(0, specTL.length() - 1);
    } else if (specTL.endsWith("rem")) {
        units = specTL.substring(specTL.length() - 3);
        text = specTL.substring(0, specTL.length() - 3);
    } else {
        units = specTL.substring(specTL.length() - 2);
        text = specTL.substring(0, specTL.length() - 2);
    }
    switch(units) {
        case "rem":
            try {
                return (int) Math.round(defaultSize * Double.parseDouble(text));
            } catch (final NumberFormatException nfe) {
                nfe.printStackTrace();
                return defaultSize;
            }
        case "em":
            try {
                float parentFontSize = parentRenderState == null ? defaultSize : parentRenderState.getFont().getSize();
                return (int) Math.round(parentFontSize * Double.parseDouble(text));
            } catch (final NumberFormatException nfe) {
                return defaultSize;
            }
        case "px":
        case "pt":
        case "pc":
        case "mm":
        case "ex":
            final int pixelSize = getPixelSize(spec, parentRenderState, window, (int) defaultSize);
            final int dpi = GraphicsEnvironment.isHeadless() ? 72 : Toolkit.getDefaultToolkit().getScreenResolution();
            return pixelSize * 96 / dpi;
        case "%":
            final String value = specTL.substring(0, specTL.length() - 1);
            try {
                float parentFontSize = parentRenderState == null ? defaultSize : parentRenderState.getFont().getSize();
                final double valued = Double.parseDouble(value);
                return (float) (parentFontSize * valued / 100.0);
            } catch (final NumberFormatException nfe) {
                return defaultSize;
            }
        default:
            CSSValues fontZize = CSSValues.get(specTL);
            switch(fontZize) {
                case SMALL:
                    return 12.0f;
                case MEDIUM:
                    return 14.0f;
                case LARGE:
                    return 20.0f;
                case X_SMALL:
                    return 11.0f;
                case XX_SMALL:
                    return 10.0f;
                case X_LARGE:
                    return 26.0f;
                case XX_LARGE:
                    return 40.0f;
                case LARGER:
                    float lager = parentRenderState == null ? defaultSize : parentRenderState.getFont().getSize();
                    return lager * 1.2f;
                case SMALLER:
                    float smaller = parentRenderState == null ? defaultSize : parentRenderState.getFont().getSize();
                    return smaller / 1.2f;
                case INHERIT:
                    float inherit = defaultSize;
                    if (parentRenderState != null && parentRenderState.getPreviousRenderState() != null) {
                        inherit = parentRenderState.getPreviousRenderState().getFont().getSize();
                    }
                    return inherit;
                case INITIAL:
                default:
                    return getPixelSize(spec, parentRenderState, window, (int) defaultSize);
            }
    }
}
Also used : CSSValues(org.loboevolution.html.CSSValues)

Aggregations

CSSValues (org.loboevolution.html.CSSValues)26 RenderState (org.loboevolution.html.renderstate.RenderState)3 BackgroundInfo (org.loboevolution.info.BackgroundInfo)3 CSS3Properties (org.loboevolution.html.node.css.CSS3Properties)2 HTMLElement (org.loboevolution.html.dom.HTMLElement)1 RFlex (org.loboevolution.html.renderer.RFlex)1