From 68ae337aa05f598af18b09fe4125146d4d67db83 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 22 Apr 2015 15:31:29 -0700 Subject: [PATCH] Don't include trailing newline in width for line breaking In a paragraph with a trailing newline, the width of the newline character was included in the line width for breaking purposes, basically as if it were a non-breaking space. This caused a discrepancy, where Layout.getDesiredWidth() suggested that the text would fit in a single line, but StaticLayout would break it because of the added width of the newline character. The proposed fix is simply to consider newline to be a space that disappears at the end of a line. Bug: 20152308 Change-Id: I539574c5b8ea892c8ed6aca6c59e90ccdf74a680 --- libs/minikin/LineBreaker.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/minikin/LineBreaker.cpp b/libs/minikin/LineBreaker.cpp index f4201cb26b7..88190fff6f5 100644 --- a/libs/minikin/LineBreaker.cpp +++ b/libs/minikin/LineBreaker.cpp @@ -84,11 +84,12 @@ void LineBreaker::setIndents(const std::vector& indents) { } // This function determines whether a character is a space that disappears at end of line. -// It is the Unicode set: [[:General_Category=Space_Separator:]-[:Line_Break=Glue:]] +// It is the Unicode set: [[:General_Category=Space_Separator:]-[:Line_Break=Glue:]], +// plus '\n'. // Note: all such characters are in the BMP, so it's ok to use code units for this. static bool isLineEndSpace(uint16_t c) { - return c == ' ' || c == 0x1680 || (0x2000 <= c && c <= 0x200A && c != 0x2007) || c == 0x205F || - c == 0x3000; + return c == '\n' || c == ' ' || c == 0x1680 || (0x2000 <= c && c <= 0x200A && c != 0x2007) || + c == 0x205F || c == 0x3000; } // Ordinarily, this method measures the text in the range given. However, when paint