Merge "Save locale list to Font instance" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-02-05 02:23:11 +00:00
committed by Android (Google) Code Review
2 changed files with 20 additions and 11 deletions

View File

@@ -486,7 +486,8 @@ public final class Font {
long ptr; long ptr;
int fontIdentifier; int fontIdentifier;
if (mFont == null) { if (mFont == null) {
ptr = nBuild(builderPtr, readonlyBuffer, filePath, mWeight, italic, mTtcIndex); ptr = nBuild(builderPtr, readonlyBuffer, filePath, mLocaleList, mWeight, italic,
mTtcIndex);
long fontBufferPtr = nGetFontBufferAddress(ptr); long fontBufferPtr = nGetFontBufferAddress(ptr);
synchronized (SOURCE_ID_LOCK) { synchronized (SOURCE_ID_LOCK) {
long id = FONT_SOURCE_ID_MAP.get(fontBufferPtr, -1); long id = FONT_SOURCE_ID_MAP.get(fontBufferPtr, -1);
@@ -513,8 +514,8 @@ public final class Font {
@CriticalNative @CriticalNative
private static native void nAddAxis(long builderPtr, int tag, float value); private static native void nAddAxis(long builderPtr, int tag, float value);
private static native long nBuild( private static native long nBuild(
long builderPtr, @NonNull ByteBuffer buffer, @NonNull String filePath, int weight, long builderPtr, @NonNull ByteBuffer buffer, @NonNull String filePath,
boolean italic, int ttcIndex); @NonNull String localeList, int weight, boolean italic, int ttcIndex);
@CriticalNative @CriticalNative
private static native long nGetReleaseNativeFont(); private static native long nGetReleaseNativeFont();

View File

@@ -79,7 +79,8 @@ static void Font_Builder_addAxis(CRITICAL_JNI_PARAMS_COMMA jlong builderPtr, jin
// Regular JNI // Regular JNI
static jlong Font_Builder_build(JNIEnv* env, jobject clazz, jlong builderPtr, jobject buffer, static jlong Font_Builder_build(JNIEnv* env, jobject clazz, jlong builderPtr, jobject buffer,
jstring filePath, jint weight, jboolean italic, jint ttcIndex) { jstring filePath, jstring langTags, jint weight, jboolean italic,
jint ttcIndex) {
NPE_CHECK_RETURN_ZERO(env, buffer); NPE_CHECK_RETURN_ZERO(env, buffer);
std::unique_ptr<NativeFontBuilder> builder(toBuilder(builderPtr)); std::unique_ptr<NativeFontBuilder> builder(toBuilder(builderPtr));
const void* fontPtr = env->GetDirectBufferAddress(buffer); const void* fontPtr = env->GetDirectBufferAddress(buffer);
@@ -94,6 +95,7 @@ static jlong Font_Builder_build(JNIEnv* env, jobject clazz, jlong builderPtr, jo
return 0; return 0;
} }
ScopedUtfChars fontPath(env, filePath); ScopedUtfChars fontPath(env, filePath);
ScopedUtfChars langTagStr(env, langTags);
jobject fontRef = MakeGlobalRefOrDie(env, buffer); jobject fontRef = MakeGlobalRefOrDie(env, buffer);
sk_sp<SkData> data(SkData::MakeWithProc(fontPtr, fontSize, sk_sp<SkData> data(SkData::MakeWithProc(fontPtr, fontSize,
release_global_ref, reinterpret_cast<void*>(fontRef))); release_global_ref, reinterpret_cast<void*>(fontRef)));
@@ -105,8 +107,13 @@ static jlong Font_Builder_build(JNIEnv* env, jobject clazz, jlong builderPtr, jo
"Failed to create internal object. maybe invalid font data."); "Failed to create internal object. maybe invalid font data.");
return 0; return 0;
} }
std::shared_ptr<minikin::Font> font = minikin::Font::Builder(minikinFont).setWeight(weight) uint32_t localeListId = minikin::registerLocaleList(langTagStr.c_str());
.setSlant(static_cast<minikin::FontStyle::Slant>(italic)).build(); std::shared_ptr<minikin::Font> font =
minikin::Font::Builder(minikinFont)
.setWeight(weight)
.setSlant(static_cast<minikin::FontStyle::Slant>(italic))
.setLocaleListId(localeListId)
.build();
return reinterpret_cast<jlong>(new FontWrapper(std::move(font))); return reinterpret_cast<jlong>(new FontWrapper(std::move(font)));
} }
@@ -302,11 +309,12 @@ static jint FontFileUtil_isPostScriptType1Font(JNIEnv* env, jobject, jobject buf
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static const JNINativeMethod gFontBuilderMethods[] = { static const JNINativeMethod gFontBuilderMethods[] = {
{ "nInitBuilder", "()J", (void*) Font_Builder_initBuilder }, {"nInitBuilder", "()J", (void*)Font_Builder_initBuilder},
{ "nAddAxis", "(JIF)V", (void*) Font_Builder_addAxis }, {"nAddAxis", "(JIF)V", (void*)Font_Builder_addAxis},
{ "nBuild", "(JLjava/nio/ByteBuffer;Ljava/lang/String;IZI)J", (void*) Font_Builder_build }, {"nBuild", "(JLjava/nio/ByteBuffer;Ljava/lang/String;Ljava/lang/String;IZI)J",
{ "nClone", "(JJIZI)J", (void*) Font_Builder_clone }, (void*)Font_Builder_build},
{ "nGetReleaseNativeFont", "()J", (void*) Font_Builder_getReleaseNativeFont }, {"nClone", "(JJIZI)J", (void*)Font_Builder_clone},
{"nGetReleaseNativeFont", "()J", (void*)Font_Builder_getReleaseNativeFont},
}; };
static const JNINativeMethod gFontMethods[] = { static const JNINativeMethod gFontMethods[] = {