Java Code Examples for android.graphics.Typeface#getStyle()
The following examples show how to use
android.graphics.Typeface#getStyle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomTypefaceSpan.java From tns-core-modules-widgets with Apache License 2.0 | 6 votes |
private void applyCustomTypeFace(TextPaint paint) { final Typeface old = paint.getTypeface(); final int oldStyle = (old == null) ? 0 : old.getStyle(); Typeface typeface = this.typeface; int fake = oldStyle & ~typeface.getStyle(); if ((fake & android.graphics.Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fake & android.graphics.Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(typeface); }
Example 2
Source File: TypefaceSpan.java From JotaTextEditor with Apache License 2.0 | 6 votes |
private static void apply(Paint paint, String family) { int oldStyle; Typeface old = paint.getTypeface(); if (old == null) { oldStyle = 0; } else { oldStyle = old.getStyle(); } Typeface tf = Typeface.create(family, oldStyle); int fake = oldStyle & ~tf.getStyle(); if ((fake & Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fake & Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(tf); }
Example 3
Source File: CustomTypeFaceSpan.java From FaceT with Mozilla Public License 2.0 | 6 votes |
private static void applyCustomTypeFace(Paint paint, Typeface tf) { int oldStyle; Typeface old = paint.getTypeface(); if (old == null) { oldStyle = 0; } else { oldStyle = old.getStyle(); } int fake = oldStyle & ~tf.getStyle(); if ((fake & Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fake & Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(tf); }
Example 4
Source File: FontAssetManager.java From lottie-android with Apache License 2.0 | 6 votes |
private Typeface typefaceForStyle(Typeface typeface, String style) { int styleInt = Typeface.NORMAL; boolean containsItalic = style.contains("Italic"); boolean containsBold = style.contains("Bold"); if (containsItalic && containsBold) { styleInt = Typeface.BOLD_ITALIC; } else if (containsItalic) { styleInt = Typeface.ITALIC; } else if (containsBold) { styleInt = Typeface.BOLD; } if (typeface.getStyle() == styleInt) { return typeface; } return Typeface.create(typeface, styleInt); }
Example 5
Source File: RobotoLightTypefaceSpan.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
private static void applyCustomTypeFace(Paint paint, Typeface tf) { int oldStyle; Typeface old = paint.getTypeface(); if (old == null) { oldStyle = 0; } else { oldStyle = old.getStyle(); } int fake = oldStyle & ~tf.getStyle(); if ((fake & Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fake & Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(tf); }
Example 6
Source File: CustomTypefaceSpan.java From Newslly with MIT License | 6 votes |
private static void applyCustomTypeFace(Paint paint, Typeface tf) { int oldStyle; Typeface old = paint.getTypeface(); if (old == null) { oldStyle = 0; } else { oldStyle = old.getStyle(); } int fake = oldStyle & ~tf.getStyle(); if ((fake & Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fake & Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(tf); }
Example 7
Source File: ReactTextInputManager.java From react-native-GPay with MIT License | 6 votes |
/** /* This code was taken from the method setFontStyle of the class ReactTextShadowNode /* TODO: Factor into a common place they can both use */ @ReactProp(name = ViewProps.FONT_STYLE) public void setFontStyle(ReactEditText view, @Nullable String fontStyleString) { int fontStyle = UNSET; if ("italic".equals(fontStyleString)) { fontStyle = Typeface.ITALIC; } else if ("normal".equals(fontStyleString)) { fontStyle = Typeface.NORMAL; } Typeface currentTypeface = view.getTypeface(); if (currentTypeface == null) { currentTypeface = Typeface.DEFAULT; } if (fontStyle != currentTypeface.getStyle()) { view.setTypeface(currentTypeface, fontStyle); } }
Example 8
Source File: IconicFontTypefaceSpan.java From android-IconicFontEngine with Apache License 2.0 | 6 votes |
private static void applyCustomTypeFace(Paint paint, Typeface tf) { int oldStyle; Typeface old = paint.getTypeface(); if (old == null) { oldStyle = 0; } else { oldStyle = old.getStyle(); } int fake = oldStyle & ~tf.getStyle(); if ((fake & Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fake & Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(tf); }
Example 9
Source File: Switch.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Sets the typeface and style in which the text should be displayed on the * switch, and turns on the fake bold and italic bits in the Paint if the * Typeface that you provided does not have all the bits in the * style that you specified. */ public void setSwitchTypeface(Typeface tf, int style) { if (style > 0) { if (tf == null) { tf = Typeface.defaultFromStyle(style); } else { tf = Typeface.create(tf, style); } setSwitchTypeface(tf); // now compute what (if any) algorithmic styling is needed int typefaceStyle = tf != null ? tf.getStyle() : 0; int need = style & ~typefaceStyle; mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0); mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0); } else { mTextPaint.setFakeBoldText(false); mTextPaint.setTextSkewX(0); setSwitchTypeface(tf); } }
Example 10
Source File: AbstractCustomFontProvider.java From document-viewer with GNU General Public License v3.0 | 6 votes |
@Override public TypefaceEx getTypeface(final FontPack fp, final FontFamilyType type, final FontStyle style) { FontInfo font = fp.getFont(type, style); Typeface target = null; if (font != null) { target = loadTypeface(type, font); } if (target == null) { final FontStyle base = style.getBase(); if (base != style) { font = fp.getFont(type, base); if (font != null) { target = loadTypeface(type, font); } } } if (target == null) { return null; } final int st = style.getStyle(); final boolean fake = (st & Typeface.BOLD) != (target.getStyle() & Typeface.BOLD); return new TypefaceEx(fp, type, style, target, fake); }
Example 11
Source File: CustomTypefaceSpan.java From Expert-Android-Programming with MIT License | 6 votes |
private static void applyCustomTypeFace(Paint paint, Typeface tf) { int oldStyle; Typeface old = paint.getTypeface(); if (old == null) { oldStyle = 0; } else { oldStyle = old.getStyle(); } int fake = oldStyle & ~tf.getStyle(); if ((fake & Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fake & Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(tf); }
Example 12
Source File: TextAppearance.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Applies the attributes that affect measurement from Typeface to the given TextPaint. * * @see android.text.style.TextAppearanceSpan#updateMeasureState(TextPaint) */ public void updateTextPaintMeasureState( @NonNull TextPaint textPaint, @NonNull Typeface typeface) { textPaint.setTypeface(typeface); int fake = textStyle & ~typeface.getStyle(); textPaint.setFakeBoldText((fake & Typeface.BOLD) != 0); textPaint.setTextSkewX((fake & Typeface.ITALIC) != 0 ? -0.25f : 0f); textPaint.setTextSize(textSize); }
Example 13
Source File: TypefaceUtil.java From weex-uikit with MIT License | 5 votes |
public static void applyFontStyle(Paint paint, int style, int weight, String family) { int oldStyle; Typeface typeface = paint.getTypeface(); if (typeface == null) { oldStyle = 0; } else { oldStyle = typeface.getStyle(); } int want = 0; if ((weight == Typeface.BOLD) || ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) { want |= Typeface.BOLD; } if ((style == Typeface.ITALIC) || ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) { want |= Typeface.ITALIC; } if (family != null) { typeface = getOrCreateTypeface(family, want); } if (typeface != null) { paint.setTypeface(Typeface.create(typeface, want)); } else { paint.setTypeface(Typeface.defaultFromStyle(want)); } }
Example 14
Source File: TextAppearanceSpan.java From JotaTextEditor with Apache License 2.0 | 5 votes |
@Override public void updateMeasureState(TextPaint ds) { if (mTypeface != null || mStyle != 0) { Typeface tf = ds.getTypeface(); int style = 0; if (tf != null) { style = tf.getStyle(); } style |= mStyle; if (mTypeface != null) { tf = Typeface.create(mTypeface, style); } else if (tf == null) { tf = Typeface.defaultFromStyle(style); } else { tf = Typeface.create(tf, style); } int fake = style & ~tf.getStyle(); if ((fake & Typeface.BOLD) != 0) { ds.setFakeBoldText(true); } if ((fake & Typeface.ITALIC) != 0) { ds.setTextSkewX(-0.25f); } ds.setTypeface(tf); } if (mTextSize > 0) { ds.setTextSize(mTextSize); } }
Example 15
Source File: PromptUtils.java From styT with Apache License 2.0 | 5 votes |
/** * Based on setTypeface in android TextView, Copyright (C) 2006 The Android Open Source * Project. https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/widget/TextView.java */ public static void setTypeface(@NonNull TextPaint textPaint, @Nullable Typeface typeface, int style) { if (style > 0) { if (typeface == null) { typeface = Typeface.defaultFromStyle(style); } else { typeface = Typeface.create(typeface, style); } textPaint.setTypeface(typeface); int typefaceStyle = typeface != null ? typeface.getStyle() : 0; int need = style & ~typefaceStyle; textPaint.setFakeBoldText((need & Typeface.BOLD) != 0); textPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0); } else if (typeface != null) { textPaint.setTypeface(typeface); } else { textPaint.setTypeface(Typeface.defaultFromStyle(style)); } }
Example 16
Source File: CustomStyleSpan.java From react-native-GPay with MIT License | 5 votes |
private static void apply( Paint paint, int style, int weight, @Nullable String family, AssetManager assetManager) { int oldStyle; Typeface typeface = paint.getTypeface(); if (typeface == null) { oldStyle = 0; } else { oldStyle = typeface.getStyle(); } int want = 0; if ((weight == Typeface.BOLD) || ((oldStyle & Typeface.BOLD) != 0 && weight == ReactTextShadowNode.UNSET)) { want |= Typeface.BOLD; } if ((style == Typeface.ITALIC) || ((oldStyle & Typeface.ITALIC) != 0 && style == ReactTextShadowNode.UNSET)) { want |= Typeface.ITALIC; } if (family != null) { typeface = ReactFontManager.getInstance().getTypeface(family, want, assetManager); } else if (typeface != null) { // TODO(t9055065): Fix custom fonts getting applied to text children with different style typeface = Typeface.create(typeface, want); } if (typeface != null) { paint.setTypeface(typeface); } else { paint.setTypeface(Typeface.defaultFromStyle(want)); } paint.setSubpixelText(true); }
Example 17
Source File: WXCustomStyleSpan.java From weex with Apache License 2.0 | 5 votes |
private static void apply(Paint paint, int style, int weight, String family) { int oldStyle; Typeface typeface = paint.getTypeface(); if (typeface == null) { oldStyle = 0; } else { oldStyle = typeface.getStyle(); } int want = 0; if ((weight == Typeface.BOLD) || ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) { want |= Typeface.BOLD; } if ((style == Typeface.ITALIC) || ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) { want |= Typeface.ITALIC; } if (family != null) { typeface = getOrCreateTypeface(family, want); } if (typeface != null) { paint.setTypeface(Typeface.create(typeface, want)); } else { paint.setTypeface(Typeface.defaultFromStyle(want)); } }
Example 18
Source File: FontUtils.java From zom-android-matrix with Apache License 2.0 | 5 votes |
/** * Gets roboto typeface according to passed typeface style settings. * <p/> * Will get Roboto-Bold for Typeface.BOLD etc */ private static Typeface getRobotoTypeface(Context context, Typeface originalTypeface) { FontType robotoFontType = null; if (originalTypeface == null) { robotoFontType = FontType.NORMAL; } else { int style = originalTypeface.getStyle(); switch (style) { case Typeface.BOLD: robotoFontType = FontType.BOLD; break; case Typeface.BOLD_ITALIC: robotoFontType = FontType.BOLD_ITALIC; break; case Typeface.ITALIC: robotoFontType = FontType.ITALIC; break; default: robotoFontType = FontType.NORMAL; break; } } return getRobotoTypeface(context, robotoFontType); }
Example 19
Source File: Heading.java From Ruisi with Apache License 2.0 | 5 votes |
public static void applyStyle(Paint paint, int style) { int oldStyle; Typeface old = paint.getTypeface(); if (old == null) { oldStyle = 0; } else { oldStyle = old.getStyle(); } int want = oldStyle | style; Typeface tf; if (old == null) { tf = Typeface.defaultFromStyle(want); } else { tf = Typeface.create(old, want); } int fake = want & ~tf.getStyle(); if ((fake & Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fake & Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(tf); }
Example 20
Source File: TokenCompleteTextView.java From SocialTokenAutoComplete with Apache License 2.0 | 4 votes |
private void updateHint() { Editable text = getText(); CharSequence hintText = getHint(); if (text == null || hintText == null) { return; } //Show hint if we need to if (prefix.length() > 0) { HintSpan[] hints = text.getSpans(0, text.length(), HintSpan.class); HintSpan hint = null; int testLength = prefix.length(); if (hints.length > 0) { hint = hints[0]; testLength += text.getSpanEnd(hint) - text.getSpanStart(hint); } if (text.length() == testLength) { hintVisible = true; if (hint != null) { return;//hint already visible } //We need to display the hint manually Typeface tf = getTypeface(); int style = Typeface.NORMAL; if (tf != null) { style = tf.getStyle(); } ColorStateList colors = getHintTextColors(); HintSpan hintSpan = new HintSpan(null, style, (int)getTextSize(), colors, colors); text.insert(prefix.length(), hintText); text.setSpan(hintSpan, prefix.length(), prefix.length() + getHint().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setSelection(prefix.length()); } else { if (hint == null) { return; //hint already removed } //Remove the hint. There should only ever be one int sStart = text.getSpanStart(hint); int sEnd = text.getSpanEnd(hint); text.removeSpan(hint); text.replace(sStart, sEnd, ""); hintVisible = false; } } }