Methods Summary |
---|
public static android.graphics.Typeface | create(java.lang.String familyName, int style)Create a typeface object given a family name, and option style information.
If null is passed for the name, then the "default" font will be chosen.
The resulting typeface object can be queried (getStyle()) to discover what
its "real" style characteristics are.
if (sSystemFontMap != null) {
return create(sSystemFontMap.get(familyName), style);
}
return null;
|
public static android.graphics.Typeface | create(android.graphics.Typeface family, int style)Create a typeface object that best matches the specified existing
typeface and the specified Style. Use this call if you want to pick a new
style from the same family of an existing typeface object. If family is
null, this selects from the default font's family.
if (style < 0 || style > 3) {
style = 0;
}
long ni = 0;
if (family != null) {
// Return early if we're asked for the same face/style
if (family.mStyle == style) {
return family;
}
ni = family.native_instance;
}
Typeface typeface;
SparseArray<Typeface> styles = sTypefaceCache.get(ni);
if (styles != null) {
typeface = styles.get(style);
if (typeface != null) {
return typeface;
}
}
typeface = new Typeface(nativeCreateFromTypeface(ni, style));
if (styles == null) {
styles = new SparseArray<Typeface>(4);
sTypefaceCache.put(ni, styles);
}
styles.put(style, typeface);
return typeface;
|
public static android.graphics.Typeface | createFromAsset(android.content.res.AssetManager mgr, java.lang.String path)Create a new typeface from the specified font data.
if (sFallbackFonts != null) {
FontFamily fontFamily = new FontFamily();
if (fontFamily.addFontFromAsset(mgr, path)) {
FontFamily[] families = { fontFamily };
return createFromFamiliesWithDefault(families);
}
}
throw new RuntimeException("Font asset not found " + path);
|
public static android.graphics.Typeface | createFromFamilies(FontFamily[] families)Create a new typeface from an array of font families.
long[] ptrArray = new long[families.length];
for (int i = 0; i < families.length; i++) {
ptrArray[i] = families[i].mNativePtr;
}
return new Typeface(nativeCreateFromArray(ptrArray));
|
public static android.graphics.Typeface | createFromFamiliesWithDefault(FontFamily[] families)Create a new typeface from an array of font families, including
also the font families in the fallback list.
long[] ptrArray = new long[families.length + sFallbackFonts.length];
for (int i = 0; i < families.length; i++) {
ptrArray[i] = families[i].mNativePtr;
}
for (int i = 0; i < sFallbackFonts.length; i++) {
ptrArray[i + families.length] = sFallbackFonts[i].mNativePtr;
}
return new Typeface(nativeCreateFromArray(ptrArray));
|
public static android.graphics.Typeface | createFromFile(java.lang.String path)Create a new typeface from the specified font file.
if (sFallbackFonts != null) {
FontFamily fontFamily = new FontFamily();
if (fontFamily.addFont(path)) {
FontFamily[] families = { fontFamily };
return createFromFamiliesWithDefault(families);
}
}
throw new RuntimeException("Font not found " + path);
|
public static android.graphics.Typeface | createFromFile(java.io.File path)Create a new typeface from the specified font file.
return createFromFile(path.getAbsolutePath());
|
public static android.graphics.Typeface | defaultFromStyle(int style)Returns one of the default typeface objects, based on the specified style
return sDefaults[style];
|
public boolean | equals(java.lang.Object o)
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Typeface typeface = (Typeface) o;
return mStyle == typeface.mStyle && native_instance == typeface.native_instance;
|
protected void | finalize()
try {
nativeUnref(native_instance);
} finally {
super.finalize();
}
|
public int | getStyle()Returns the typeface's intrinsic style attributes
return mStyle;
|
private static java.io.File | getSystemFontConfigLocation()
init();
// Set up defaults and typefaces exposed in public API
DEFAULT = create((String) null, 0);
DEFAULT_BOLD = create((String) null, Typeface.BOLD);
SANS_SERIF = create("sans-serif", 0);
SERIF = create("serif", 0);
MONOSPACE = create("monospace", 0);
sDefaults = new Typeface[] {
DEFAULT,
DEFAULT_BOLD,
create((String) null, Typeface.ITALIC),
create((String) null, Typeface.BOLD_ITALIC),
};
return new File("/system/etc/");
|
public int | hashCode()
/*
* Modified method for hashCode with long native_instance derived from
* http://developer.android.com/reference/java/lang/Object.html
*/
int result = 17;
result = 31 * result + (int) (native_instance ^ (native_instance >>> 32));
result = 31 * result + mStyle;
return result;
|
private static void | init()
// Load font config and initialize Minikin state
File systemFontConfigLocation = getSystemFontConfigLocation();
File configFilename = new File(systemFontConfigLocation, FONTS_CONFIG);
try {
FileInputStream fontsIn = new FileInputStream(configFilename);
FontListParser.Config fontConfig = FontListParser.parse(fontsIn);
List<FontFamily> familyList = new ArrayList<FontFamily>();
// Note that the default typeface is always present in the fallback list;
// this is an enhancement from pre-Minikin behavior.
for (int i = 0; i < fontConfig.families.size(); i++) {
Family f = fontConfig.families.get(i);
if (i == 0 || f.name == null) {
familyList.add(makeFamilyFromParsed(f));
}
}
sFallbackFonts = familyList.toArray(new FontFamily[familyList.size()]);
setDefault(Typeface.createFromFamilies(sFallbackFonts));
Map<String, Typeface> systemFonts = new HashMap<String, Typeface>();
for (int i = 0; i < fontConfig.families.size(); i++) {
Typeface typeface;
Family f = fontConfig.families.get(i);
if (f.name != null) {
if (i == 0) {
// The first entry is the default typeface; no sense in
// duplicating the corresponding FontFamily.
typeface = sDefaultTypeface;
} else {
FontFamily fontFamily = makeFamilyFromParsed(f);
FontFamily[] families = { fontFamily };
typeface = Typeface.createFromFamiliesWithDefault(families);
}
systemFonts.put(f.name, typeface);
}
}
for (FontListParser.Alias alias : fontConfig.aliases) {
Typeface base = systemFonts.get(alias.toName);
Typeface newFace = base;
int weight = alias.weight;
if (weight != 400) {
newFace = new Typeface(nativeCreateWeightAlias(base.native_instance, weight));
}
systemFonts.put(alias.name, newFace);
}
sSystemFontMap = systemFonts;
} catch (RuntimeException e) {
Log.w(TAG, "Didn't create default family (most likely, non-Minikin build)", e);
// TODO: normal in non-Minikin case, remove or make error when Minikin-only
} catch (FileNotFoundException e) {
Log.e(TAG, "Error opening " + configFilename);
} catch (IOException e) {
Log.e(TAG, "Error reading " + configFilename);
} catch (XmlPullParserException e) {
Log.e(TAG, "XML parse exception for " + configFilename);
}
|
public final boolean | isBold()Returns true if getStyle() has the BOLD bit set.
return (mStyle & BOLD) != 0;
|
public final boolean | isItalic()Returns true if getStyle() has the ITALIC bit set.
return (mStyle & ITALIC) != 0;
|
private static FontFamily | makeFamilyFromParsed(android.graphics.FontListParser.Family family)
FontFamily fontFamily = new FontFamily(family.lang, family.variant);
for (FontListParser.Font font : family.fonts) {
fontFamily.addFontWeightStyle(font.fontName, font.weight, font.isItalic);
}
return fontFamily;
|
private static native long | nativeCreateFromArray(long[] familyArray)
|
private static native long | nativeCreateFromTypeface(long native_instance, int style)
|
private static native long | nativeCreateWeightAlias(long native_instance, int weight)
|
private static native int | nativeGetStyle(long native_instance)
|
private static native void | nativeSetDefault(long native_instance)
|
private static native void | nativeUnref(long native_instance)
|
private static void | setDefault(android.graphics.Typeface t)
sDefaultTypeface = t;
nativeSetDefault(t.native_instance);
|