summaryrefslogtreecommitdiff
path: root/graphics/java
diff options
context:
space:
mode:
author Seigo Nonaka <nona@google.com> 2024-12-20 11:35:45 +0900
committer Seigo Nonaka <nona@google.com> 2024-12-20 13:29:03 +0900
commit596db6aafc9bb0ea270d6e38d854f9867c9d4ae7 (patch)
tree0ba3f374df321b8fab64f160806819c7dbf9f5e0 /graphics/java
parent042f578681e6b75c2c390f5848fb9395cb507b67 (diff)
Add warning message if developer depends on undocumented behavior
Bug: 371894731 Test: Manually done Flag: com.android.text.flags.typeface_redesign_readonly Change-Id: I375e8dd6bf5e04be4819c2e9146473cb02df409a
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/Paint.java17
-rw-r--r--graphics/java/android/graphics/Typeface.java11
2 files changed, 26 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);