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

Commit a85714f3 authored by Behdad Esfahbod's avatar Behdad Esfahbod Committed by Android Git Automerger
Browse files

am 1de5e88f: Merge "Add fontFeatureSettings to TextView and attrs" into lmp-dev

* commit '1de5e88fba15a5b6123c6e115d060789e2a88609':
  Add fontFeatureSettings to TextView and attrs
parents 838c6cba fb72b6b1
Loading
Loading
Loading
Loading
+52 −1
Original line number Diff line number Diff line
@@ -658,6 +658,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        float dx = 0, dy = 0, r = 0;
        boolean elegant = false;
        float letterSpacing = 0;
        String fontFeatureSettings = null;

        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:
                    letterSpacing = appearance.getFloat(attr, 0);
                    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:
                letterSpacing = a.getFloat(attr, 0);
                break;

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

        if (allCaps) {
            setTransformationMethod(new AllCapsTransformationMethod(getContext()));
@@ -2502,6 +2512,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                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();
    }

@@ -2686,6 +2701,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     * This will normally be 0.
     *
     * @see #setLetterSpacing(float)
     * @see Paint#setLetterSpacing
     * @hide
     */
    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.
     *
     * @see #getLetterSpacing()
     * @see Paint#setFlags
     * @see Paint#getLetterSpacing
     *
     * @attr ref android.R.styleable#TextView_letterSpacing
     * @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,
+2 −2
Original line number Diff line number Diff line
@@ -430,9 +430,9 @@ public:

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