From 42ef515d185d4fc038d602172789cc264f1d9960 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 22 Oct 2012 15:01:17 -0700 Subject: [PATCH] Fix for bug: Gmail (and other places): cursor placed on top of letter This patch fixes bug 7346656. In this particular case, the text line in the EditText was split into multiple spans, with the boundary between the "r" and "," in "r,". These were being drawn as two separate runs, but measured as a single run, leading to inconsistent measurements because this is a kern pair in Roboto. The fix is to eliminate the special-case code for measuring. This will actually improve efficiency, as the value computed in one pass is now more likely to be reused in another. Change-Id: I04142a0ec98f280fc1027c7cbdbf903e3096f8e4 --- core/java/android/text/TextLine.java | 31 ++++++++++++---------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java index 0d2835a98dbe7..1fecf81d5a4fe 100644 --- a/core/java/android/text/TextLine.java +++ b/core/java/android/text/TextLine.java @@ -939,27 +939,22 @@ class TextLine { continue; } - if (c == null) { - x += handleText(wp, i, mlimit, i, inext, runIsRtl, c, x, top, - y, bottom, fmi, needWidth || mlimit < measureLimit); - } else { - for (int j = i, jnext; j < mlimit; j = jnext) { - jnext = mCharacterStyleSpanSet.getNextTransition(mStart + j, mStart + mlimit) - - mStart; + for (int j = i, jnext; j < mlimit; j = jnext) { + jnext = mCharacterStyleSpanSet.getNextTransition(mStart + j, mStart + mlimit) - + mStart; - wp.set(mPaint); - for (int k = 0; k < mCharacterStyleSpanSet.numberOfSpans; k++) { - // Intentionally using >= and <= as explained above - if ((mCharacterStyleSpanSet.spanStarts[k] >= mStart + jnext) || - (mCharacterStyleSpanSet.spanEnds[k] <= mStart + j)) continue; + wp.set(mPaint); + for (int k = 0; k < mCharacterStyleSpanSet.numberOfSpans; k++) { + // Intentionally using >= and <= as explained above + if ((mCharacterStyleSpanSet.spanStarts[k] >= mStart + jnext) || + (mCharacterStyleSpanSet.spanEnds[k] <= mStart + j)) continue; - CharacterStyle span = mCharacterStyleSpanSet.spans[k]; - span.updateDrawState(wp); - } - - x += handleText(wp, j, jnext, i, inext, runIsRtl, c, x, - top, y, bottom, fmi, needWidth || jnext < measureLimit); + CharacterStyle span = mCharacterStyleSpanSet.spans[k]; + span.updateDrawState(wp); } + + x += handleText(wp, j, jnext, i, inext, runIsRtl, c, x, + top, y, bottom, fmi, needWidth || jnext < measureLimit); } }