Merge "Fix measurement to respect grapheme and span boundaries" into mnc-dr1.5-dev am: 36c5ab3542

am: 50c22adc25

* commit '50c22adc2564fa1c31b9d0aea88707da4299d6ed':
  Fix measurement to respect grapheme and span boundaries
This commit is contained in:
Raph Levien
2016-01-12 01:17:37 +00:00
committed by android-build-merger

View File

@@ -718,13 +718,14 @@ class TextLine {
* @param bottom the bottom of the line * @param bottom the bottom of the line
* @param fmi receives metrics information, can be null * @param fmi receives metrics information, can be null
* @param needWidth true if the width of the run is needed * @param needWidth true if the width of the run is needed
* @param offset the offset for the purpose of measuring
* @return the signed width of the run based on the run direction; only * @return the signed width of the run based on the run direction; only
* valid if needWidth is true * valid if needWidth is true
*/ */
private float handleText(TextPaint wp, int start, int end, private float handleText(TextPaint wp, int start, int end,
int contextStart, int contextEnd, boolean runIsRtl, int contextStart, int contextEnd, boolean runIsRtl,
Canvas c, float x, int top, int y, int bottom, Canvas c, float x, int top, int y, int bottom,
FontMetricsInt fmi, boolean needWidth) { FontMetricsInt fmi, boolean needWidth, int offset) {
// Get metrics first (even for empty strings or "0" width runs) // Get metrics first (even for empty strings or "0" width runs)
if (fmi != null) { if (fmi != null) {
@@ -742,11 +743,11 @@ class TextLine {
if (needWidth || (c != null && (wp.bgColor != 0 || wp.underlineColor != 0 || runIsRtl))) { if (needWidth || (c != null && (wp.bgColor != 0 || wp.underlineColor != 0 || runIsRtl))) {
if (mCharsValid) { if (mCharsValid) {
ret = wp.getRunAdvance(mChars, start, end, contextStart, contextEnd, ret = wp.getRunAdvance(mChars, start, end, contextStart, contextEnd,
runIsRtl, end); runIsRtl, offset);
} else { } else {
int delta = mStart; int delta = mStart;
ret = wp.getRunAdvance(mText, delta + start, delta + end, ret = wp.getRunAdvance(mText, delta + start, delta + end,
delta + contextStart, delta + contextEnd, runIsRtl, delta + end); delta + contextStart, delta + contextEnd, runIsRtl, delta + offset);
} }
} }
@@ -895,8 +896,8 @@ class TextLine {
TextPaint wp = mWorkPaint; TextPaint wp = mWorkPaint;
wp.set(mPaint); wp.set(mPaint);
final int mlimit = measureLimit; final int mlimit = measureLimit;
return handleText(wp, start, mlimit, start, limit, runIsRtl, c, x, top, return handleText(wp, start, limit, start, limit, runIsRtl, c, x, top,
y, bottom, fmi, needWidth || mlimit < measureLimit); y, bottom, fmi, needWidth || mlimit < measureLimit, mlimit);
} }
mMetricAffectingSpanSpanSet.init(mSpanned, mStart + start, mStart + limit); mMetricAffectingSpanSpanSet.init(mSpanned, mStart + start, mStart + limit);
@@ -940,13 +941,14 @@ class TextLine {
} }
for (int j = i, jnext; j < mlimit; j = jnext) { for (int j = i, jnext; j < mlimit; j = jnext) {
jnext = mCharacterStyleSpanSet.getNextTransition(mStart + j, mStart + mlimit) - jnext = mCharacterStyleSpanSet.getNextTransition(mStart + j, mStart + inext) -
mStart; mStart;
int offset = Math.min(jnext, mlimit);
wp.set(mPaint); wp.set(mPaint);
for (int k = 0; k < mCharacterStyleSpanSet.numberOfSpans; k++) { for (int k = 0; k < mCharacterStyleSpanSet.numberOfSpans; k++) {
// Intentionally using >= and <= as explained above // Intentionally using >= and <= as explained above
if ((mCharacterStyleSpanSet.spanStarts[k] >= mStart + jnext) || if ((mCharacterStyleSpanSet.spanStarts[k] >= mStart + offset) ||
(mCharacterStyleSpanSet.spanEnds[k] <= mStart + j)) continue; (mCharacterStyleSpanSet.spanEnds[k] <= mStart + j)) continue;
CharacterStyle span = mCharacterStyleSpanSet.spans[k]; CharacterStyle span = mCharacterStyleSpanSet.spans[k];
@@ -958,7 +960,7 @@ class TextLine {
wp.setHyphenEdit(0); wp.setHyphenEdit(0);
} }
x += handleText(wp, j, jnext, i, inext, runIsRtl, c, x, x += handleText(wp, j, jnext, i, inext, runIsRtl, c, x,
top, y, bottom, fmi, needWidth || jnext < measureLimit); top, y, bottom, fmi, needWidth || jnext < measureLimit, offset);
} }
} }