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

Commit 6a4a1d74 authored by Gilles Debunne's avatar Gilles Debunne Committed by Sriram Raman
Browse files

Bugfixes in StaticLayout. DO NOT MERGE.

Bug 3422121

Cherry-picked from master's 95472.

With ellipsize, lines starting with a very long word that does not
fit inside the width were simply ignored. Cut the long word instead.

start - widthStart index offset shift in BiDi.

The original ellipsize-end patch that added '...' after the last
word on end-ellipsized lines has been punted in favor of a true
ellipsize support in I.

I believe the StaticLayout calculateEllipsise is a no-op since textwidth <= avail
by construction: fitWidth and okwidth are < outerWidth. The only exception is the
paraEnd != here case in generate (when not a single character fits in width).
This case is exercised by StaticLayoutTest in cts (width of 8 pixels) and revealed
an offset error in widstart.

All in all, it looks like this code was probably never really tested. I tried some
typical text configuration to make sure these changes improved the situation.

Change-Id: I6c2cb26436a21f0f89078c275a89e891f0f23b92
parent 566bf98a
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -1727,6 +1727,17 @@ public abstract class Layout {
        }
    }

    /**
     * Inform this layout that not all of its lines will be displayed, because a maximum number of
     * lines has been set on the associated TextView.
     *
     * A non strictly positive value means that all lines are displayed.
     *
     * @param lineCount number of visible lines
     * @hide
     */
    public void setMaximumVisibleLineCount(int lineCount) {}

    private CharSequence mText;
    private TextPaint mPaint;
    /* package */ TextPaint mWorkPaint;
@@ -1765,14 +1776,4 @@ public abstract class Layout {
    /* package */ static final Directions DIRS_ALL_RIGHT_TO_LEFT =
        new Directions(new int[] { 0, RUN_LENGTH_MASK | RUN_RTL_FLAG });

    /**
     * Inform this layout that not all of its lines will be displayed, because a maximum number of
     * lines has been set on the associated TextView.
     *
     * A non positive value means that all lines are displayed.
     *
     * @param line line number of the last visible line (line numbers start at 1 for the first line)
     * @hide
     */
    public void setMaximumVisibleLineCount(int line) {}
}
+9 −61
Original line number Diff line number Diff line
@@ -359,44 +359,6 @@ public class StaticLayout extends Layout
                            if (fitbottom > okbottom)
                                okbottom = fitbottom;
                        }
                    } else {
                        if (ellipsize != null) {
                            // Break only at spaces using ok indexes.
                            if (ok != here) {
                                // Log.e("text", "output ok " + here + " to " +ok);

                                while (ok < spanEnd && chs[ok - paraStart] == ' ') {
                                    ok++;
                                }

                                v = out(source,
                                        here, ok,
                                        okascent, okdescent, oktop, okbottom,
                                        v,
                                        spacingmult, spacingadd, chooseht,
                                        choosehtv, fm, hasTabOrEmoji,
                                        needMultiply, paraStart, chdirs, dir, easy,
                                        ok == bufend, includepad, trackpad,
                                        chs, widths, here - paraStart,
                                        ellipsize, ellipsizedWidth, okwidth,
                                        paint);

                                here = ok;
                            } else {
                                // Act like it fit even though it didn't.

                                fitwidth = w;
                                here = fit = j + 1;

                                if (fmtop < fittop)
                                    fittop = fmtop;
                                if (fmascent < fitascent)
                                    fitascent = fmascent;
                                if (fmdescent > fitdescent)
                                    fitdescent = fmdescent;
                                if (fmbottom > fitbottom)
                                    fitbottom = fmbottom;
                            }
                    } else {
                            if (ok != here) {
                                // Log.e("text", "output ok " + here + " to " +ok);
@@ -413,7 +375,7 @@ public class StaticLayout extends Layout
                                        choosehtv, fm, hasTabOrEmoji,
                                        needMultiply, paraStart, chdirs, dir, easy,
                                        ok == bufend, includepad, trackpad,
                                        chs, widths, here - paraStart,
                                        chs, widths, paraStart,
                                        ellipsize, ellipsizedWidth, okwidth,
                                        paint);

@@ -429,7 +391,7 @@ public class StaticLayout extends Layout
                                        choosehtv, fm, hasTabOrEmoji,
                                        needMultiply, paraStart, chdirs, dir, easy,
                                        fit == bufend, includepad, trackpad,
                                        chs, widths, here - paraStart,
                                        chs, widths, paraStart,
                                        ellipsize, ellipsizedWidth, fitwidth,
                                        paint);

@@ -451,13 +413,12 @@ public class StaticLayout extends Layout
                                        needMultiply, paraStart, chdirs, dir, easy,
                                        here + 1 == bufend, includepad,
                                        trackpad,
                                        chs, widths, here - paraStart,
                                        chs, widths, paraStart,
                                        ellipsize, ellipsizedWidth,
                                        widths[here - paraStart], paint);

                                here = here + 1;
                            }
                        }

                        if (here < spanStart) {
                            // didn't output all the text for this span
@@ -500,7 +461,7 @@ public class StaticLayout extends Layout
                        choosehtv, fm, hasTabOrEmoji,
                        needMultiply, paraStart, chdirs, dir, easy,
                        paraEnd == bufend, includepad, trackpad,
                        chs, widths, here - paraStart,
                        chs, widths, paraStart,
                        ellipsize, ellipsizedWidth, w, paint);
            }

@@ -620,19 +581,6 @@ public class StaticLayout extends Layout
        return false;
    }

/*
    private static void dump(byte[] data, int count, String label) {
        if (false) {
            System.out.print(label);

            for (int i = 0; i < count; i++)
                System.out.print(" " + data[i]);

            System.out.println();
        }
    }
*/

    private int out(CharSequence text, int start, int end,
                      int above, int below, int top, int bottom, int v,
                      float spacingmult, float spacingadd,
@@ -735,8 +683,8 @@ public class StaticLayout extends Layout
        if (easy) {
            mLineDirections[j] = linedirs;
        } else {
            mLineDirections[j] = AndroidBidi.directions(dir, chdirs, widstart, chs,
                    widstart, end - start);
            mLineDirections[j] = AndroidBidi.directions(dir, chdirs, start - widstart, chs,
                    start - widstart, end - start);
        }

        // If ellipsize is in marquee mode, do not apply ellipsis on the first line
@@ -875,7 +823,7 @@ public class StaticLayout extends Layout
    @Override
    public int getLineDescent(int line) {
        int descent = mLines[mColumns * line + DESCENT];
        if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount - 1 &&
        if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount - 1 && // -1 intended
                line != mLineCount) {
            descent += getBottomPadding();
        }
@@ -939,8 +887,8 @@ public class StaticLayout extends Layout
     * @hide
     */
    @Override
    public void setMaximumVisibleLineCount(int line) {
        mMaximumVisibleLineCount = line;
    public void setMaximumVisibleLineCount(int lineCount) {
        mMaximumVisibleLineCount = lineCount;
    }

    private int mLineCount;