From 78f0d83550d70f043e1b9d35f56efa8c7572f44f Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Tue, 10 May 2016 12:21:33 -0700 Subject: [PATCH] Sum up character widths to get the last line width for ellipsis. To properly apply ellipsis, we virtually concatenate the last line and overflowed lines after line breaking for a paragraph. Previously, width of the concatenated line was computed by summing up all line's width. However, the width is wrong when there are any trailing white spaces that can be normal white spaces by concatenating lines. With this CL, we sum up widths of all characters in lines except the last overflowed line. Bug: 28599066 Change-Id: I41d828ee8eb8a702cd5096d626b307cbb3467047 --- core/java/android/text/StaticLayout.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java index 239f2d0c89b24..bb131a0e83e88 100644 --- a/core/java/android/text/StaticLayout.java +++ b/core/java/android/text/StaticLayout.java @@ -754,15 +754,21 @@ public class StaticLayout extends Layout { && ellipsize != TextUtils.TruncateAt.MARQUEE)); if (remainingLineCount > 0 && remainingLineCount < breakCount && ellipsisMayBeApplied) { - // Treat the last line and overflowed lines as a single line. - breaks[remainingLineCount - 1] = breaks[breakCount - 1]; // Calculate width and flag. float width = 0; int flag = 0; for (int i = remainingLineCount - 1; i < breakCount; i++) { - width += lineWidths[i]; + if (i == breakCount - 1) { + width += lineWidths[i]; + } else { + for (int j = (i == 0 ? 0 : breaks[i - 1]); j < breaks[i]; j++) { + width += widths[j]; + } + } flag |= flags[i] & TAB_MASK; } + // Treat the last line and overflowed lines as a single line. + breaks[remainingLineCount - 1] = breaks[breakCount - 1]; lineWidths[remainingLineCount - 1] = width; flags[remainingLineCount - 1] = flag;