Home | History | Annotate | Download | only in graphics

Lines Matching defs:Typeface

73  * The Typeface class specifies the typeface and intrinsic style of a font.
78 public class Typeface {
80 private static String TAG = "Typeface";
82 /** The default NORMAL typeface object */
83 public static final Typeface DEFAULT;
85 * The default BOLD typeface object. Note: this may be not actually be
89 public static final Typeface DEFAULT_BOLD;
90 /** The NORMAL style of the default sans serif typeface. */
91 public static final Typeface SANS_SERIF;
92 /** The NORMAL style of the default serif typeface. */
93 public static final Typeface SERIF;
94 /** The NORMAL style of the default monospace typeface. */
95 public static final Typeface MONOSPACE;
97 static Typeface[] sDefaults;
98 private static final LongSparseArray<SparseArray<Typeface>> sTypefaceCache =
102 * Cache for Typeface objects dynamically loaded from assets. Currently max size is 16.
105 private static final LruCache<String, Typeface> sDynamicTypefaceCache = new LruCache<>(16);
107 static Typeface sDefaultTypeface;
108 static Map<String, Typeface> sSystemFontMap;
133 // Style value for building typeface.
140 private static void setDefault(Typeface t) {
145 /** Returns the typeface's intrinsic style attributes */
165 public static Typeface createFromResources(AssetManager mgr, String path, int cookie) {
171 Typeface typeface = sDynamicTypefaceCache.get(key);
172 if (typeface != null) return typeface;
183 typeface = createFromFamiliesWithDefault(families,
185 sDynamicTypefaceCache.put(key, typeface);
186 return typeface;
198 public static Typeface createFromResources(
220 Typeface typeface = FontsContract.getFontSync(request);
221 return typeface == null ? DEFAULT : typeface;
224 Typeface typeface = findFromCache(mgr, path);
225 if (typeface != null) return typeface;
244 typeface = createFromFamiliesWithDefault(familyChain,
250 sDynamicTypefaceCache.put(key, typeface);
252 return typeface;
261 public static Typeface findFromCache(AssetManager mgr, String path) {
265 Typeface typeface = sDynamicTypefaceCache.get(key);
266 if (typeface != null) {
267 return typeface;
274 * A builder class for creating new Typeface instance.
278 * 1) Create Typeface from ttf file.
281 * Typeface.Builder buidler = new Typeface.Builder("your_font_file.ttf");
282 * Typeface typeface = builder.build();
286 * 2) Create Typeface from ttc file in assets directory.
289 * Typeface.Builder buidler = new Typeface.Builder(getAssets(), "your_font_file.ttc");
291 * Typeface typeface = builder.build();
295 * 3) Create Typeface with variation settings.
298 * Typeface.Builder buidler = new Typeface.Builder("your_font_file.ttf");
302 * Typeface typeface = builder.build();
415 * Can not be used for Typeface source. build() method will return null for invalid index.
467 * By specifying a fallback family name, a fallback Typeface will be returned if the
468 * {@link #build} method fails to create a Typeface from the provided font. The fallback
477 * {@link #setWeight} and {@link #setItalic}. For example, if a Typeface is constructed
528 // TODO: Unify with Typeface.sTypefaceCache.
530 private static final LongSparseArray<SparseArray<Typeface>> sTypefaceCache =
533 private Typeface resolveFallbackTypeface() {
538 Typeface base = sSystemFontMap.get(mFallbackFamilyName);
552 Typeface typeface;
554 SparseArray<Typeface> innerCache = sTypefaceCache.get(base.native_instance);
556 typeface = innerCache.get(key);
557 if (typeface != null) {
558 return typeface;
562 typeface = new Typeface(
570 innerCache.put(key, typeface);
572 return typeface;
576 * Generates new Typeface from specified configuration.
578 * @return Newly created Typeface. May return null if some parameters are invalid.
580 public Typeface build() {
604 Typeface typeface = sDynamicTypefaceCache.get(key);
605 if (typeface != null) return typeface;
616 typeface = createFromFamiliesWithDefault(families, mWeight, mItalic);
617 sDynamicTypefaceCache.put(key, typeface);
618 return typeface;
649 // No fonts are avaialble. No need to create new Typeface and returns fallback
650 // Typeface instead.
665 * Create a typeface object given a family name, and option style information.
667 * The resulting typeface object can be queried (getStyle()) to discover what
671 * @param style The style (normal, bold, italic) of the typeface.
673 * @return The best matching typeface.
675 public static Typeface create(String familyName, int style) {
683 * Create a typeface object that best matches the specified existing
684 * typeface and the specified Style. Use this call if you want to pick a new
685 * style from the same family of an existing typeface object. If family is
689 * @param style The style (normal, bold, italic) of the typeface.
691 * @return The best matching typeface.
693 public static Typeface create(Typeface family, int style) {
707 Typeface typeface;
708 SparseArray<Typeface> styles = sTypefaceCache.get(ni);
711 typeface = styles.get(style);
712 if (typeface != null) {
713 return typeface;
717 typeface = new Typeface(nativeCreateFromTypeface(ni, style));
719 styles = new SparseArray<Typeface>(4);
722 styles.put(style, typeface);
724 return typeface;
728 public static Typeface createFromTypefaceWithVariation(@Nullable Typeface family,
731 return new Typeface(nativeCreateFromTypefaceWithVariation(ni, axes));
735 * Returns one of the default typeface objects, based on the specified style
737 * @return the default typeface that corresponds to the style
739 public static Typeface defaultFromStyle(int style) {
744 * Create a new typeface from the specified font data.
748 * @return The new typeface.
750 public static Typeface createFromAsset(AssetManager mgr, String path) {
756 Typeface typeface = new Builder(mgr, path).build();
757 if (typeface != null) return typeface;
761 typeface = sDynamicTypefaceCache.get(key);
762 if (typeface != null) return typeface;
769 // stack, we need to place the empty font at the first place. The typeface with
770 // empty font behaves different from default typeface especially in fallback
775 typeface = createFromFamiliesWithDefault(families, RESOLVE_BY_FONT_TABLE,
777 sDynamicTypefaceCache.put(key, typeface);
778 return typeface;
800 * Create a new typeface from the specified font file.
803 * @return The new typeface.
805 public static Typeface createFromFile(@Nullable File path) {
812 * Create a new typeface from the specified font file.
815 * @return The new typeface.
817 public static Typeface createFromFile(@Nullable String path) {
823 // stack, we need to place the empty font at the first place. The typeface with
824 // empty font behaves different from default typeface especially in fallback font
839 * Create a new typeface from an array of font families.
843 private static Typeface createFromFamilies(FontFamily[] families) {
848 return new Typeface(nativeCreateFromArray(
853 * Create a new typeface from an array of font families, including
865 private static Typeface createFromFamiliesWithDefault(FontFamily[] families,
874 return new Typeface(nativeCreateFromArray(ptrArray, weight, italic));
878 private Typeface(long ni) {
880 throw new RuntimeException("native typeface cannot be made");
935 // Note that the default typeface is always present in the fallback list;
947 setDefault(Typeface.createFromFamilies(sFallbackFonts));
949 Map<String, Typeface> systemFonts = new HashMap<String, Typeface>();
951 Typeface typeface;
955 // The first entry is the default typeface; no sense in
957 typeface = sDefaultTypeface;
964 typeface = Typeface.createFromFamiliesWithDefault(families,
967 systemFonts.put(f.getName(), typeface);
971 Typeface base = systemFonts.get(alias.getToName());
972 Typeface newFace = base;
975 newFace = new Typeface(nativeCreateWeightAlias(base.native_instance, weight));
997 DEFAULT_BOLD = create((String) null, Typeface.BOLD);
1002 sDefaults = new Typeface[] {
1005 create((String) null, Typeface.ITALIC),
1006 create((String) null, Typeface.BOLD_ITALIC),
1030 Typeface typeface = (Typeface) o;
1032 return mStyle == typeface.mStyle && native_instance == typeface.native_instance;