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

Commit 23241887 authored by Doug Felt's avatar Doug Felt
Browse files

Fix IndexOutOfBoundsException when measuring text.

Some line wrapping conditions caused the same style run to be measured
twice, incorrectly advancing the position in the width buffer and
occasionally causing measurement to run out of room.  The fix is to
not remeasure the same style run.

Change-Id: Iceb29729c1c27bb602df20fdf83af1da28c82e11
parent c8f302fb
Loading
Loading
Loading
Loading
+25 −18
Original line number Diff line number Diff line
@@ -216,8 +216,10 @@ extends Layout

            boolean tab = false;

            int spanEnd;
            for (int spanStart = paraStart; spanStart < paraEnd; spanStart = spanEnd) {
            for (int spanStart = paraStart, spanEnd = spanStart, nextSpanStart;
                    spanStart < paraEnd; spanStart = nextSpanStart) {

                if (spanStart == spanEnd) {
                    if (spanned == null)
                        spanEnd = paraEnd;
                    else
@@ -225,9 +227,6 @@ extends Layout
                                MetricAffectingSpan.class);

                    int spanLen = spanEnd - spanStart;
                int startInPara = spanStart - paraStart;
                int endInPara = spanEnd - paraStart;

                    if (spanned == null) {
                        measured.addStyleRun(paint, spanLen, fm);
                    } else {
@@ -235,6 +234,11 @@ extends Layout
                            spanned.getSpans(spanStart, spanEnd, MetricAffectingSpan.class);
                        measured.addStyleRun(paint, spans, spanLen, fm);
                    }
                }

                nextSpanStart = spanEnd;
                int startInPara = spanStart - paraStart;
                int endInPara = spanEnd - paraStart;

                int fmtop = fm.top;
                int fmbottom = fm.bottom;
@@ -432,7 +436,10 @@ extends Layout
                        }

                        if (here < spanStart) {
                            j = spanEnd = here; // must remeasure
                            // didn't output all the text for this span
                            // we've measured the raw widths, though, so
                            // just reset the start point
                            j = nextSpanStart = here;
                        } else {
                            j = here - 1;    // continue looping
                        }