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

Commit b07f334c authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Android (Google) Code Review
Browse files

Merge "Revert "Clear variation settings when setTypeface is called"" into main

parents 81489831 6b77d9c1
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -68,11 +68,4 @@ 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);
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ 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,
    };

    /**
@@ -76,7 +75,6 @@ public final class TextFlags {
            Flags.fixLineHeightForLocale(),
            Flags.icuBidiMigration(),
            Flags.fixMisalignedContextMenu(),
            Flags.clearFontVariationSettings(),
    };

    /**
+3 −26
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ 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;
@@ -1541,21 +1540,8 @@ 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;
    }
@@ -2051,14 +2037,6 @@ 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.
     *
@@ -2081,8 +2059,8 @@ public class Paint {

        if (settings == null || settings.length() == 0) {
            mFontVariationSettings = null;
            setTypefaceInternal(Typeface.createFromTypefaceWithVariation(mTypeface,
                      Collections.emptyList()), false);
            setTypeface(Typeface.createFromTypefaceWithVariation(mTypeface,
                      Collections.emptyList()));
            return true;
        }

@@ -2100,8 +2078,7 @@ public class Paint {
            return false;
        }
        mFontVariationSettings = settings;
        setTypefaceInternal(Typeface.createFromTypefaceWithVariation(targetTypeface, filteredAxes),
                false);
        setTypeface(Typeface.createFromTypefaceWithVariation(targetTypeface, filteredAxes));
        return true;
    }