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

Commit dd2d58e0 authored by Tyler Freeman's avatar Tyler Freeman Committed by Automerger Merge Worker
Browse files

Merge changes from topics "fontscaling-lineheight-after",...

Merge changes from topics "fontscaling-lineheight-after", "fontscaling-lineheight-spfix" into udc-dev am: 48e1f12c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22628385



Change-Id: Id41dd1d5cadaf3cb45045b44aa4855a9df9b8394
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 22f3a5c7 48e1f12c
Loading
Loading
Loading
Loading
+16 −4
Original line number Original line Diff line number Diff line
@@ -385,9 +385,21 @@ public class TypedValue {
     *
     *
     * @return The complex unit type.
     * @return The complex unit type.
     */
     */
     public int getComplexUnit()
    public int getComplexUnit() {
     {
        return getUnitFromComplexDimension(data);
         return COMPLEX_UNIT_MASK & (data>>TypedValue.COMPLEX_UNIT_SHIFT);
    }

    /**
     * Return the complex unit type for the given complex dimension. For example, a dimen type
     * with value 12sp will return {@link #COMPLEX_UNIT_SP}. Use with values created with {@link
     * #createComplexDimension(int, int)} etc.
     *
     * @return The complex unit type.
     *
     * @hide
     */
    public static int getUnitFromComplexDimension(int complexDimension) {
        return COMPLEX_UNIT_MASK & (complexDimension >> TypedValue.COMPLEX_UNIT_SHIFT);
    }
    }


    /**
    /**
+32 −0
Original line number Original line Diff line number Diff line
@@ -868,6 +868,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    private float mSpacingAdd = 0.0f;
    private float mSpacingAdd = 0.0f;
    /**
     * Remembers what line height was set to originally, before we broke it down into raw pixels.
     *
     * <p>This is stored as a complex dimension with both value and unit packed into one field!
     * {@see TypedValue}
     */
    private int mLineHeightComplexDimen;
    private int mBreakStrategy;
    private int mBreakStrategy;
    private int mHyphenationFrequency;
    private int mHyphenationFrequency;
    private int mJustificationMode;
    private int mJustificationMode;
@@ -4641,6 +4649,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        if (size != mTextPaint.getTextSize()) {
        if (size != mTextPaint.getTextSize()) {
            mTextPaint.setTextSize(size);
            mTextPaint.setTextSize(size);
            maybeRecalculateLineHeight();
            if (shouldRequestLayout && mLayout != null) {
            if (shouldRequestLayout && mLayout != null) {
                // Do not auto-size right after setting the text size.
                // Do not auto-size right after setting the text size.
                mNeedsAutoSizeText = false;
                mNeedsAutoSizeText = false;
@@ -6226,6 +6235,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        if (lineHeight != fontHeight) {
        if (lineHeight != fontHeight) {
            // Set lineSpacingExtra by the difference of lineSpacing with lineHeight
            // Set lineSpacingExtra by the difference of lineSpacing with lineHeight
            setLineSpacing(lineHeight - fontHeight, 1f);
            setLineSpacing(lineHeight - fontHeight, 1f);
            mLineHeightComplexDimen =
                        TypedValue.createComplexDimension(lineHeight, TypedValue.COMPLEX_UNIT_PX);
        }
        }
    }
    }
@@ -6258,6 +6270,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                || mTextSizeUnit != TypedValue.COMPLEX_UNIT_SP
                || mTextSizeUnit != TypedValue.COMPLEX_UNIT_SP
        ) {
        ) {
            setLineHeightPx(TypedValue.applyDimension(unit, lineHeight, metrics));
            setLineHeightPx(TypedValue.applyDimension(unit, lineHeight, metrics));
            // Do this last so it overwrites what setLineHeightPx() sets it to.
            mLineHeightComplexDimen = TypedValue.createComplexDimension(lineHeight, unit);
            return;
            return;
        }
        }
@@ -6276,6 +6291,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        );
        );
        var ratio = lineHeight / textSizeSp;
        var ratio = lineHeight / textSizeSp;
        setLineHeightPx(textSizePx * ratio);
        setLineHeightPx(textSizePx * ratio);
        // Do this last so it overwrites what setLineHeightPx() sets it to.
        mLineHeightComplexDimen = TypedValue.createComplexDimension(lineHeight, unit);
    }
    private void maybeRecalculateLineHeight() {
        if (mLineHeightComplexDimen == 0) {
            return;
        }
        int unit = TypedValue.getUnitFromComplexDimension(mLineHeightComplexDimen);
        if (unit != TypedValue.COMPLEX_UNIT_SP) {
            // The lineHeight was never supplied in SP, so we didn't do any fancy recalculations
            // in setLineHeight(). We don't need to recalculate.
            return;
        }
        setLineHeight(unit, TypedValue.complexToFloat(mLineHeightComplexDimen));
    }
    }
    /**
    /**