diff --git a/engine/src/flutter/lib/web_ui/skwasm/text/paragraph_builder.cpp b/engine/src/flutter/lib/web_ui/skwasm/text/paragraph_builder.cpp index 29e659dd91..b573d31e02 100644 --- a/engine/src/flutter/lib/web_ui/skwasm/text/paragraph_builder.cpp +++ b/engine/src/flutter/lib/web_ui/skwasm/text/paragraph_builder.cpp @@ -5,6 +5,7 @@ #include "../export.h" #include "../wrappers.h" #include "third_party/skia/modules/skparagraph/include/ParagraphBuilder.h" +#include "third_party/skia/modules/skunicode/include/SkUnicode_client.h" using namespace skia::textlayout; using namespace Skwasm; @@ -12,7 +13,8 @@ using namespace Skwasm; SKWASM_EXPORT ParagraphBuilder* paragraphBuilder_create( ParagraphStyle* style, FlutterFontCollection* collection) { - return ParagraphBuilder::make(*style, collection->collection).release(); + return ParagraphBuilder::make(*style, collection->collection, nullptr) + .release(); } SKWASM_EXPORT void paragraphBuilder_dispose(ParagraphBuilder* builder) { @@ -52,6 +54,11 @@ SKWASM_EXPORT void paragraphBuilder_pop(ParagraphBuilder* builder) { } SKWASM_EXPORT Paragraph* paragraphBuilder_build(ParagraphBuilder* builder) { + auto [words, graphemeBreaks, lineBreaks] = builder->getClientICUData(); + auto text = builder->getText(); + sk_sp clientICU = + SkUnicodes::Client::Make(text, words, graphemeBreaks, lineBreaks); + builder->SetUnicode(clientICU); return builder->Build().release(); } diff --git a/engine/src/flutter/skia/flutter_defines.gni b/engine/src/flutter/skia/flutter_defines.gni index 2c08f76cba..f3a5fc623b 100644 --- a/engine/src/flutter/skia/flutter_defines.gni +++ b/engine/src/flutter/skia/flutter_defines.gni @@ -13,6 +13,7 @@ flutter_defines = [ "SK_LEGACY_IGNORE_DRAW_VERTICES_BLEND_WITH_NO_SHADER", "SK_RESOLVE_FILTERS_BEFORE_RESTORE", "SK_DISABLE_LEGACY_METAL_BACKEND_SURFACE", + "SK_DISABLE_LEGACY_PARAGRAPH_UNICODE", # Fast low-precision software rendering isn't a priority for Flutter. "SK_DISABLE_LEGACY_SHADERCONTEXT", diff --git a/engine/src/flutter/third_party/txt/benchmarks/skparagraph_benchmarks.cc b/engine/src/flutter/third_party/txt/benchmarks/skparagraph_benchmarks.cc index 7dd27bdb6a..7f9fd9520f 100644 --- a/engine/src/flutter/third_party/txt/benchmarks/skparagraph_benchmarks.cc +++ b/engine/src/flutter/third_party/txt/benchmarks/skparagraph_benchmarks.cc @@ -28,6 +28,7 @@ #include "third_party/skia/modules/skparagraph/include/ParagraphBuilder.h" #include "third_party/skia/modules/skparagraph/include/TypefaceFontProvider.h" #include "third_party/skia/modules/skparagraph/utils/TestFontCollection.h" +#include "third_party/skia/modules/skunicode/include/SkUnicode_icu.h" namespace sktxt = skia::textlayout; @@ -55,7 +56,7 @@ BENCHMARK_F(SkParagraphFixture, ShortLayout)(benchmark::State& state) { text_style.setFontFamilies({SkString("Roboto")}); text_style.setColor(SK_ColorBLACK); auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); builder->pushStyle(text_style); builder->addText(text); builder->pop(); @@ -90,7 +91,7 @@ BENCHMARK_F(SkParagraphFixture, LongLayout)(benchmark::State& state) { text_style.setFontFamilies({SkString("Roboto")}); text_style.setColor(SK_ColorBLACK); auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); builder->pushStyle(text_style); builder->addText(text); builder->pop(); @@ -126,7 +127,7 @@ BENCHMARK_F(SkParagraphFixture, JustifyLayout)(benchmark::State& state) { text_style.setFontFamilies({SkString("Roboto")}); text_style.setColor(SK_ColorBLACK); auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); builder->pushStyle(text_style); builder->addText(text); builder->pop(); @@ -144,7 +145,7 @@ BENCHMARK_F(SkParagraphFixture, ManyStylesLayout)(benchmark::State& state) { text_style.setFontFamilies({SkString("Roboto")}); text_style.setColor(SK_ColorBLACK); auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); for (int i = 0; i < 1000; ++i) { builder->pushStyle(text_style); builder->addText(text); @@ -167,7 +168,7 @@ BENCHMARK_DEFINE_F(SkParagraphFixture, TextBigO)(benchmark::State& state) { text_style.setFontFamilies({SkString("Roboto")}); text_style.setColor(SK_ColorBLACK); auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); builder->pushStyle(text_style); builder->addText(u16_text); builder->pop(); @@ -191,7 +192,8 @@ BENCHMARK_DEFINE_F(SkParagraphFixture, StylesBigO)(benchmark::State& state) { text_style.setColor(SK_ColorBLACK); auto builder = sktxt::ParagraphBuilder::make( paragraph_style, - sk_make_sp(txt::GetFontDir())); + sk_make_sp(txt::GetFontDir()), + SkUnicodes::ICU::Make()); for (int i = 0; i < 1000; ++i) { builder->pushStyle(text_style); builder->addText(text); @@ -215,7 +217,7 @@ BENCHMARK_F(SkParagraphFixture, PaintSimple)(benchmark::State& state) { text_style.setFontFamilies({SkString("Roboto")}); text_style.setColor(SK_ColorBLACK); auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); builder->pushStyle(text_style); builder->addText(text); builder->pop(); @@ -253,7 +255,7 @@ BENCHMARK_F(SkParagraphFixture, PaintLarge)(benchmark::State& state) { text_style.setFontFamilies({SkString("Roboto")}); text_style.setColor(SK_ColorBLACK); auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); builder->pushStyle(text_style); builder->addText(text); builder->pop(); @@ -278,7 +280,7 @@ BENCHMARK_F(SkParagraphFixture, PaintDecoration)(benchmark::State& state) { sktxt::TextDecoration::kLineThrough | sktxt::TextDecoration::kOverline | sktxt::TextDecoration::kUnderline)); auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); text_style.setDecorationStyle(sktxt::TextDecorationStyle::kSolid); builder->pushStyle(text_style); builder->addText(text); @@ -308,7 +310,7 @@ BENCHMARK_F(SkParagraphFixture, SimpleBuilder)(benchmark::State& state) { text_style.setColor(SK_ColorBLACK); while (state.KeepRunning()) { auto builder = - sktxt::ParagraphBuilder::make(paragraph_style, font_collection_); + sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make()); builder->pushStyle(text_style); builder->addText(text); builder->pop(); diff --git a/engine/src/flutter/third_party/txt/src/skia/paragraph_builder_skia.cc b/engine/src/flutter/third_party/txt/src/skia/paragraph_builder_skia.cc index 46f6d4aa60..0468e5f554 100644 --- a/engine/src/flutter/third_party/txt/src/skia/paragraph_builder_skia.cc +++ b/engine/src/flutter/third_party/txt/src/skia/paragraph_builder_skia.cc @@ -19,6 +19,7 @@ #include "third_party/skia/modules/skparagraph/include/ParagraphStyle.h" #include "third_party/skia/modules/skparagraph/include/TextStyle.h" +#include "third_party/skia/modules/skunicode/include/SkUnicode_icu.h" #include "txt/paragraph_style.h" namespace skt = skia::textlayout; @@ -50,7 +51,9 @@ ParagraphBuilderSkia::ParagraphBuilderSkia( const bool impeller_enabled) : base_style_(style.GetTextStyle()), impeller_enabled_(impeller_enabled) { builder_ = skt::ParagraphBuilder::make( - TxtToSkia(style), font_collection->CreateSktFontCollection()); + TxtToSkia(style), + font_collection->CreateSktFontCollection(), + SkUnicodes::ICU::Make()); } ParagraphBuilderSkia::~ParagraphBuilderSkia() = default;