From 65a33037aca51b85f2e21bb3881ce9cc6f496c37 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 20 Oct 2017 11:50:21 -0700 Subject: [PATCH] libtxt: better accuracy for text justification (flutter/engine#4255) * do not reset the justify offset after each run within a line * track word start/end ranges relative to the start of the text instead of the line --- .../src/flutter/third_party/txt/src/txt/paragraph.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 58f4d2d647..63f6954815 100644 --- a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc +++ b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc @@ -132,12 +132,12 @@ void FindWords(const std::vector& text, word_start = i; in_word = true; } else if (in_word && is_space) { - words->emplace_back(word_start - start, i - start); + words->emplace_back(word_start, i); in_word = false; } } if (in_word) - words->emplace_back(word_start - start, end - start); + words->emplace_back(word_start, end); } } // namespace @@ -318,6 +318,7 @@ void Paragraph::Layout(double width, bool force) { std::vector glyph_single_line_position_x; double run_x_offset = GetLineXOffset(line_number); + double justify_x_offset = 0; std::vector paint_records; for (const StyledRuns::Run& run : line_runs) { @@ -393,7 +394,6 @@ void Paragraph::Layout(double width, bool force) { blob_start += blob_len; } - double justify_x_offset = 0; size_t code_unit_index = 0; double word_start_position = std::numeric_limits::quiet_NaN(); @@ -413,7 +413,7 @@ void Paragraph::Layout(double width, bool force) { blob_buffer.pos[pos_index + 1] = layout.getY(glyph_index); if (word_index < words.size() && - code_unit_index == words[word_index].start) { + words[word_index].start == line_run_start + code_unit_index) { word_start_position = run_x_offset + glyph_x_offset; } @@ -448,7 +448,7 @@ void Paragraph::Layout(double width, bool force) { } if (word_index < words.size() && - code_unit_index == words[word_index].end) { + words[word_index].end == line_run_start + code_unit_index) { if (justify_line) justify_x_offset += word_gap_width; word_index++;