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

Commit af77018f authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Revise method comment on setFontVariationSettings" into oc-dev...

Merge "Merge "Revise method comment on setFontVariationSettings" into oc-dev am: e6746726" into oc-dev-plus-aosp
parents ce126185 06e3d60d
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.fonts.FontVariationAxis;
import android.graphics.fonts.FontVariationAxis.InvalidFormatException;
import android.icu.text.DecimalFormatSymbols;
import android.os.AsyncTask;
import android.os.Build.VERSION_CODES;
@@ -3886,26 +3887,43 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     * are invalid. If a specified axis name is not defined in the font, the settings will be
     * ignored.
     *
     * <p>
     * Examples,
     * <ul>
     * <li>Set font width to 150.
     * <pre>
     * <code>
     *   TextView textView = (TextView) findViewById(R.id.textView);
     *   textView.setFontVariationSettings("'wdth' 150");
     * </code>
     * </pre>
     * </li>
     *
     * <li>Set the font slant to 20 degrees and ask for italic style.
     * <pre>
     *   textView.setFontVariationSettings("'wdth' 1.0");
     *   textView.setFontVariationSettings("'AX  ' 1.8, 'FB  ' 2.0");
     * <code>
     *   TextView textView = (TextView) findViewById(R.id.textView);
     *   textView.setFontVariationSettings("'slnt' 20, 'ital' 1");
     * </code>
     * </pre>
     * </p>
     * </li>
     * </ul>
     *
     * @param fontVariationSettings font variation settings. You can pass null or empty string as
     *                              no variation settings.
     *
     * @return true if the given settings is effective to at least one font file underlying this
     *         TextView. This function also returns true for empty settings string. Otherwise
     *         returns false.
     *
     * @throws FontVariationAxis.InvalidFormatException
     *         If given string is not a valid font variation settings format.
     * @throws InvalidFormatException If given string is not a valid font variation settings
     *                                format.
     *
     * @see #getFontVariationSettings()
     * @see Paint#getFontVariationSettings() Paint.getFontVariationSettings()
     * @see FontVariationAxis
     */
    public boolean setFontVariationSettings(@Nullable String fontVariationSettings)
            throws FontVariationAxis.InvalidFormatException {
            throws InvalidFormatException {
        final String existingSettings = mTextPaint.getFontVariationSettings();
        if (fontVariationSettings == existingSettings
                || (fontVariationSettings != null
+39 −14
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.NonNull;
import android.annotation.Size;
import android.graphics.FontListParser;
import android.graphics.fonts.FontVariationAxis;
import android.graphics.fonts.FontVariationAxis.InvalidFormatException;
import android.os.LocaleList;
import android.text.FontConfig;
import android.text.GraphicsOperations;
@@ -1539,25 +1540,49 @@ public class Paint {
    }

    /**
     * Set font variation settings.
     * Sets TrueType or OpenType font variation settings. The settings string is constructed from
     * multiple pairs of axis tag and style values. The axis tag must contain four ASCII characters
     * and must be wrapped with single quotes (U+0027) or double quotes (U+0022). Axis strings that
     * are longer or shorter than four characters, or contain characters outside of U+0020..U+007E
     * are invalid. If a specified axis name is not defined in the font, the settings will be
     * ignored.
     *
     * Examples,
     * <ul>
     * <li>Set font width to 150.
     * <pre>
     * <code>
     *   Paint paint = new Paint();
     *   paint.setFontVariationSettings("'wdth' 150");
     * </code>
     * </pre>
     * </li>
     *
     * <li>Set the font slant to 20 degrees and ask for italic style.
     * <pre>
     * <code>
     *   Paint paint = new Paint();
     *   paint.setFontVariationSettings("'slnt' 20, 'ital' 1");
     * </code>
     * </pre>
     * </li>
     * </ul>
     *
     * @param fontVariationSettings font variation settings. You can pass null or empty string as
     *                              no variation settings.
     *
     * This function does nothing if none of the settings is applicable to underlying font files.
     *
     * @param settings font variation settings, e.g. "'wdth' 300, 'wght' 1.8"
     *
     * @see #getFontVariationSettings()
     *
     * @param settings the font variation settings. You can pass null or empty string as no
     *                 variation settings.
     * @return true if the given settings is effective to at least one font file underlying this
     *         typeface. This function also returns true for empty settings string. Otherwise
     *         returns false
     * @throws FontVariationAxis.InvalidFormatException
     *         If given string is not a valid font variation settings format.
     *
     * @throws InvalidFormatException If given string is not a valid font variation settings format.
     *
     * @see #getFontVariationSettings()
     * @see FontVariationAxis
     */
    public boolean setFontVariationSettings(String settings)
            throws FontVariationAxis.InvalidFormatException {
        settings = TextUtils.nullIfEmpty(settings);
    public boolean setFontVariationSettings(String fontVariationSettings)
            throws InvalidFormatException {
        final String settings = TextUtils.nullIfEmpty(fontVariationSettings);
        if (settings == mFontVariationSettings
                || (settings != null && settings.equals(mFontVariationSettings))) {
            return true;