libtxt: exclude soft break whitespace from line widths for right justification (flutter/engine#5166)

If a line has a soft break due to word wrap, the line width should not include
the width of the whitespace characters within the soft break.
This commit is contained in:
Jason Simmons
2018-05-03 15:14:58 -07:00
committed by GitHub
parent 75b94b4ea5
commit f96d87c349

View File

@@ -787,7 +787,12 @@ double Paragraph::GetLineXOffset(size_t line_number,
if (align == TextAlign::right ||
(align == TextAlign::start && direction == TextDirection::rtl) ||
(align == TextAlign::end && direction == TextDirection::ltr)) {
return width_ - line_total_advance;
// If this line has a soft break, then use the line width calculated by the
// line breaker because that width excludes the soft break's whitespace.
double text_width = line_ranges_[line_number].hard_break
? line_total_advance
: line_widths_[line_number];
return width_ - text_width;
} else if (paragraph_style_.text_align == TextAlign::center) {
return (width_ - line_widths_[line_number]) / 2;
} else {