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

Commit 884eb4b8 authored by Gilles Debunne's avatar Gilles Debunne Committed by Android (Google) Code Review
Browse files

Merge "Better handling of spaces at ends of lines in StaticLayout."

parents 58cf5762 81541491
Loading
Loading
Loading
Loading
+25 −38
Original line number Diff line number Diff line
@@ -150,8 +150,8 @@ public class StaticLayout extends Layout {

        mColumns = COLUMNS_ELLIPSIZE;
        mLines = new int[ArrayUtils.idealIntArraySize(2 * mColumns)];
        mLineDirections = new Directions[
                             ArrayUtils.idealIntArraySize(2 * mColumns)];
        mLineDirections = new Directions[ArrayUtils.idealIntArraySize(2 * mColumns)];
        // FIXME This is never recycled
        mMeasured = MeasuredText.obtain();
    }

@@ -340,7 +340,9 @@ public class StaticLayout extends Layout {
                        w += widths[j - paraStart];
                    }

                    if (w <= width) {
                    boolean isSpaceOrTab = c == CHAR_SPACE || c == CHAR_TAB;

                    if (w <= width || isSpaceOrTab) {
                        fitWidth = w;
                        fit = j + 1;

@@ -353,30 +355,22 @@ public class StaticLayout extends Layout {
                        if (fmBottom > fitBottom)
                            fitBottom = fmBottom;

                        /*
                         * From the Unicode Line Breaking Algorithm:
                         * (at least approximately)
                         *
                         * .,:; are class IS: breakpoints
                         *      except when adjacent to digits
                         * /    is class SY: a breakpoint
                         *      except when followed by a digit.
                         * -    is class HY: a breakpoint
                         *      except when followed by a digit.
                         *
                         * Ideographs are class ID: breakpoints when adjacent,
                         * except for NS (non-starters), which can be broken
                         * after but not before.
                         */
                        if (c == CHAR_SPACE || c == CHAR_TAB ||
                        // From the Unicode Line Breaking Algorithm (at least approximately)
                        boolean isLineBreak = isSpaceOrTab ||
                                // .,:; are class IS breakpoints, except when adjacent to digits
                                ((c == CHAR_DOT || c == CHAR_COMMA ||
                                c == CHAR_COLON || c == CHAR_SEMICOLON) &&
                                (j - 1 < here || !Character.isDigit(chs[j - 1 - paraStart])) &&
                                (j + 1 >= spanEnd || !Character.isDigit(chs[j + 1 - paraStart]))) ||
                                // / is class SY and - is class HY, except when followed by a digit
                                ((c == CHAR_SLASH || c == CHAR_HYPHEN) &&
                                (j + 1 >= spanEnd || !Character.isDigit(chs[j + 1 - paraStart]))) ||
                                // Ideographs are class ID: breakpoints when adjacent, except for NS
                                // (non-starters), which can be broken after but not before
                                (c >= CHAR_FIRST_CJK && isIdeographic(c, true) &&
                             j + 1 < spanEnd && isIdeographic(chs[j + 1 - paraStart], false))) {
                                j + 1 < spanEnd && isIdeographic(chs[j + 1 - paraStart], false));

                        if (isLineBreak) {
                            okWidth = w;
                            ok = j + 1;

@@ -396,13 +390,6 @@ public class StaticLayout extends Layout {
                        float currentTextWidth;

                        if (ok != here) {
                            // If it is a space that makes the length exceed width, cut here
                            if (c == CHAR_SPACE) ok = j + 1;

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

                            endPos = ok;
                            above = okAscent;
                            below = okDescent;
@@ -450,13 +437,13 @@ public class StaticLayout extends Layout {
                            spanEnd = here;
                            break;
                        }
                    }
                    // FIXME This should be moved in the above else block which changes mLineCount

                        if (mLineCount >= mMaximumVisibleLineCount) {
                            break;
                        }
                    }
                }
            }

            if (paraEnd != here && mLineCount < mMaximumVisibleLineCount) {
                if ((fitTop | fitBottom | fitDescent | fitAscent) == 0) {