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

Commit fb72b6b1 authored by Behdad Esfahbod's avatar Behdad Esfahbod Committed by Android (Google) Code Review
Browse files

Merge "Add fontFeatureSettings to TextView and attrs" into lmp-dev

parents 166e5afa e9ad3931
Loading
Loading
Loading
Loading
+52 −1
Original line number Original line Diff line number Diff line
@@ -658,6 +658,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        float dx = 0, dy = 0, r = 0;
        float dx = 0, dy = 0, r = 0;
        boolean elegant = false;
        boolean elegant = false;
        float letterSpacing = 0;
        float letterSpacing = 0;
        String fontFeatureSettings = null;


        final Resources.Theme theme = context.getTheme();
        final Resources.Theme theme = context.getTheme();


@@ -742,6 +743,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                case com.android.internal.R.styleable.TextAppearance_letterSpacing:
                case com.android.internal.R.styleable.TextAppearance_letterSpacing:
                    letterSpacing = appearance.getFloat(attr, 0);
                    letterSpacing = appearance.getFloat(attr, 0);
                    break;
                    break;

                case com.android.internal.R.styleable.TextAppearance_fontFeatureSettings:
                    fontFeatureSettings = appearance.getString(attr);
                    break;
                }
                }
            }
            }


@@ -1087,6 +1092,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            case com.android.internal.R.styleable.TextView_letterSpacing:
            case com.android.internal.R.styleable.TextView_letterSpacing:
                letterSpacing = a.getFloat(attr, 0);
                letterSpacing = a.getFloat(attr, 0);
                break;
                break;

            case com.android.internal.R.styleable.TextView_fontFeatureSettings:
                fontFeatureSettings = a.getString(attr);
                break;
            }
            }
        }
        }
        a.recycle();
        a.recycle();
@@ -1269,6 +1278,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        setRawTextSize(textSize);
        setRawTextSize(textSize);
        setElegantTextHeight(elegant);
        setElegantTextHeight(elegant);
        setLetterSpacing(letterSpacing);
        setLetterSpacing(letterSpacing);
        setFontFeatureSettings(fontFeatureSettings);


        if (allCaps) {
        if (allCaps) {
            setTransformationMethod(new AllCapsTransformationMethod(getContext()));
            setTransformationMethod(new AllCapsTransformationMethod(getContext()));
@@ -2502,6 +2512,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                com.android.internal.R.styleable.TextAppearance_letterSpacing, 0));
                com.android.internal.R.styleable.TextAppearance_letterSpacing, 0));
        }
        }


        if (appearance.hasValue(com.android.internal.R.styleable.TextAppearance_fontFeatureSettings)) {
            setFontFeatureSettings(appearance.getString(
                com.android.internal.R.styleable.TextAppearance_fontFeatureSettings));
        }

        appearance.recycle();
        appearance.recycle();
    }
    }


@@ -2686,6 +2701,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     * This will normally be 0.
     * This will normally be 0.
     *
     *
     * @see #setLetterSpacing(float)
     * @see #setLetterSpacing(float)
     * @see Paint#setLetterSpacing
     * @hide
     * @hide
     */
     */
    public float getLetterSpacing() {
    public float getLetterSpacing() {
@@ -2697,7 +2713,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     * for slight expansion will be around 0.05.  Negative values tighten text.
     * for slight expansion will be around 0.05.  Negative values tighten text.
     *
     *
     * @see #getLetterSpacing()
     * @see #getLetterSpacing()
     * @see Paint#setFlags
     * @see Paint#getLetterSpacing
     *
     *
     * @attr ref android.R.styleable#TextView_letterSpacing
     * @attr ref android.R.styleable#TextView_letterSpacing
     * @hide
     * @hide
@@ -2715,6 +2731,41 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
        }
    }
    }


    /**
     * @return the currently set font feature settings.  Default is null.
     *
     * @see #setFontFeatureSettings(String)
     * @see Paint#setFontFeatureSettings
     * @hide
     */
    public String getFontFeatureSettings() {
        return mTextPaint.getFontFeatureSettings();
    }

    /**
     * Sets font feature settings.  The format is the same as the CSS
     * font-feature-settings attribute:
     * http://dev.w3.org/csswg/css-fonts/#propdef-font-feature-settings
     *
     * @see #getFontFeatureSettings()
     * @see Paint#getFontFeatureSettings
     *
     * @attr ref android.R.styleable#TextView_fontFeatureSettings
     * @hide
     */
    @android.view.RemotableViewMethod
    public void setFontFeatureSettings(String fontFeatureSettings) {
        if (fontFeatureSettings != mTextPaint.getFontFeatureSettings()) {
            mTextPaint.setFontFeatureSettings(fontFeatureSettings);

            if (mLayout != null) {
                nullLayouts();
                requestLayout();
                invalidate();
            }
        }
    }



    /**
    /**
     * Sets the text color for all the states (normal, selected,
     * Sets the text color for all the states (normal, selected,
+2 −2
Original line number Original line Diff line number Diff line
@@ -430,9 +430,9 @@ public:


    static void setFontFeatureSettings(JNIEnv* env, jobject clazz, jlong paintHandle, jstring settings) {
    static void setFontFeatureSettings(JNIEnv* env, jobject clazz, jlong paintHandle, jstring settings) {
        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
        if (!settings)
        if (!settings) {
            paint->setFontFeatureSettings(std::string());
            paint->setFontFeatureSettings(std::string());
        else {
        } else {
            ScopedUtfChars settingsChars(env, settings);
            ScopedUtfChars settingsChars(env, settings);
            paint->setFontFeatureSettings(std::string(settingsChars.c_str(), settingsChars.size()));
            paint->setFontFeatureSettings(std::string(settingsChars.c_str(), settingsChars.size()));
        }
        }
+4 −0
Original line number Original line Diff line number Diff line
@@ -3784,6 +3784,8 @@
        <attr name="elegantTextHeight" format="boolean" />
        <attr name="elegantTextHeight" format="boolean" />
        <!-- Text letter-spacing. -->
        <!-- Text letter-spacing. -->
        <attr name="letterSpacing" format="float" />
        <attr name="letterSpacing" format="float" />
        <!-- Font feature settings. -->
        <attr name="fontFeatureSettings" format="string" />
    </declare-styleable>
    </declare-styleable>
    <declare-styleable name="TextClock">
    <declare-styleable name="TextClock">
        <!-- Specifies the formatting pattern used to show the time and/or date
        <!-- Specifies the formatting pattern used to show the time and/or date
@@ -4079,6 +4081,8 @@
        <attr name="elegantTextHeight" />
        <attr name="elegantTextHeight" />
        <!-- Text letter-spacing. -->
        <!-- Text letter-spacing. -->
        <attr name="letterSpacing" />
        <attr name="letterSpacing" />
        <!-- Font feature settings. -->
        <attr name="fontFeatureSettings" />
    </declare-styleable>
    </declare-styleable>
    <declare-styleable name="TextViewAppearance">
    <declare-styleable name="TextViewAppearance">
        <!-- Base text color, typeface, size, and style. -->
        <!-- Base text color, typeface, size, and style. -->
+5 −2
Original line number Original line Diff line number Diff line
@@ -1305,10 +1305,13 @@ public class Paint {
     * @hide
     * @hide
     */
     */
    public void setFontFeatureSettings(String settings) {
    public void setFontFeatureSettings(String settings) {
        if (settings != null && settings.equals(""))
        if (settings != null && settings.equals("")) {
            settings = null;
            settings = null;
        }
        if ((settings == null && mFontFeatureSettings == null)
        if ((settings == null && mFontFeatureSettings == null)
                || (settings != null && settings.equals(mFontFeatureSettings))) return;
                || (settings != null && settings.equals(mFontFeatureSettings))) {
            return;
        }
        mFontFeatureSettings = settings;
        mFontFeatureSettings = settings;
        native_setFontFeatureSettings(mNativePaint, settings);
        native_setFontFeatureSettings(mNativePaint, settings);
    }
    }