diff options
| -rw-r--r-- | graphics/java/android/graphics/Paint.java | 17 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Typeface.java | 11 | ||||
| -rw-r--r-- | libs/hwui/jni/Typeface.cpp | 6 |
3 files changed, 32 insertions, 2 deletions
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 2e885145819c..50c95a9fa882 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -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; } diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java index 889a778556b7..874b847c709c 100644 --- a/graphics/java/android/graphics/Typeface.java +++ b/graphics/java/android/graphics/Typeface.java @@ -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; } @@ -1698,6 +1706,9 @@ public class Typeface { private static native int nativeGetWeight(long nativePtr); @CriticalNative + private static native boolean nativeIsVariationInstance(long nativePtr); + + @CriticalNative private static native long nativeGetReleaseFunc(); private static native void nativeRegisterGenericFamily(String str, long nativePtr); diff --git a/libs/hwui/jni/Typeface.cpp b/libs/hwui/jni/Typeface.cpp index 0f458dde8b07..707577d6d075 100644 --- a/libs/hwui/jni/Typeface.cpp +++ b/libs/hwui/jni/Typeface.cpp @@ -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}, |