diff options
| author | Raph Levien <raph@google.com> | 2016-01-12 17:45:34 -0800 |
|---|---|---|
| committer | Raph Levien <raph@google.com> | 2016-01-12 17:45:34 -0800 |
| commit | e53e428a7efd624459961da3f932b408f896453b (patch) | |
| tree | 27fb30d266b7b16292bf17ce1244bdb2324b3250 /core/java/android/text/Layout.java | |
| parent | 477e26cf931290f6b3353fab43a05406eea223f9 (diff) | |
| parent | 957bdc56c5e236d8c759781c2c09c3a99a68b065 (diff) | |
resolve merge conflicts of 957bdc56c5 to master.
Change-Id: I4c8749f92a1fa39bf0d08e10155d9e68c87401c0
Diffstat (limited to 'core/java/android/text/Layout.java')
| -rw-r--r-- | core/java/android/text/Layout.java | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index f9387b39616f..2c4241b7eceb 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -1116,24 +1116,30 @@ public abstract class Layout { public int getOffsetForHorizontal(int line, float horiz) { // TODO: use Paint.getOffsetForAdvance to avoid binary search final int lineEndOffset = getLineEnd(line); + final int lineStartOffset = getLineStart(line); + + Directions dirs = getLineDirections(line); + + TextLine tl = TextLine.obtain(); + // XXX: we don't care about tabs as we just use TextLine#getOffsetToLeftRightOf here. + tl.set(mPaint, mText, lineStartOffset, lineEndOffset, getParagraphDirection(line), dirs, + false, null); + final int max; if (line == getLineCount() - 1) { max = lineEndOffset; } else { - max = mPaint.getTextRunCursor(mText, 0, mText.length(), - isRtlCharAt(lineEndOffset) ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR, - lineEndOffset, Paint.CURSOR_BEFORE); + max = tl.getOffsetToLeftRightOf(lineEndOffset - lineStartOffset, + !isRtlCharAt(lineEndOffset - 1)) + lineStartOffset; } - final int min = getLineStart(line); - Directions dirs = getLineDirections(line); - - int best = min; + int best = lineStartOffset; float bestdist = Math.abs(getPrimaryHorizontal(best) - horiz); for (int i = 0; i < dirs.mDirections.length; i += 2) { - int here = min + dirs.mDirections[i]; + int here = lineStartOffset + dirs.mDirections[i]; int there = here + (dirs.mDirections[i+1] & RUN_LENGTH_MASK); - int swap = (dirs.mDirections[i+1] & RUN_RTL_FLAG) != 0 ? -1 : 1; + boolean isRtl = (dirs.mDirections[i+1] & RUN_RTL_FLAG) != 0; + int swap = isRtl ? -1 : 1; if (there > max) there = max; @@ -1153,23 +1159,23 @@ public abstract class Layout { low = here + 1; if (low < there) { - low = getOffsetAtStartOf(low); - - float dist = Math.abs(getPrimaryHorizontal(low) - horiz); - - int aft = TextUtils.getOffsetAfter(mText, low); - if (aft < there) { - float other = Math.abs(getPrimaryHorizontal(aft) - horiz); - - if (other < dist) { - dist = other; - low = aft; + int aft = tl.getOffsetToLeftRightOf(low - lineStartOffset, isRtl) + lineStartOffset; + low = tl.getOffsetToLeftRightOf(aft - lineStartOffset, !isRtl) + lineStartOffset; + if (low >= here && low < there) { + float dist = Math.abs(getPrimaryHorizontal(low) - horiz); + if (aft < there) { + float other = Math.abs(getPrimaryHorizontal(aft) - horiz); + + if (other < dist) { + dist = other; + low = aft; + } } - } - if (dist < bestdist) { - bestdist = dist; - best = low; + if (dist < bestdist) { + bestdist = dist; + best = low; + } } } @@ -1188,6 +1194,7 @@ public abstract class Layout { best = max; } + TextLine.recycle(tl); return best; } |
