diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/FontFamily.java | 19 | ||||
-rw-r--r-- | graphics/java/android/graphics/FontListParser.java | 16 | ||||
-rw-r--r-- | graphics/java/android/graphics/Typeface.java | 2 |
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)); } |