Merge change 1478 into donut
* changes: Fixes #1847219. Add a new API to load fonts from arbitrary files: Typeface.createFromFile(String/File).
This commit is contained in:
@@ -53318,6 +53318,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"
|
||||
|
||||
@@ -133,6 +133,14 @@ static SkTypeface* Typeface_createFromAsset(JNIEnv* env, jobject,
|
||||
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 @@ static JNINativeMethod gTypefaceMethods[] = {
|
||||
{ "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 @@ int register_android_graphics_Typeface(JNIEnv* env)
|
||||
gTypefaceMethods,
|
||||
SK_ARRAY_COUNT(gTypefaceMethods));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user