@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 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); }
private static Typeface createUnderlyingTypeface(String familyName, int style) { long thisFontId = nextFontId++; FONTS.put(thisFontId, new FontDesc(familyName, style)); if (getApiLevel() >= LOLLIPOP) { return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(long.class, thisFontId)); } else { return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(int.class, (int) thisFontId)); } }
@Implementation public int getStyle() { return description.getStyle(); }
@Implementation public int getStyle() { return description.getStyle(); }
@Implementation public int getStyle() { return description.getStyle(); }
@Implementation protected int getStyle() { return description.getStyle(); }
private static Typeface createUnderlyingTypeface(String familyName, int style) { long thisFontId = nextFontId++; FONTS.put(thisFontId, new FontDesc(familyName, style)); if (getApiLevel() >= LOLLIPOP) { return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(long.class, thisFontId)); } else { return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(int.class, (int) thisFontId)); } }
private static Typeface createUnderlyingTypeface(String familyName, int style) { long thisFontId = nextFontId++; FONTS.put(thisFontId, new FontDesc(familyName, style)); return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(long .class, thisFontId)); }
@Implementation public static Typeface create(Typeface family, int style) { if (family == null) { return createUnderlyingTypeface(null, style); } else { return createUnderlyingTypeface(shadowOf(family).getFontDescription().getFamilyName(), style); } }
private static Typeface createUnderlyingTypeface(String familyName, int style) { long thisFontId = nextFontId++; FONTS.put(thisFontId, new FontDesc(familyName, style)); if (getApiLevel() >= LOLLIPOP) { return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(long.class, thisFontId)); } else { return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(int.class, (int) thisFontId)); } }
@Implementation public static Typeface create(Typeface family, int style) { if (family == null) { return createUnderlyingTypeface(null, style); } else { return createUnderlyingTypeface(shadowOf(family).getFontDescription().getFamilyName(), style); } }
private static Typeface createUnderlyingTypeface(String familyName, int style) { long thisFontId = nextFontId++; FONTS.put(thisFontId, new FontDesc(familyName, style)); if (getApiLevel() >= LOLLIPOP) { return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(long.class, thisFontId)); } else { return ReflectionHelpers.callConstructor(Typeface.class, ClassParameter.from(int.class, (int) thisFontId)); } }
@Implementation public static Typeface create(Typeface family, int style) { if (family == null) { return createUnderlyingTypeface(null, style); } else { return createUnderlyingTypeface(shadowOf(family).getFontDescription().getFamilyName(), style); } }
@Implementation protected static Typeface create(Typeface family, int style) { if (family == null) { return createUnderlyingTypeface(null, style); } else { ShadowTypeface shadowTypeface = Shadow.extract(family); return createUnderlyingTypeface(shadowTypeface.getFontDescription().getFamilyName(), style); } }
@Implementation protected int getStyle() { return description.getStyle(); }
@Implementation protected static Typeface create(Typeface family, int style) { if (family == null) { return createUnderlyingTypeface(null, style); } else { ShadowTypeface shadowTypeface = Shadow.extract(family); return createUnderlyingTypeface(shadowTypeface.getFontDescription().getFamilyName(), style); } }
@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); }
@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_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); }