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); } }
@Override public void setRectColor(Paint rectPaint) { final Typeface typeface = getTypeface(); if (typeface != null && typeface.getStyle()== Typeface.BOLD ) { rectPaint.setColor(darkerColorResource); } else { rectPaint.setColor(defaultColorResource); } }
private int hintStyle() { Typeface tf = getTypeface(); int style = Typeface.NORMAL; if (tf != null) { style = tf.getStyle(); } return style; }
private void apply(final Paint paint) { final Typeface oldTypeface = paint.getTypeface(); final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0; final int fakeStyle = oldStyle & ~typeface.getStyle(); if ((fakeStyle & Typeface.BOLD) != 0) { paint.setFakeBoldText(true); } if ((fakeStyle & Typeface.ITALIC) != 0) { paint.setTextSkewX(-0.25f); } paint.setTypeface(typeface); } }
public TypefaceAssert hasStyle(int style) { isNotNull(); int actualStyle = actual.getStyle(); assertThat(actualStyle) // .overridingErrorMessage("Expected style <%s> but was <%s>.", style, actualStyle) // .isEqualTo(style); return this; }
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); } }
final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0; final int fakeStyle = oldStyle & ~typeface.getStyle();
@Test public void createFromAsset_shouldCreateTypeface() { Typeface typeface = Typeface.createFromAsset( ApplicationProvider.getApplicationContext().getAssets(), "myFont.ttf"); assertThat(typeface.getStyle()).isEqualTo(Typeface.NORMAL); assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("myFont.ttf"); assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.NORMAL); }
@Test public void createFromFile_withFile_shouldCreateTypeface() { Typeface typeface = Typeface.createFromFile(fontFile); assertThat(typeface.getStyle()).isEqualTo(Typeface.NORMAL); assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("myFont.ttf"); }
@Test public void createFromFile_withPath_shouldCreateTypeface() { Typeface typeface = Typeface.createFromFile(fontFile.getPath()); assertThat(typeface.getStyle()).isEqualTo(Typeface.NORMAL); assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("myFont.ttf"); assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.NORMAL); }
@Test public void create_withoutFamily_shouldCreateTypeface() { Typeface typeface = Typeface.create((Typeface) null, Typeface.ITALIC); assertThat(typeface.getStyle()).isEqualTo(Typeface.ITALIC); assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo(null); assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.ITALIC); }
@Test public void create_withFamilyName_shouldCreateTypeface() { Typeface typeface = Typeface.create("roboto", Typeface.BOLD); assertThat(typeface.getStyle()).isEqualTo(Typeface.BOLD); assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("roboto"); assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.BOLD); }
@Test public void create_withFamily_shouldCreateTypeface() { Typeface typeface = Typeface.create(Typeface.create("roboto", Typeface.BOLD), Typeface.ITALIC); assertThat(typeface.getStyle()).isEqualTo(Typeface.ITALIC); assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("roboto"); assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.ITALIC); }
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)); } }
int typefaceStyle = typeface != null ? typeface.getStyle() : 0; int need = style & ~typefaceStyle; textPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
assertEquals(Typeface.NORMAL, typeface.getStyle()); assertEquals(Typeface.BOLD, typeface.getStyle()); assertEquals(Typeface.ITALIC, typeface.getStyle()); assertEquals(Typeface.BOLD_ITALIC, typeface.getStyle()); assertEquals(Typeface.NORMAL, typeface.getStyle()); assertEquals(Typeface.BOLD, typeface.getStyle()); assertEquals(Typeface.ITALIC, typeface.getStyle()); assertEquals(Typeface.BOLD_ITALIC, typeface.getStyle()); assertEquals(Typeface.NORMAL, typeface.getStyle()); assertEquals(Typeface.BOLD, typeface.getStyle()); assertEquals(Typeface.ITALIC, typeface.getStyle()); assertEquals(Typeface.BOLD_ITALIC, typeface.getStyle()); assertEquals(Typeface.NORMAL, typeface.getStyle()); assertEquals(Typeface.BOLD, typeface.getStyle()); assertEquals(Typeface.ITALIC, typeface.getStyle());
assertEquals(Typeface.NORMAL, textPaint.getTypeface().getStyle()); assertEquals(Typeface.BOLD, textPaint.getTypeface().getStyle()); assertEquals(Typeface.BOLD, textPaint.getTypeface().getStyle()); assertEquals(Typeface.ITALIC, textPaint.getTypeface().getStyle()); assertEquals(Typeface.ITALIC, textPaint.getTypeface().getStyle()); assertEquals(Typeface.BOLD_ITALIC, textPaint.getTypeface().getStyle()); assertEquals(Typeface.BOLD_ITALIC, textPaint.getTypeface().getStyle()); assertEquals(Typeface.BOLD_ITALIC, textPaint.getTypeface().getStyle()); assertEquals(Typeface.ITALIC, textPaint.getTypeface().getStyle()); assertEquals(Typeface.BOLD, textPaint.getTypeface().getStyle()); assertEquals(Typeface.ITALIC, textPaint.getTypeface().getStyle()); assertEquals(Typeface.BOLD, textPaint.getTypeface().getStyle());
@Override public TypefaceEx getTypeface(final FontPack fp, final FontFamilyType type, final FontStyle style) { final int st = style.getStyle(); final Typeface family = type.getSystem(); final Typeface target = Typeface.create(family, st); final boolean fake = (st & Typeface.BOLD) != (target.getStyle() & Typeface.BOLD); return new TypefaceEx(fp, type, style, target, fake); }