summaryrefslogtreecommitdiff
path: root/graphics/java/android
diff options
context:
space:
mode:
author Seigo Nonaka <nona@google.com> 2023-10-23 10:48:42 +0900
committer Seigo Nonaka <nona@google.com> 2023-10-25 10:19:04 +0900
commitde05ca718cbaf1594723894651b31b77264d386d (patch)
tree74d23ce0df60562d5aa68aefe5e9d1747a260dbd /graphics/java/android
parentce80e37f4556c35ba80e1a6fe57585c5aef39eb3 (diff)
Change default value of setElegantTextFlag
As a first step of deprecating UI fonts, make setElegantTextFlag as true by default if the target SDK is set to Android 15 or later.. Bug: 279646685 Test: atest PaintDefaultsTest Change-Id: If8e40c075122cafd2f89ae703bf6a5f07ebc7bd0
Diffstat (limited to 'graphics/java/android')
-rw-r--r--graphics/java/android/graphics/Paint.java54
1 files changed, 49 insertions, 5 deletions
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index 9fde0fd6e6ab..a53f2d12401b 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -27,6 +27,9 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Px;
import android.annotation.Size;
+import android.app.compat.CompatChanges;
+import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.graphics.fonts.FontVariationAxis;
import android.os.Build;
@@ -614,6 +617,7 @@ public class Paint {
mCompatScaling = mInvCompatScaling = 1;
setTextLocales(LocaleList.getAdjustedDefault());
mColor = Color.pack(Color.BLACK);
+ resetElegantTextHeight();
}
/**
@@ -654,7 +658,7 @@ public class Paint {
mBidiFlags = BIDI_DEFAULT_LTR;
setTextLocales(LocaleList.getAdjustedDefault());
- setElegantTextHeight(false);
+ resetElegantTextHeight();
mFontFeatureSettings = null;
mFontVariationSettings = null;
@@ -1735,12 +1739,30 @@ public class Paint {
/**
* Get the elegant metrics flag.
*
+ * From API {@link Build.VERSION_CODES#VANILLA_ICE_CREAM}, the default value will be true by
+ * default if the app has a target SDK of API {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} or
+ * later.
+ *
* @return true if elegant metrics are enabled for text drawing.
*/
public boolean isElegantTextHeight() {
- return nIsElegantTextHeight(mNativePaint);
+ int rawValue = nGetElegantTextHeight(mNativePaint);
+ switch (rawValue) {
+ case ELEGANT_TEXT_HEIGHT_DISABLED:
+ return false;
+ case ELEGANT_TEXT_HEIGHT_ENABLED:
+ return true;
+ case ELEGANT_TEXT_HEIGHT_UNSET:
+ default:
+ return com.android.text.flags.Flags.deprecateUiFonts();
+ }
}
+ // Note: the following three values must be equal to the ones in the JNI file: Paint.cpp
+ private static final int ELEGANT_TEXT_HEIGHT_UNSET = -1;
+ private static final int ELEGANT_TEXT_HEIGHT_ENABLED = 0;
+ private static final int ELEGANT_TEXT_HEIGHT_DISABLED = 1;
+
/**
* Set the paint's elegant height metrics flag. This setting selects font
* variants that have not been compacted to fit Latin-based vertical
@@ -1749,7 +1771,29 @@ public class Paint {
* @param elegant set the paint's elegant metrics flag for drawing text.
*/
public void setElegantTextHeight(boolean elegant) {
- nSetElegantTextHeight(mNativePaint, elegant);
+ nSetElegantTextHeight(mNativePaint,
+ elegant ? ELEGANT_TEXT_HEIGHT_ENABLED : ELEGANT_TEXT_HEIGHT_DISABLED);
+ }
+
+ /**
+ * A change ID for deprecating UI fonts.
+ *
+ * From API {@link Build.VERSION_CODES#VANILLA_ICE_CREAM}, the default value will be true by
+ * default if the app has a target SDK of API {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} or
+ * later.
+ *
+ * @hide
+ */
+ @ChangeId
+ @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
+ public static final long DEPRECATE_UI_FONT = 279646685L;
+
+ private void resetElegantTextHeight() {
+ if (CompatChanges.isChangeEnabled(DEPRECATE_UI_FONT)) {
+ nSetElegantTextHeight(mNativePaint, ELEGANT_TEXT_HEIGHT_UNSET);
+ } else {
+ nSetElegantTextHeight(mNativePaint, ELEGANT_TEXT_HEIGHT_DISABLED);
+ }
}
/**
@@ -3608,9 +3652,9 @@ public class Paint {
@CriticalNative
private static native void nSetStrikeThruText(long paintPtr, boolean strikeThruText);
@CriticalNative
- private static native boolean nIsElegantTextHeight(long paintPtr);
+ private static native int nGetElegantTextHeight(long paintPtr);
@CriticalNative
- private static native void nSetElegantTextHeight(long paintPtr, boolean elegant);
+ private static native void nSetElegantTextHeight(long paintPtr, int elegant);
@CriticalNative
private static native float nGetTextSize(long paintPtr);
@CriticalNative