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
This commit is contained in:
Raph Levien 2015-04-22 15:31:29 -07:00
parent 05e89cffd4
commit d24df3eb94

View File

@ -84,11 +84,12 @@ void LineBreaker::setIndents(const std::vector<float>& 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