From 1fa3c9bef2f96e4130d481a4d2241968ab937019 Mon Sep 17 00:00:00 2001 From: Alan Lau Date: Wed, 30 Jul 2014 17:35:20 +0000 Subject: [PATCH] Revert "Revert "DO NOT MERGE Fix line breaking for clusters in narrow views"" This reverts commit cbeef01cce314e3a3977b042d8ec0744816c0df4. Change-Id: I170ccb2264941e8a8b090b3bb553970414f0c4eb --- core/java/android/text/StaticLayout.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java index 814326c3ba3ff..457e04f6e562a 100644 --- a/core/java/android/text/StaticLayout.java +++ b/core/java/android/text/StaticLayout.java @@ -379,7 +379,7 @@ public class StaticLayout extends Layout { okBottom = fitBottom; } } else { - final boolean moreChars = (j + 1 < spanEnd); + final boolean moreChars; int endPos; int above, below, top, bottom; float currentTextWidth; @@ -391,6 +391,7 @@ public class StaticLayout extends Layout { top = okTop; bottom = okBottom; currentTextWidth = okWidth; + moreChars = (j + 1 < spanEnd); } else if (fit != here) { endPos = fit; above = fitAscent; @@ -398,13 +399,21 @@ public class StaticLayout extends Layout { top = fitTop; bottom = fitBottom; currentTextWidth = fitWidth; + moreChars = (j + 1 < spanEnd); } else { + // must make progress, so take next character endPos = here + 1; - above = fm.ascent; - below = fm.descent; - top = fm.top; - bottom = fm.bottom; + // but to deal properly with clusters + // take all zero width characters following that + while (endPos < spanEnd && widths[endPos - paraStart] == 0) { + endPos++; + } + above = fmAscent; + below = fmDescent; + top = fmTop; + bottom = fmBottom; currentTextWidth = widths[here - paraStart]; + moreChars = (endPos < spanEnd); } v = out(source, here, endPos,