From b64dcc447086983ab44a45969cf1132455aba4ad Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 26 Jan 2018 13:35:53 -0800 Subject: [PATCH] libtxt: be more resilient if the minikin glyphs and the grapheme breaker get out of sync (flutter/engine#4590) --- .../flutter/third_party/txt/src/txt/paragraph.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 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 4d0a933d50..7f3eb3d48b 100644 --- a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc +++ b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc @@ -545,17 +545,23 @@ void Paragraph::Layout(double width, bool force) { int32_t next_grapheme; if (run.is_rtl()) { next_grapheme = grapheme_breaker_->previous(); + if (next_grapheme == icu::BreakIterator::DONE) + break; subglyph_code_unit_counts.push_back(current_grapheme - next_grapheme); } else { next_grapheme = grapheme_breaker_->next(); + if (next_grapheme == icu::BreakIterator::DONE) + break; subglyph_code_unit_counts.push_back(next_grapheme - current_grapheme); while (next_grapheme < static_cast(text_count)) { if (layout.getCharAdvance(next_grapheme) != 0) break; - size_t sub_grapheme = grapheme_breaker_->current(); - next_grapheme = grapheme_breaker_->next(); + if (grapheme_breaker_->next() == icu::BreakIterator::DONE) + break; + size_t sub_grapheme = next_grapheme; + next_grapheme = grapheme_breaker_->current(); subglyph_code_unit_counts.push_back(next_grapheme - sub_grapheme); } } @@ -590,6 +596,9 @@ void Paragraph::Layout(double width, bool force) { } } + if (glyph_positions.empty()) + continue; + SkPaint::FontMetrics metrics; paint.getFontMetrics(&metrics); paint_records.emplace_back(run.style(), SkPoint::Make(run_x_offset, 0),