summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-05-15 02:04:16 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-15 02:04:17 +0000
commit091d1ea18a4e38f53c95ad294a0bba54a7c337a6 (patch)
tree30d1f6fd20e7366cf3d4183e1609419982d70c9e /graphics
parent9e2b288ba89ad78ba601eef4843831b382a17bd5 (diff)
parent363e21b4518d7059638df2821b8a0947f74eaf2c (diff)
downloadframeworks_base-091d1ea18a4e38f53c95ad294a0bba54a7c337a6.zip
frameworks_base-091d1ea18a4e38f53c95ad294a0bba54a7c337a6.tar.gz
frameworks_base-091d1ea18a4e38f53c95ad294a0bba54a7c337a6.tar.bz2
Merge "Add fallback fonts to system fonts (Minikin)"
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/Typeface.java57
1 files changed, 43 insertions, 14 deletions
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index 7322948..64451c4 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -64,6 +64,7 @@ public class Typeface {
static Typeface sDefaultTypeface;
static Map<String, Typeface> sSystemFontMap;
+ static FontFamily[] sFallbackFonts;
/**
* @hide
@@ -205,14 +206,30 @@ public class Typeface {
*/
public static Typeface createFromFamilies(FontFamily[] families) {
long[] ptrArray = new long[families.length];
- Log.d("Minikin", "# of families: " + families.length);
for (int i = 0; i < families.length; i++) {
- Log.d("Minikin", "family ptr: " + families[i].mNativePtr);
ptrArray[i] = families[i].mNativePtr;
}
return new Typeface(nativeCreateFromArray(ptrArray));
}
+ /**
+ * Create a new typeface from an array of font families, including
+ * also the font families in the fallback list.
+ *
+ * @param families array of font families
+ * @hide
+ */
+ public static Typeface createFromFamiliesWithDefault(FontFamily[] families) {
+ 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));
+ }
+
// don't allow clients to call this directly
private Typeface(long ni) {
if (ni == 0) {
@@ -243,25 +260,37 @@ public class Typeface {
FileInputStream systemIn = new FileInputStream(systemConfigFilename);
List<FontListParser.Family> systemFontConfig = FontListParser.parse(systemIn);
+
+ FileInputStream fallbackIn = new FileInputStream(configFilename);
+ 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.
+ familyList.add(makeFamilyFromParsed(systemFontConfig.get(0)));
+ for (Family f : FontListParser.parse(fallbackIn)) {
+ familyList.add(makeFamilyFromParsed(f));
+ }
+ sFallbackFonts = familyList.toArray(new FontFamily[familyList.size()]);
+ setDefault(Typeface.createFromFamilies(sFallbackFonts));
+
Map<String, Typeface> systemFonts = new HashMap<String, Typeface>();
- for (Family f : systemFontConfig) {
- FontFamily fontFamily = makeFamilyFromParsed(f);
- FontFamily[] families = { fontFamily };
- Typeface typeface = Typeface.createFromFamilies(families);
+ for (int i = 0; i < systemFontConfig.size(); i++) {
+ Typeface typeface;
+ Family f = systemFontConfig.get(i);
+ 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);
+ }
for (String name : f.names) {
systemFonts.put(name, typeface);
}
}
sSystemFontMap = systemFonts;
- FileInputStream fallbackIn = new FileInputStream(configFilename);
- List<FontFamily> families = new ArrayList<FontFamily>();
- families.add(makeFamilyFromParsed(systemFontConfig.get(0)));
- for (Family f : FontListParser.parse(fallbackIn)) {
- families.add(makeFamilyFromParsed(f));
- }
- FontFamily[] familyArray = families.toArray(new FontFamily[families.size()]);
- setDefault(Typeface.createFromFamilies(familyArray));
} catch (RuntimeException e) {
Log.w(TAG, "Didn't create default family (most likely, non-Minikin build)");
// TODO: normal in non-Minikin case, remove or make error when Minikin-only