summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-05-27 16:33:11 -0700
committerRaph Levien <raph@google.com>2014-05-29 14:21:24 -0700
commitf9e3d311275c37fe5f2562993687a1627780a6d0 (patch)
tree57c3f63db32ee0dcac31cda4a2739501d7585c97 /graphics
parentdc925857fcd6a9097d6a1d8b85fca231e8d102fc (diff)
downloadframeworks_base-f9e3d311275c37fe5f2562993687a1627780a6d0.zip
frameworks_base-f9e3d311275c37fe5f2562993687a1627780a6d0.tar.gz
frameworks_base-f9e3d311275c37fe5f2562993687a1627780a6d0.tar.bz2
Language and variant selection for Minikin
This is the frameworks/base side of what's needed to support language selection (especially Han unification, but also compact/elegant selection for scripts that require more vertical space). This is part of the fix for bug 15179652 "Japanese font isn't shown on LMP". Change-Id: I8f0f3aa9a1915659f8d0b590cf1c56529356049a
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/FontFamily.java19
-rw-r--r--graphics/java/android/graphics/FontListParser.java16
-rw-r--r--graphics/java/android/graphics/Typeface.java2
3 files changed, 31 insertions, 6 deletions
diff --git a/graphics/java/android/graphics/FontFamily.java b/graphics/java/android/graphics/FontFamily.java
index 210ea86b..6802b9a 100644
--- a/graphics/java/android/graphics/FontFamily.java
+++ b/graphics/java/android/graphics/FontFamily.java
@@ -30,9 +30,22 @@ public class FontFamily {
public long mNativePtr;
public FontFamily() {
- mNativePtr = nCreateFamily();
+ mNativePtr = nCreateFamily(null, 0);
if (mNativePtr == 0) {
- throw new RuntimeException();
+ throw new IllegalStateException("error creating native FontFamily");
+ }
+ }
+
+ public FontFamily(String lang, String variant) {
+ int varEnum = 0;
+ if ("compact".equals(variant)) {
+ varEnum = 1;
+ } else if ("elegant".equals(variant)) {
+ varEnum = 2;
+ }
+ mNativePtr = nCreateFamily(lang, varEnum);
+ if (mNativePtr == 0) {
+ throw new IllegalStateException("error creating native FontFamily");
}
}
@@ -49,7 +62,7 @@ public class FontFamily {
return nAddFont(mNativePtr, path.getAbsolutePath());
}
- static native long nCreateFamily();
+ static native long nCreateFamily(String lang, int variant);
static native void nUnrefFamily(long nativePtr);
static native boolean nAddFont(long nativeFamily, String path);
}
diff --git a/graphics/java/android/graphics/FontListParser.java b/graphics/java/android/graphics/FontListParser.java
index f304f4e..a863a06 100644
--- a/graphics/java/android/graphics/FontListParser.java
+++ b/graphics/java/android/graphics/FontListParser.java
@@ -34,14 +34,18 @@ import java.util.List;
public class FontListParser {
public static class Family {
- public Family(List<String> names, List<String> fontFiles) {
+ public Family(List<String> names, List<String> fontFiles, String lang, String variant) {
this.names = names;
this.fontFiles = fontFiles;
+ this.lang = lang;
+ this.variant = variant;
}
public List<String> names;
// todo: need attributes for font files
public List<String> fontFiles;
+ public String lang;
+ public String variant;
}
/* Parse fallback list (no names) */
@@ -75,6 +79,8 @@ public class FontListParser {
throws XmlPullParserException, IOException {
List<String> names = null;
List<String> fontFiles = new ArrayList<String>();
+ String lang = null;
+ String variant = null;
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) continue;
String tag = parser.getName();
@@ -82,6 +88,12 @@ public class FontListParser {
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) continue;
if (parser.getName().equals("file")) {
+ if (lang == null) {
+ lang = parser.getAttributeValue(null, "lang");
+ }
+ if (variant == null) {
+ variant = parser.getAttributeValue(null, "variant");
+ }
String filename = parser.nextText();
String fullFilename = "/system/fonts/" + filename;
fontFiles.add(fullFilename);
@@ -98,7 +110,7 @@ public class FontListParser {
}
}
}
- return new Family(names, fontFiles);
+ return new Family(names, fontFiles, lang, variant);
}
private static void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index b7613fb..2b07c3f 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -245,7 +245,7 @@ public class Typeface {
private static FontFamily makeFamilyFromParsed(FontListParser.Family family) {
// TODO: expand to handle attributes like lang and variant
- FontFamily fontFamily = new FontFamily();
+ FontFamily fontFamily = new FontFamily(family.lang, family.variant);
for (String fontFile : family.fontFiles) {
fontFamily.addFont(new File(fontFile));
}