Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8098f49d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

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

+16 −8
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ static void Font_Builder_addAxis(CRITICAL_JNI_PARAMS_COMMA jlong builderPtr, jin

// Regular JNI
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);
    std::unique_ptr<NativeFontBuilder> builder(toBuilder(builderPtr));
    const void* fontPtr = env->GetDirectBufferAddress(buffer);
@@ -94,6 +95,7 @@ static jlong Font_Builder_build(JNIEnv* env, jobject clazz, jlong builderPtr, jo
        return 0;
    }
    ScopedUtfChars fontPath(env, filePath);
    ScopedUtfChars langTagStr(env, langTags);
    jobject fontRef = MakeGlobalRefOrDie(env, buffer);
    sk_sp<SkData> data(SkData::MakeWithProc(fontPtr, fontSize,
            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.");
        return 0;
    }
    std::shared_ptr<minikin::Font> font = minikin::Font::Builder(minikinFont).setWeight(weight)
                    .setSlant(static_cast<minikin::FontStyle::Slant>(italic)).build();
    uint32_t localeListId = minikin::registerLocaleList(langTagStr.c_str());
    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)));
}

@@ -304,7 +311,8 @@ static jint FontFileUtil_isPostScriptType1Font(JNIEnv* env, jobject, jobject buf
static const JNINativeMethod gFontBuilderMethods[] = {
        {"nInitBuilder", "()J", (void*)Font_Builder_initBuilder},
        {"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",
         (void*)Font_Builder_build},
        {"nClone", "(JJIZI)J", (void*)Font_Builder_clone},
        {"nGetReleaseNativeFont", "()J", (void*)Font_Builder_getReleaseNativeFont},
};