From e7c2f2dfb6e3b193304cc92bf2da7276a42a4735 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 16 Jan 2018 10:39:31 -0800 Subject: [PATCH] libtxt: skip redundant bidi processing performed by minikin (flutter/engine#4539) The libtxt Paragraph class now runs the bidi algorithm itself, and each text run passed to doLayout will be entirely LTR or RTL --- .../third_party/txt/src/minikin/Layout.cpp | 23 ++++++------------- .../third_party/txt/src/minikin/Layout.h | 4 ++-- .../third_party/txt/src/txt/paragraph.cc | 12 ++++------ 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/engine/src/flutter/third_party/txt/src/minikin/Layout.cpp b/engine/src/flutter/third_party/txt/src/minikin/Layout.cpp index b361f3010d0..32961710692 100644 --- a/engine/src/flutter/third_party/txt/src/minikin/Layout.cpp +++ b/engine/src/flutter/third_party/txt/src/minikin/Layout.cpp @@ -600,7 +600,7 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - int bidiFlags, + bool isRtl, const FontStyle& style, const MinikinPaint& paint, const std::shared_ptr& collection) { @@ -613,11 +613,9 @@ void Layout::doLayout(const uint16_t* buf, reset(); mAdvances.resize(count, 0); - for (const BidiText::Iter::RunInfo& runInfo : - BidiText(buf, start, count, bufSize, bidiFlags)) { - doLayoutRunCached(buf, runInfo.mRunStart, runInfo.mRunLength, bufSize, - runInfo.mIsRtl, &ctx, start, collection, this, NULL); - } + doLayoutRunCached(buf, start, count, bufSize, isRtl, &ctx, start, collection, + this, NULL); + ctx.clearHbFonts(); } @@ -625,7 +623,7 @@ float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - int bidiFlags, + bool isRtl, const FontStyle& style, const MinikinPaint& paint, const std::shared_ptr& collection, @@ -636,15 +634,8 @@ float Layout::measureText(const uint16_t* buf, ctx.style = style; ctx.paint = paint; - float advance = 0; - for (const BidiText::Iter::RunInfo& runInfo : - BidiText(buf, start, count, bufSize, bidiFlags)) { - float* advancesForRun = - advances ? advances + (runInfo.mRunStart - start) : advances; - advance += doLayoutRunCached(buf, runInfo.mRunStart, runInfo.mRunLength, - bufSize, runInfo.mIsRtl, &ctx, 0, collection, - NULL, advancesForRun); - } + float advance = doLayoutRunCached(buf, start, count, bufSize, isRtl, &ctx, 0, + collection, NULL, advances); ctx.clearHbFonts(); return advance; diff --git a/engine/src/flutter/third_party/txt/src/minikin/Layout.h b/engine/src/flutter/third_party/txt/src/minikin/Layout.h index 90476ee03d8..3b60ef6817d 100644 --- a/engine/src/flutter/third_party/txt/src/minikin/Layout.h +++ b/engine/src/flutter/third_party/txt/src/minikin/Layout.h @@ -74,7 +74,7 @@ class Layout { size_t start, size_t count, size_t bufSize, - int bidiFlags, + bool isRtl, const FontStyle& style, const MinikinPaint& paint, const std::shared_ptr& collection); @@ -83,7 +83,7 @@ class Layout { size_t start, size_t count, size_t bufSize, - int bidiFlags, + bool isRtl, const FontStyle& style, const MinikinPaint& paint, const std::shared_ptr& collection, 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 a91aeadfa69..127c22061b4 100644 --- a/engine/src/flutter/third_party/txt/src/txt/paragraph.cc +++ b/engine/src/flutter/third_party/txt/src/txt/paragraph.cc @@ -429,9 +429,6 @@ void Paragraph::Layout(double width, bool force) { uint16_t* text_ptr = text_.data(); size_t text_start = run.start; size_t text_count = run.end - run.start; - int bidiFlags = (paragraph_style_.text_direction == TextDirection::rtl) - ? minikin::kBidi_RTL - : minikin::kBidi_LTR; // Apply ellipsizing if the run was not completely laid out and this // is the last line (or lines are unlimited). @@ -442,12 +439,12 @@ void Paragraph::Layout(double width, bool force) { paragraph_style_.unlimited_lines())) { float ellipsis_width = layout.measureText( reinterpret_cast(ellipsis.data()), 0, - ellipsis.length(), ellipsis.length(), bidiFlags, font, + ellipsis.length(), ellipsis.length(), run.is_rtl(), font, minikin_paint, minikin_font_collection, nullptr); std::vector text_advances(text_count); float text_width = layout.measureText( - text_ptr, text_start, text_count, text_.size(), bidiFlags, font, + text_ptr, text_start, text_count, text_.size(), run.is_rtl(), font, minikin_paint, minikin_font_collection, text_advances.data()); // Truncate characters from the text until the ellipsis fits. @@ -477,8 +474,9 @@ void Paragraph::Layout(double width, bool force) { } } - layout.doLayout(text_ptr, text_start, text_count, text_.size(), bidiFlags, - font, minikin_paint, minikin_font_collection); + layout.doLayout(text_ptr, text_start, text_count, text_.size(), + run.is_rtl(), font, minikin_paint, + minikin_font_collection); if (layout.nGlyphs() == 0) continue;