From f31724a16c42d54aa939313a50ba4969235094ab Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 14 Jun 2018 16:14:37 -0700 Subject: [PATCH] libtxt: fix the adjustment of code unit runs for line justification (flutter/engine#5536) Fixes https://github.com/flutter/flutter/issues/18483 --- .../flutter/third_party/txt/src/txt/paragraph.cc | 13 ++++++++----- .../src/flutter/third_party/txt/src/txt/paragraph.h | 10 ++++++++++ 2 files changed, 18 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 78b2ef8be9..cc247dd107 100644 --- a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc +++ b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc @@ -192,8 +192,7 @@ Paragraph::GlyphPosition::GlyphPosition(double x_start, x_pos(x_start, x_start + x_advance) {} void Paragraph::GlyphPosition::Shift(double delta) { - x_pos.start += delta; - x_pos.end += delta; + x_pos.Shift(delta); } Paragraph::GlyphLine::GlyphLine(std::vector&& p, size_t tcu) @@ -212,6 +211,12 @@ Paragraph::CodeUnitRun::CodeUnitRun(std::vector&& p, font_metrics(metrics), direction(dir) {} +void Paragraph::CodeUnitRun::Shift(double delta) { + x_pos.Shift(delta); + for (GlyphPosition& position : positions) + position.Shift(delta); +} + Paragraph::Paragraph() { breaker_.setLocale(icu::Locale(), nullptr); } @@ -697,9 +702,7 @@ void Paragraph::Layout(double width, bool force) { double line_x_offset = GetLineXOffset(run_x_offset); if (line_x_offset) { for (CodeUnitRun& code_unit_run : line_code_unit_runs) { - for (GlyphPosition& position : code_unit_run.positions) { - position.Shift(line_x_offset); - } + code_unit_run.Shift(line_x_offset); } for (GlyphPosition& position : line_glyph_positions) { position.Shift(line_x_offset); diff --git a/engine/src/flutter/third_party/txt/src/txt/paragraph.h b/engine/src/flutter/third_party/txt/src/txt/paragraph.h index edbff5e56a..bc8dc3ea93 100644 --- a/engine/src/flutter/third_party/txt/src/txt/paragraph.h +++ b/engine/src/flutter/third_party/txt/src/txt/paragraph.h @@ -73,11 +73,19 @@ class Paragraph { struct Range { Range() : start(), end() {} Range(T s, T e) : start(s), end(e) {} + T start, end; + bool operator==(const Range& other) const { return start == other.start && end == other.end; } + T width() { return end - start; } + + void Shift(T delta) { + start += delta; + end += delta; + } }; // Minikin Layout doLayout() and LineBreaker addStyleRun() has an @@ -260,6 +268,8 @@ class Paragraph { size_t line, const SkPaint::FontMetrics& metrics, TextDirection dir); + + void Shift(double delta); }; // Holds the laid out x positions of each glyph.