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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations