am 3e3439d: Merge change 1478 into donut

Merge commit '3e3439d5ba0cf5eda060c4991219c32af917fc5b'

* commit '3e3439d5ba0cf5eda060c4991219c32af917fc5b':
  Fixes #1847219. Add a new API to load fonts from arbitrary files: Typeface.createFromFile(String/File).
diff --git a/api/current.xml b/api/current.xml
index 09f1b85..141a498 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -55625,6 +55625,32 @@
 <parameter name="path" type="java.lang.String">
 </parameter>
 </method>
+<method name="createFromFile"
+ return="android.graphics.Typeface"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="path" type="java.io.File">
+</parameter>
+</method>
+<method name="createFromFile"
+ return="android.graphics.Typeface"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="path" type="java.lang.String">
+</parameter>
+</method>
 <method name="defaultFromStyle"
  return="android.graphics.Typeface"
  abstract="false"
diff --git a/core/jni/android/graphics/Typeface.cpp b/core/jni/android/graphics/Typeface.cpp
index e951431..4f23f65 100644
--- a/core/jni/android/graphics/Typeface.cpp
+++ b/core/jni/android/graphics/Typeface.cpp
@@ -133,6 +133,14 @@
     return SkTypeface::CreateFromStream(new AssetStream(asset, true));
 }
 
+static SkTypeface* Typeface_createFromFile(JNIEnv* env, jobject, jstring jpath) {
+    NPE_CHECK_RETURN_ZERO(env, jpath);
+
+    AutoJavaStringToUTF8 str(env, jpath);
+
+    return SkTypeface::CreateFromFile(str.c_str());
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 static JNINativeMethod gTypefaceMethods[] = {
@@ -140,9 +148,10 @@
     { "nativeCreateFromTypeface", "(II)I", (void*)Typeface_createFromTypeface },
     { "nativeUnref",              "(I)V",  (void*)Typeface_unref },
     { "nativeGetStyle",           "(I)I",  (void*)Typeface_getStyle },
-    { "nativeCreateFromAsset",
-                        "(Landroid/content/res/AssetManager;Ljava/lang/String;)I",
-                                            (void*)Typeface_createFromAsset }
+    { "nativeCreateFromAsset",    "(Landroid/content/res/AssetManager;Ljava/lang/String;)I",
+                                           (void*)Typeface_createFromAsset },
+    { "nativeCreateFromFile",     "(Ljava/lang/String)I",
+                                           (void*)Typeface_createFromFile }
 };
 
 int register_android_graphics_Typeface(JNIEnv* env);
@@ -153,4 +162,3 @@
                                                        gTypefaceMethods,
                                                        SK_ARRAY_COUNT(gTypefaceMethods));
 }
-
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 @@
 
 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 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 @@
     }
 
     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);
 }