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

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

Merge "Register generic font families in Zygote"

parents 84f970c8 d06aa0ab
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -20,11 +20,13 @@
#include "FontUtils.h"
#include "GraphicsJNI.h"
#include <nativehelper/ScopedPrimitiveArray.h>
#include <nativehelper/ScopedUtfChars.h>
#include "SkTypeface.h"
#include <android_runtime/android_util_AssetManager.h>
#include <androidfw/AssetManager.h>
#include <hwui/Typeface.h>
#include <minikin/FontFamily.h>
#include <minikin/SystemFonts.h>

using namespace android;

@@ -108,6 +110,7 @@ static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArr
// CriticalNative
static void Typeface_setDefault(jlong faceHandle) {
    Typeface::setDefault(toTypeface(faceHandle));
    minikin::SystemFonts::registerDefault(toTypeface(faceHandle)->fFontCollection);
}

static jobject Typeface_getSupportedAxes(JNIEnv *env, jobject, jlong faceHandle) {
@@ -128,6 +131,12 @@ static jobject Typeface_getSupportedAxes(JNIEnv *env, jobject, jlong faceHandle)
    return result;
}

static void Typeface_registerGenericFamily(JNIEnv *env, jobject, jstring familyName, jlong ptr) {
    ScopedUtfChars familyNameChars(env, familyName);
    minikin::SystemFonts::registerFallback(familyNameChars.c_str(),
                                           toTypeface(ptr)->fFontCollection);
}

///////////////////////////////////////////////////////////////////////////////

static const JNINativeMethod gTypefaceMethods[] = {
@@ -144,6 +153,8 @@ static const JNINativeMethod gTypefaceMethods[] = {
                                           (void*)Typeface_createFromArray },
    { "nativeSetDefault",         "(J)V",   (void*)Typeface_setDefault },
    { "nativeGetSupportedAxes",   "(J)[I",  (void*)Typeface_getSupportedAxes },
    { "nativeRegisterGenericFamily", "(Ljava/lang/String;J)V",
          (void*)Typeface_registerGenericFamily },
};

int register_android_graphics_Typeface(JNIEnv* env)
+18 −0
Original line number Diff line number Diff line
@@ -1115,6 +1115,13 @@ public class Typeface {
        }
    }

    private static void registerGenericFamilyNative(@NonNull String familyName,
            @Nullable Typeface typeface) {
        if (typeface != null) {
            nativeRegisterGenericFamily(familyName, typeface.native_instance);
        }
    }

    static {
        final HashMap<String, Typeface> systemFontMap = new HashMap<>();
        initSystemDefaultTypefaces(systemFontMap, SystemFonts.getRawSystemFallbackMap(),
@@ -1140,6 +1147,15 @@ public class Typeface {
            create((String) null, Typeface.BOLD_ITALIC),
        };

        // A list of generic families to be registered in native.
        // https://www.w3.org/TR/css-fonts-4/#generic-font-families
        String[] genericFamilies = {
            "serif", "sans-serif", "cursive", "fantasy", "monospace", "system-ui"
        };

        for (String genericFamily : genericFamilies) {
            registerGenericFamilyNative(genericFamily, systemFontMap.get(genericFamily));
        }
    }

    @Override
@@ -1202,4 +1218,6 @@ public class Typeface {

    @CriticalNative
    private static native long nativeGetReleaseFunc();

    private static native void nativeRegisterGenericFamily(String str, long nativePtr);
}