Search in sources :

Example 6 with WXStyle

use of com.taobao.weex.dom.WXStyle in project incubator-weex by apache.

the class WXMask method get.

private int get(int type, ImmutableDomObject domObject) {
    try {
        Spacing margin = domObject.getMargin();
        WXStyle style = domObject.getStyles();
        switch(type) {
            case LEFT:
                return add(style.getLeft(), margin.get(Spacing.LEFT));
            case RIGHT:
                return add(style.getRight(), margin.get(Spacing.RIGHT));
            case TOP:
                return add(style.getTop(), margin.get(Spacing.TOP));
            case BOTTOM:
                return add(style.getBottom(), margin.get(Spacing.BOTTOM));
        }
    } catch (Throwable t) {
    // ignore
    }
    return 0;
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) Spacing(com.taobao.weex.dom.flex.Spacing)

Example 7 with WXStyle

use of com.taobao.weex.dom.WXStyle in project WeexErosFramework by bmfe.

the class BMWXText method updateFontSize.

private void updateFontSize() {
    if (mChangeFontSize == null) {
        return;
    }
    WXStyle styles = null;
    WXAttr attrs = null;
    if (getDomObject() != null) {
        styles = getDomObject().getStyles();
        attrs = getDomObject().getAttrs();
        if ((styles != null && "iconfont".equals(styles.get("fontFamily"))) || (attrs != null && attrs.get("changeFont") != null && !Boolean.valueOf((String) attrs.get("changeFont")))) {
            return;
        }
    }
    float scale = 0;
    // 获取fontScale字段
    if (attrs != null && attrs.get("fontScale") != null) {
        float fontScale = Float.valueOf((String) attrs.get("fontScale"));
        mCurrentScale = fontScale / mCurrentScale;
    }
    if (mChangeFontSize.equals(mCurrentFontSize) && mCurrentScale == 1) {
        return;
    }
    // 获取scale字段 在标准字体下不产生变化
    if (attrs != null && attrs.get("scale") != null && !(scale > 0)) {
        scale = Float.valueOf((String) attrs.get("scale"));
        float change = getFixedEnlarge(mChangeFontSize, scale);
        float current = getFixedEnlarge(mCurrentFontSize, scale);
        scale = change / current;
    }
    // 根据全局字体配置设置字体大小
    if (!(scale > 0)) {
        float current = getEnlarge(mCurrentFontSize);
        float change = getEnlarge(mChangeFontSize);
        scale = change / current * mCurrentScale;
    }
    if (getDomObject() != null && getDomObject().getStyles() != null) {
        WXStyle wxStyle = getDomObject().getStyles();
        Object object = wxStyle.get("fontSize");
        if (object instanceof Integer) {
            int fontSize = (int) object;
            int changeFontSize = (int) (fontSize * (scale));
            wxStyle.put("fontSize", changeFontSize);
        }
        // 设置lineHeight
        Object lineHeight = wxStyle.get("lineHeight");
        if (lineHeight instanceof Integer) {
            int target = (int) lineHeight;
            wxStyle.put("lineHeight", (int) (target * scale));
        }
        updateStyle(wxStyle);
    }
    mCurrentFontSize = mChangeFontSize;
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXAttr(com.taobao.weex.dom.WXAttr)

Example 8 with WXStyle

use of com.taobao.weex.dom.WXStyle in project weex-example by KalicyZhou.

the class WXComponent method setPseudoClassStatus.

/**
   *
   * @param clzName like ':active' or ':active:enabled'
   * @param status
   */
protected void setPseudoClassStatus(String clzName, boolean status) {
    WXStyle styles = getDomObject().getStyles();
    Map<String, Map<String, Object>> pesudoStyles = styles.getPesudoStyles();
    if (pesudoStyles == null || pesudoStyles.size() == 0) {
        return;
    }
    Map<String, Object> resultStyles = mPesudoStatus.updateStatusAndGetUpdateStyles(clzName, status, pesudoStyles, styles.getPesudoResetStyles());
    updateStyleByPesudo(resultStyles);
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) IWXObject(com.taobao.weex.common.IWXObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with WXStyle

use of com.taobao.weex.dom.WXStyle in project WeexErosFramework by bmfe.

the class HookWXText method updateFontSize.

private void updateFontSize() {
    if (getDomObject() != null && getDomObject().getStyles().get(Constants.Name.FONT_SIZE) == null) {
        WXStyle s = getDomObject().getStyles();
        s.put(Constants.Name.FONT_SIZE, 30);
        updateStyle(s);
        return;
    }
    if (mChangeFontSize == null) {
        return;
    }
    WXStyle styles = null;
    WXAttr attrs = null;
    if (getDomObject() != null) {
        styles = getDomObject().getStyles();
        attrs = getDomObject().getAttrs();
        if ((styles != null && "iconfont".equals(styles.get("fontFamily"))) || (attrs != null && attrs.get("changeFont") != null && !Boolean.valueOf((String) attrs.get("changeFont")))) {
            return;
        }
    }
    float scale = 0;
    // 获取fontScale字段
    if (attrs != null && attrs.get("fontScale") != null) {
        float fontScale = Float.valueOf((String) attrs.get("fontScale"));
        mCurrentScale = fontScale / mCurrentScale;
    }
    if (mChangeFontSize.equals(mCurrentFontSize) && mCurrentScale == 1) {
        return;
    }
    // 获取scale字段 在标准字体下不产生变化
    if (attrs != null && attrs.get("scale") != null && !(scale > 0)) {
        scale = Float.valueOf((String) attrs.get("scale"));
        float change = getFixedEnlarge(mChangeFontSize, scale);
        float current = getFixedEnlarge(mCurrentFontSize, scale);
        scale = change / current;
    }
    // 根据全局字体配置设置字体大小
    if (!(scale > 0)) {
        float current = getEnlarge(mCurrentFontSize);
        float change = getEnlarge(mChangeFontSize);
        scale = change / current * mCurrentScale;
    }
    if (getDomObject() != null && getDomObject().getStyles() != null) {
        WXStyle wxStyle = getDomObject().getStyles();
        Object object = wxStyle.get("fontSize");
        if (object instanceof Integer) {
            int fontSize = (int) object;
            int changeFontSize = Math.round(fontSize * (scale));
            wxStyle.put("fontSize", changeFontSize);
        }
        // 设置lineHeight
        Object lineHeight = wxStyle.get("lineHeight");
        if (lineHeight instanceof Integer) {
            int target = (int) lineHeight;
            wxStyle.put("lineHeight", Math.round(target * scale));
        }
        updateStyle(wxStyle);
    }
    mCurrentFontSize = mChangeFontSize;
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXAttr(com.taobao.weex.dom.WXAttr)

Example 10 with WXStyle

use of com.taobao.weex.dom.WXStyle in project WeexErosFramework by bmfe.

the class BMRich method update.

private void update() {
    WXStyle styles = getDomObject().getStyles();
    if (styles == null) {
        styles = new WXStyle();
    }
    // 如果此时style为empty不会触发更新 我们在这里加入一个占位符保证style不为empty
    if (styles.isEmpty()) {
        styles.put("placeholder", "bm");
    }
    updateStyle(styles);
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle)

Aggregations

WXStyle (com.taobao.weex.dom.WXStyle)13 WXDomObject (com.taobao.weex.dom.WXDomObject)9 JSONObject (com.alibaba.fastjson.JSONObject)6 WXAttr (com.taobao.weex.dom.WXAttr)5 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)4 IWXObject (com.taobao.weex.common.IWXObject)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Point (android.graphics.Point)1 ArrayMap (android.support.v4.util.ArrayMap)1 View (android.view.View)1 WXEvent (com.taobao.weex.dom.WXEvent)1 Spacing (com.taobao.weex.dom.flex.Spacing)1 ArrayStack (com.taobao.weex.el.parse.ArrayStack)1 WXImage (com.taobao.weex.ui.component.WXImage)1