From ecc6fb262baa5cf98eb33eef2f4b9c2bbba38251 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 15 Apr 2020 17:19:38 -0700 Subject: [PATCH] Adjust newline rectangles to reflect paragraph alignment GetRectsForRange inserts empty rectangles that represent newline characters within the specified range of text positions. The x coordinate of these rectangles needs to account for left/right/center alignment. Fixes https://github.com/flutter/flutter/issues/53057 --- third_party/txt/src/txt/paragraph_txt.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/third_party/txt/src/txt/paragraph_txt.cc b/third_party/txt/src/txt/paragraph_txt.cc index 54d8cc486e150..88bbee2521706 100644 --- a/third_party/txt/src/txt/paragraph_txt.cc +++ b/third_party/txt/src/txt/paragraph_txt.cc @@ -1732,11 +1732,12 @@ std::vector ParagraphTxt::GetRectsForRange( if (line_box_metrics.find(line_number) == line_box_metrics.end()) { if (line.end_index != line.end_including_newline && line.end_index >= start && line.end_including_newline <= end) { - SkScalar x = line_widths_[line_number]; - // Move empty box to center if center aligned and is an empty line. - if (x == 0 && !isinf(width_) && - paragraph_style_.effective_align() == TextAlign::center) { - x = width_ / 2; + SkScalar x; + const GlyphLine& glyph_line = glyph_lines_[line_number]; + if (glyph_lines_[line_number].positions.empty()) { + x = GetLineXOffset(0, line_number, false); + } else { + x = glyph_line.positions.back().x_pos.end; } SkScalar top = (line_number > 0) ? line_metrics_[line_number - 1].height : 0;