List of usage examples for android.text Layout getPaint
public final TextPaint getPaint()
From source file:com.taobao.weex.ui.component.WXText.java
private void registerTypefaceObserver(String desiredFontFamily) { if (WXEnvironment.getApplication() == null) { WXLogUtils.w("WXText", "ApplicationContent is null on register typeface observer"); return;/*from w w w . j a v a 2s . com*/ } mFontFamily = desiredFontFamily; if (mTypefaceObserver != null) { return; } mTypefaceObserver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String fontFamily = intent.getStringExtra("fontFamily"); if (!mFontFamily.equals(fontFamily)) { return; } FontDO fontDO = TypefaceUtil.getFontDO(fontFamily); if (fontDO != null && fontDO.getTypeface() != null && getHostView() != null) { WXTextView hostView = getHostView(); Layout layout = hostView.getTextLayout(); if (layout != null) { layout.getPaint().setTypeface(fontDO.getTypeface()); WXLogUtils.d("WXText", "Apply font family " + fontFamily + " to paint"); } else { WXLogUtils.w("WXText", "Layout not created"); } hostView.invalidate(); } WXLogUtils.d("WXText", "Font family " + fontFamily + " is available"); } }; LocalBroadcastManager.getInstance(WXEnvironment.getApplication()).registerReceiver(mTypefaceObserver, new IntentFilter(TypefaceUtil.ACTION_TYPE_FACE_AVAILABLE)); }
From source file:com.facebook.litho.widget.TextSpec.java
@OnMeasure static void onMeasure(ComponentContext context, ComponentLayout layout, int widthSpec, int heightSpec, Size size, @Prop(resType = ResType.STRING) CharSequence text, @Prop(optional = true) TruncateAt ellipsize, @Prop(optional = true, resType = ResType.BOOL) boolean shouldIncludeFontPadding, @Prop(optional = true, resType = ResType.INT) int minLines, @Prop(optional = true, resType = ResType.INT) int maxLines, @Prop(optional = true, resType = ResType.INT) int minEms, @Prop(optional = true, resType = ResType.INT) int maxEms, @Prop(optional = true, resType = ResType.DIMEN_SIZE) int minWidth, @Prop(optional = true, resType = ResType.DIMEN_SIZE) int maxWidth, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy, @Prop(optional = true, resType = ResType.COLOR) int shadowColor, @Prop(optional = true, resType = ResType.BOOL) boolean isSingleLine, @Prop(optional = true, resType = ResType.COLOR) int textColor, @Prop(optional = true) ColorStateList textColorStateList, @Prop(optional = true, resType = ResType.COLOR) int linkColor, @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float extraSpacing, @Prop(optional = true, resType = ResType.FLOAT) float spacingMultiplier, @Prop(optional = true) int textStyle, @Prop(optional = true) Typeface typeface, @Prop(optional = true) Alignment textAlignment, @Prop(optional = true) boolean glyphWarming, @Prop(optional = true) TextDirectionHeuristicCompat textDirection, Output<Layout> measureLayout, Output<Integer> measuredWidth, Output<Integer> measuredHeight) { if (TextUtils.isEmpty(text)) { measureLayout.set(null);/*from w ww. j a v a 2 s . com*/ size.width = 0; size.height = 0; return; } Layout newLayout = createTextLayout(widthSpec, ellipsize, shouldIncludeFontPadding, maxLines, shadowRadius, shadowDx, shadowDy, shadowColor, isSingleLine, text, textColor, textColorStateList, linkColor, textSize, extraSpacing, spacingMultiplier, textStyle, typeface, textAlignment, glyphWarming, layout.getResolvedLayoutDirection(), minEms, maxEms, minWidth, maxWidth, textDirection); measureLayout.set(newLayout); size.width = SizeSpec.resolveSize(widthSpec, newLayout.getWidth()); // Adjust height according to the minimum number of lines. int preferredHeight = LayoutMeasureUtil.getHeight(newLayout); final int lineCount = newLayout.getLineCount(); if (lineCount < minLines) { final TextPaint paint = newLayout.getPaint(); final int lineHeight = Math.round(paint.getFontMetricsInt(null) * spacingMultiplier + extraSpacing); preferredHeight += lineHeight * (minLines - lineCount); } size.height = SizeSpec.resolveSize(heightSpec, preferredHeight); // Some devices seem to be returning negative sizes in some cases. if (size.width < 0 || size.height < 0) { size.width = Math.max(size.width, 0); size.height = Math.max(size.height, 0); final ComponentsLogger logger = context.getLogger(); if (logger != null) { final LogEvent event = logger.newEvent(EVENT_ERROR); event.addParam(PARAM_MESSAGE, "Text layout measured to less than 0 pixels"); logger.log(event); } } measuredWidth.set(size.width); measuredHeight.set(size.height); }