diff options
author | Romain Guy <romainguy@android.com> | 2009-05-12 13:22:18 -0700 |
---|---|---|
committer | Romain Guy <romainguy@android.com> | 2009-05-12 13:22:18 -0700 |
commit | a87a132ebf1c2dd733cf52feff6e44525257c961 (patch) | |
tree | 683a3803f2b3704db73a56a769fcd0f19f912b52 /graphics | |
parent | da33d0d139531ff184a1a339b734de00f1cc0743 (diff) | |
download | frameworks_base-a87a132ebf1c2dd733cf52feff6e44525257c961.zip frameworks_base-a87a132ebf1c2dd733cf52feff6e44525257c961.tar.gz frameworks_base-a87a132ebf1c2dd733cf52feff6e44525257c961.tar.bz2 |
Fixes #1847219. Add a new API to load fonts from arbitrary files: Typeface.createFromFile(String/File).
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/Typeface.java | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java index c69c92c..e40e84a 100644 --- a/graphics/java/android/graphics/Typeface.java +++ b/graphics/java/android/graphics/Typeface.java @@ -18,6 +18,8 @@ package android.graphics; import android.content.res.AssetManager; +import java.io.File; + /** * The Typeface class specifies the typeface and intrinsic style of a font. * This is used in the paint, along with optionally Paint settings like @@ -118,7 +120,27 @@ public class Typeface { public static Typeface createFromAsset(AssetManager mgr, String path) { return new Typeface(nativeCreateFromAsset(mgr, path)); } - + + /** + * Create a new typeface from the specified font file. + * + * @param path The path to the font data. + * @return The new typeface. + */ + public static Typeface createFromFile(File path) { + return new Typeface(nativeCreateFromFile(path.getAbsolutePath())); + } + + /** + * Create a new typeface from the specified font file. + * + * @param path The full path to the font data. + * @return The new typeface. + */ + public static Typeface createFromFile(String path) { + return new Typeface(nativeCreateFromFile(path)); + } + // don't allow clients to call this directly private Typeface(int ni) { native_instance = ni; @@ -140,14 +162,14 @@ public class Typeface { } protected void finalize() throws Throwable { + super.finalize(); nativeUnref(native_instance); } private static native int nativeCreate(String familyName, int style); - private static native int nativeCreateFromTypeface(int native_instance, - int style); + private static native int nativeCreateFromTypeface(int native_instance, int style); private static native void nativeUnref(int native_instance); private static native int nativeGetStyle(int native_instance); - private static native int nativeCreateFromAsset(AssetManager mgr, - String path); + private static native int nativeCreateFromAsset(AssetManager mgr, String path); + private static native int nativeCreateFromFile(String path); } |