From f96d87c349d281bf9ec56ee9617bd963cb37558f Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 3 May 2018 15:14:58 -0700 Subject: [PATCH] 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. --- engine/src/flutter/third_party/txt/src/txt/paragraph.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc index 9e732f7164..38952cd0e0 100644 --- a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc +++ b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc @@ -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 {