summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-05-08 22:59:07 -0700
committerRaph Levien <raph@google.com>2014-05-12 10:41:43 -0700
commit363e21b4518d7059638df2821b8a0947f74eaf2c (patch)
treea17c81f5cd6d66f44edbe802f145b887e9bd2258 /graphics
parent15cf4757dc0099301662f8a26da561434cc07cfa (diff)
downloadframeworks_base-363e21b4518d7059638df2821b8a0947f74eaf2c.zip
frameworks_base-363e21b4518d7059638df2821b8a0947f74eaf2c.tar.gz
frameworks_base-363e21b4518d7059638df2821b8a0947f74eaf2c.tar.bz2
Add fallback fonts to system fonts (Minikin)
This patch explicitly keeps the list of fallback fonts, and creates all system fonts including the fallback list as well. At present, fonts created from assets or directly from files do not have the fallback list present, so that remains to be done. This patch affects only builds with USE_MINIKIN defined; otherwise the fallback font processing in Skia will apply. Change-Id: I6148e06a45a11f53a6bb2f04c8813df4968ea8c8
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