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

Commit c70e7a0b authored by Gilles Debunne's avatar Gilles Debunne
Browse files

Ellipsize avoids spaces and starts right after text

Bug 5509226

Change ellipsize bounds to take spaces into account

The hardcoded ' ' character may be problematic with other langages.

Note that a different ellipsize logic also exists in StaticLayout.
Created 6062415 to track this.

Change-Id: I3406ec23a592f952bf3e0ca68f0838ee807baba0
parent a16c98c1
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -222,23 +222,27 @@ class MeasuredText {
        return wid;
    }

    int breakText(int start, int limit, boolean forwards, float width) {
    int breakText(int limit, boolean forwards, float width) {
        float[] w = mWidths;
        if (forwards) {
            for (int i = start; i < limit; ++i) {
                if ((width -= w[i]) < 0) {
                    return i - start;
                }
            }
            int i = 0;
            while (i < limit) {
                width -= w[i];
                if (width < 0.0f) break;
                i++;
            }
            while (i > 0 && mChars[i - 1] == ' ') i--;
            return i;
        } else {
            for (int i = limit; --i >= start;) {
                if ((width -= w[i]) < 0) {
                    return limit - i -1;
                }
            int i = limit - 1;
            while (i >= 0) {
                width -= w[i];
                if (width < 0.0f) break;
                i--;
            }
            while (i < limit - 1 && mChars[i + 1] == ' ') i++;
            return limit - i - 1;
        }

        return limit - start;
    }

    float measure(int start, int limit) {
+4 −4
Original line number Diff line number Diff line
@@ -1091,13 +1091,13 @@ public class TextUtils {
            if (avail < 0) {
                // it all goes
            } else if (where == TruncateAt.START) {
                right = len - mt.breakText(0, len, false, avail);
                right = len - mt.breakText(len, false, avail);
            } else if (where == TruncateAt.END || where == TruncateAt.END_SMALL) {
                left = mt.breakText(0, len, true, avail);
                left = mt.breakText(len, true, avail);
            } else {
                right = len - mt.breakText(0, len, false, avail / 2);
                right = len - mt.breakText(len, false, avail / 2);
                avail -= mt.measure(right, len);
                left = mt.breakText(0, right, true, avail);
                left = mt.breakText(right, true, avail);
            }

            if (callback != null) {