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

Commit 99bc7977 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add warning message if developer depends on undocumented behavior" into main

parents ed17baad 596db6aa
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -1586,6 +1586,18 @@ public class Paint {
     * @return         typeface
     */
    public Typeface setTypeface(Typeface typeface) {
        if (Flags.typefaceRedesignReadonly() && typeface != null
                && typeface.isVariationInstance()) {
            Log.w(TAG, "Attempting to set a Typeface on a Paint object that was previously "
                    + "configured with setFontVariationSettings(). This is no longer supported as "
                    + "of Target SDK " + Build.VERSION_CODES.BAKLAVA + ". To apply font"
                    + " variations, call setFontVariationSettings() directly on the Paint object"
                    + " instead.");
        }
        return setTypefaceWithoutWarning(typeface);
    }

    private Typeface setTypefaceWithoutWarning(Typeface typeface) {
        final long typefaceNative = typeface == null ? 0 : typeface.native_instance;
        nSetTypeface(mNativePaint, typefaceNative);
        mTypeface = typeface;
@@ -2183,7 +2195,7 @@ public class Paint {

        if (settings == null || settings.length() == 0) {
            mFontVariationSettings = null;
            setTypeface(Typeface.createFromTypefaceWithVariation(mTypeface,
            setTypefaceWithoutWarning(Typeface.createFromTypefaceWithVariation(mTypeface,
                      Collections.emptyList()));
            return true;
        }
@@ -2202,7 +2214,8 @@ public class Paint {
            return false;
        }
        mFontVariationSettings = settings;
        setTypeface(Typeface.createFromTypefaceWithVariation(targetTypeface, filteredAxes));
        setTypefaceWithoutWarning(
                Typeface.createFromTypefaceWithVariation(targetTypeface, filteredAxes));
        return true;
    }

+11 −0
Original line number Diff line number Diff line
@@ -237,6 +237,8 @@ public class Typeface {

    private @IntRange(from = 0, to = FontStyle.FONT_WEIGHT_MAX) final int mWeight;

    private boolean mIsVariationInstance;

    // Value for weight and italic. Indicates the value is resolved by font metadata.
    // Must be the same as the C++ constant in core/jni/android/graphics/FontFamily.cpp
    /** @hide */
@@ -279,6 +281,11 @@ public class Typeface {
        return mWeight;
    }

    /** @hide */
    public boolean isVariationInstance() {
        return mIsVariationInstance;
    }

    /** Returns the typeface's intrinsic style attributes */
    public @Style int getStyle() {
        return mStyle;
@@ -1280,6 +1287,7 @@ public class Typeface {
        mCleaner = sRegistry.registerNativeAllocation(this, native_instance);
        mStyle = nativeGetStyle(ni);
        mWeight = nativeGetWeight(ni);
        mIsVariationInstance = nativeIsVariationInstance(ni);
        mSystemFontFamilyName = systemFontFamilyName;
        mDerivedFrom = derivedFrom;
    }
@@ -1697,6 +1705,9 @@ public class Typeface {
    @CriticalNative
    private static native int  nativeGetWeight(long nativePtr);

    @CriticalNative
    private static native boolean nativeIsVariationInstance(long nativePtr);

    @CriticalNative
    private static native long nativeGetReleaseFunc();

+6 −0
Original line number Diff line number Diff line
@@ -107,6 +107,11 @@ static jint Typeface_getWeight(CRITICAL_JNI_PARAMS_COMMA jlong faceHandle) {
    return toTypeface(faceHandle)->fStyle.weight();
}

// Critical Native
static jboolean Typeface_isVariationInstance(CRITICAL_JNI_PARAMS_COMMA jlong faceHandle) {
    return toTypeface(faceHandle)->fIsVariationInstance;
}

static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArray,
                                      jlong fallbackPtr, int weight, int italic) {
    ScopedLongArrayRO families(env, familyArray);
@@ -398,6 +403,7 @@ static const JNINativeMethod gTypefaceMethods[] = {
        {"nativeGetReleaseFunc", "()J", (void*)Typeface_getReleaseFunc},
        {"nativeGetStyle", "(J)I", (void*)Typeface_getStyle},
        {"nativeGetWeight", "(J)I", (void*)Typeface_getWeight},
        {"nativeIsVariationInstance", "(J)Z", (void*)Typeface_isVariationInstance},
        {"nativeCreateFromArray", "([JJII)J", (void*)Typeface_createFromArray},
        {"nativeSetDefault", "(J)V", (void*)Typeface_setDefault},
        {"nativeGetSupportedAxes", "(J)[I", (void*)Typeface_getSupportedAxes},