Loading core/jni/android/graphics/FontFamily.cpp +14 −5 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ #include "JNIHelp.h" #include <core_jni_helpers.h> #include "SkData.h" #include "SkRefCnt.h" #include "SkTypeface.h" #include "GraphicsJNI.h" #include <ScopedPrimitiveArray.h> Loading Loading @@ -82,6 +84,10 @@ static jboolean FontFamily_addFontWeightStyle(JNIEnv* env, jobject clazz, jlong return true; } static void releaseAsset(const void* ptr, size_t length, void* context) { delete static_cast<Asset*>(context); } static jboolean FontFamily_addFontFromAsset(JNIEnv* env, jobject, jlong familyPtr, jobject jassetMgr, jstring jpath) { NPE_CHECK_RETURN_ZERO(env, jassetMgr); Loading @@ -98,12 +104,15 @@ static jboolean FontFamily_addFontFromAsset(JNIEnv* env, jobject, jlong familyPt return false; } SkStream* stream = new AssetStreamAdaptor(asset, AssetStreamAdaptor::kYes_OwnAsset, AssetStreamAdaptor::kYes_HasMemoryBase); const void* buf = asset->getBuffer(false); if (NULL == buf) { delete asset; return false; } SkAutoTUnref<SkData> data(SkData::NewWithProc(buf, asset->getLength(), releaseAsset, asset)); SkAutoTUnref<SkMemoryStream> stream(new SkMemoryStream(data)); SkTypeface* face = SkTypeface::CreateFromStream(stream); // Note: SkTypeface::CreateFromStream holds its own reference to the stream stream->unref(); if (face == NULL) { ALOGE("addFontFromAsset failed to create font %s", str.c_str()); return false; Loading Loading
core/jni/android/graphics/FontFamily.cpp +14 −5 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ #include "JNIHelp.h" #include <core_jni_helpers.h> #include "SkData.h" #include "SkRefCnt.h" #include "SkTypeface.h" #include "GraphicsJNI.h" #include <ScopedPrimitiveArray.h> Loading Loading @@ -82,6 +84,10 @@ static jboolean FontFamily_addFontWeightStyle(JNIEnv* env, jobject clazz, jlong return true; } static void releaseAsset(const void* ptr, size_t length, void* context) { delete static_cast<Asset*>(context); } static jboolean FontFamily_addFontFromAsset(JNIEnv* env, jobject, jlong familyPtr, jobject jassetMgr, jstring jpath) { NPE_CHECK_RETURN_ZERO(env, jassetMgr); Loading @@ -98,12 +104,15 @@ static jboolean FontFamily_addFontFromAsset(JNIEnv* env, jobject, jlong familyPt return false; } SkStream* stream = new AssetStreamAdaptor(asset, AssetStreamAdaptor::kYes_OwnAsset, AssetStreamAdaptor::kYes_HasMemoryBase); const void* buf = asset->getBuffer(false); if (NULL == buf) { delete asset; return false; } SkAutoTUnref<SkData> data(SkData::NewWithProc(buf, asset->getLength(), releaseAsset, asset)); SkAutoTUnref<SkMemoryStream> stream(new SkMemoryStream(data)); SkTypeface* face = SkTypeface::CreateFromStream(stream); // Note: SkTypeface::CreateFromStream holds its own reference to the stream stream->unref(); if (face == NULL) { ALOGE("addFontFromAsset failed to create font %s", str.c_str()); return false; Loading