Loading core/java/android/text/ClientFlags.java +7 −0 Original line number Diff line number Diff line Loading @@ -68,4 +68,11 @@ public class ClientFlags { public static boolean fixMisalignedContextMenu() { return TextFlags.isFeatureEnabled(Flags.FLAG_FIX_MISALIGNED_CONTEXT_MENU); } /** * @see Flags#clearFontVariationSettings() */ public static boolean clearFontVariationSettings() { return TextFlags.isFeatureEnabled(Flags.FLAG_CLEAR_FONT_VARIATION_SETTINGS); } } core/java/android/text/TextFlags.java +2 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ public final class TextFlags { Flags.FLAG_FIX_LINE_HEIGHT_FOR_LOCALE, Flags.FLAG_ICU_BIDI_MIGRATION, Flags.FLAG_FIX_MISALIGNED_CONTEXT_MENU, Flags.FLAG_CLEAR_FONT_VARIATION_SETTINGS, }; /** Loading @@ -75,6 +76,7 @@ public final class TextFlags { Flags.fixLineHeightForLocale(), Flags.icuBidiMigration(), Flags.fixMisalignedContextMenu(), Flags.clearFontVariationSettings(), }; /** Loading core/java/android/text/flags/flags.aconfig +11 −0 Original line number Diff line number Diff line Loading @@ -220,3 +220,14 @@ flag { is_fixed_read_only: true bug: "346915432" } flag { name: "clear_font_variation_settings" namespace: "text" description: "The font variation settings must be cleared when the new Typeface is set" bug: "353609778" metadata { purpose: PURPOSE_BUGFIX } } graphics/java/android/graphics/Paint.java +26 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.compat.annotation.UnsupportedAppUsage; import android.graphics.fonts.FontVariationAxis; import android.os.Build; import android.os.LocaleList; import android.text.ClientFlags; import android.text.GraphicsOperations; import android.text.SpannableString; import android.text.SpannedString; Loading Loading @@ -1540,8 +1541,21 @@ public class Paint { * @return typeface */ public Typeface setTypeface(Typeface typeface) { return setTypefaceInternal(typeface, true); } private Typeface setTypefaceInternal(Typeface typeface, boolean clearFontVariationSettings) { final long typefaceNative = typeface == null ? 0 : typeface.native_instance; nSetTypeface(mNativePaint, typefaceNative); if (ClientFlags.clearFontVariationSettings()) { if (clearFontVariationSettings && !Objects.equals(mTypeface, typeface)) { // We cannot call setFontVariationSetting with empty string or null because it calls // setTypeface method. To avoid recursive setTypeface call, manually resetting // mFontVariationSettings. mFontVariationSettings = null; } } mTypeface = typeface; return typeface; } Loading Loading @@ -2037,6 +2051,14 @@ public class Paint { * </li> * </ul> * * Note: This method replaces the Typeface previously set to this instance. * Until API {@link Build.VERSION_CODES.VANILLA_ICE_CREAM}, any caller of * {@link #setTypeface(Typeface)} should call this method with empty settings, then call * {@link #setTypeface(Typeface)}, then call this method with preferred variation settings. * The device API more than {@link Build.VERSION_CODES.VANILLA_ICE_CREAM}, the * {@link #setTypeface(Typeface)} method clears font variation settings. So caller of * {@link #setTypeface(Typeface)} should call this method again for applying variation settings. * * @param fontVariationSettings font variation settings. You can pass null or empty string as * no variation settings. * Loading @@ -2059,8 +2081,8 @@ public class Paint { if (settings == null || settings.length() == 0) { mFontVariationSettings = null; setTypeface(Typeface.createFromTypefaceWithVariation(mTypeface, Collections.emptyList())); setTypefaceInternal(Typeface.createFromTypefaceWithVariation(mTypeface, Collections.emptyList()), false); return true; } Loading @@ -2078,7 +2100,8 @@ public class Paint { return false; } mFontVariationSettings = settings; setTypeface(Typeface.createFromTypefaceWithVariation(targetTypeface, filteredAxes)); setTypefaceInternal(Typeface.createFromTypefaceWithVariation(targetTypeface, filteredAxes), false); return true; } Loading Loading
core/java/android/text/ClientFlags.java +7 −0 Original line number Diff line number Diff line Loading @@ -68,4 +68,11 @@ public class ClientFlags { public static boolean fixMisalignedContextMenu() { return TextFlags.isFeatureEnabled(Flags.FLAG_FIX_MISALIGNED_CONTEXT_MENU); } /** * @see Flags#clearFontVariationSettings() */ public static boolean clearFontVariationSettings() { return TextFlags.isFeatureEnabled(Flags.FLAG_CLEAR_FONT_VARIATION_SETTINGS); } }
core/java/android/text/TextFlags.java +2 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ public final class TextFlags { Flags.FLAG_FIX_LINE_HEIGHT_FOR_LOCALE, Flags.FLAG_ICU_BIDI_MIGRATION, Flags.FLAG_FIX_MISALIGNED_CONTEXT_MENU, Flags.FLAG_CLEAR_FONT_VARIATION_SETTINGS, }; /** Loading @@ -75,6 +76,7 @@ public final class TextFlags { Flags.fixLineHeightForLocale(), Flags.icuBidiMigration(), Flags.fixMisalignedContextMenu(), Flags.clearFontVariationSettings(), }; /** Loading
core/java/android/text/flags/flags.aconfig +11 −0 Original line number Diff line number Diff line Loading @@ -220,3 +220,14 @@ flag { is_fixed_read_only: true bug: "346915432" } flag { name: "clear_font_variation_settings" namespace: "text" description: "The font variation settings must be cleared when the new Typeface is set" bug: "353609778" metadata { purpose: PURPOSE_BUGFIX } }
graphics/java/android/graphics/Paint.java +26 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.compat.annotation.UnsupportedAppUsage; import android.graphics.fonts.FontVariationAxis; import android.os.Build; import android.os.LocaleList; import android.text.ClientFlags; import android.text.GraphicsOperations; import android.text.SpannableString; import android.text.SpannedString; Loading Loading @@ -1540,8 +1541,21 @@ public class Paint { * @return typeface */ public Typeface setTypeface(Typeface typeface) { return setTypefaceInternal(typeface, true); } private Typeface setTypefaceInternal(Typeface typeface, boolean clearFontVariationSettings) { final long typefaceNative = typeface == null ? 0 : typeface.native_instance; nSetTypeface(mNativePaint, typefaceNative); if (ClientFlags.clearFontVariationSettings()) { if (clearFontVariationSettings && !Objects.equals(mTypeface, typeface)) { // We cannot call setFontVariationSetting with empty string or null because it calls // setTypeface method. To avoid recursive setTypeface call, manually resetting // mFontVariationSettings. mFontVariationSettings = null; } } mTypeface = typeface; return typeface; } Loading Loading @@ -2037,6 +2051,14 @@ public class Paint { * </li> * </ul> * * Note: This method replaces the Typeface previously set to this instance. * Until API {@link Build.VERSION_CODES.VANILLA_ICE_CREAM}, any caller of * {@link #setTypeface(Typeface)} should call this method with empty settings, then call * {@link #setTypeface(Typeface)}, then call this method with preferred variation settings. * The device API more than {@link Build.VERSION_CODES.VANILLA_ICE_CREAM}, the * {@link #setTypeface(Typeface)} method clears font variation settings. So caller of * {@link #setTypeface(Typeface)} should call this method again for applying variation settings. * * @param fontVariationSettings font variation settings. You can pass null or empty string as * no variation settings. * Loading @@ -2059,8 +2081,8 @@ public class Paint { if (settings == null || settings.length() == 0) { mFontVariationSettings = null; setTypeface(Typeface.createFromTypefaceWithVariation(mTypeface, Collections.emptyList())); setTypefaceInternal(Typeface.createFromTypefaceWithVariation(mTypeface, Collections.emptyList()), false); return true; } Loading @@ -2078,7 +2100,8 @@ public class Paint { return false; } mFontVariationSettings = settings; setTypeface(Typeface.createFromTypefaceWithVariation(targetTypeface, filteredAxes)); setTypefaceInternal(Typeface.createFromTypefaceWithVariation(targetTypeface, filteredAxes), false); return true; } Loading