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

Commit 53145635 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Fix BoringLayout with PrecomputedText

The special logic for PrecomputedText in BoringLayout has problem.
The special logic is no longer necessary since TextLine is now aware of
PrecomputedText. So, just removing special logic from BoringLayout.

On the other hand, the metrics parameters check in TextLine has removed
Ie73bce52c6c673cda58973ddad04627a7cf2e5e9, but that was wrong. TextLine
can be used by BoringLayout too. Thus, need to reject PrecomputedText
if the given TextPaint is not compatible with given param.

Bug: 76227465
Test: atest CtsWidgetTestCases:EditTextTest
    CtsWidgetTestCases:TextViewFadingEdgeTest
    FrameworksCoreTests:TextViewFallbackLineSpacingTest
    FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
    CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
    CtsTextTestCases FrameworksCoreTests:android.text
    CtsWidgetTestCases:TextViewPrecomputedTextTest

Change-Id: I172b5f655402e797b53b9667b49cb4ab89ec0dc0
parent 5558126b
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -347,14 +347,7 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback
        TextLine line = TextLine.obtain();
        line.set(paint, text, 0, textLength, Layout.DIR_LEFT_TO_RIGHT,
                Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null);
        if (text instanceof PrecomputedText) {
            PrecomputedText mt = (PrecomputedText) text;
            // Reaching here means there is only one paragraph.
            MeasuredParagraph mp = mt.getMeasuredParagraph(0);
            fm.width = (int) Math.ceil(mp.getWidth(0, mp.getTextLength()));
        } else {
        fm.width = (int) Math.ceil(line.metrics(fm));
        }
        TextLine.recycle(line);

        return fm;
+5 −0
Original line number Diff line number Diff line
@@ -172,7 +172,12 @@ public class TextLine {

        mComputed = null;
        if (text instanceof PrecomputedText) {
            // Here, no need to check line break strategy or hyphenation frequency since there is no
            // line break concept here.
            mComputed = (PrecomputedText) text;
            if (!mComputed.getParams().getTextPaint().equalsForTextMeasurement(paint)) {
                mComputed = null;
            }
        }

        mCharsValid = hasReplacement || hasTabs || directions != Layout.DIRS_ALL_LEFT_TO_RIGHT;