diff --git a/engine/src/flutter/third_party/txt/BUILD.gn b/engine/src/flutter/third_party/txt/BUILD.gn index 9079ed1585..4a3a3703ad 100644 --- a/engine/src/flutter/third_party/txt/BUILD.gn +++ b/engine/src/flutter/third_party/txt/BUILD.gn @@ -122,7 +122,14 @@ source_set("txt") { if (enable_unittests) { test_fixtures("txt_fixtures") { - fixtures = [ "third_party/fonts/Roboto-Regular.ttf" ] + fixtures = [ + "third_party/fonts/Roboto-Regular.ttf", + "third_party/fonts/NotoColorEmoji.ttf", + ] + + if (host_os == "mac") { + fixtures += [ "/System/Library/Fonts/Apple Color Emoji.ttc" ] + } } executable("txt_benchmarks") { @@ -176,8 +183,7 @@ if (enable_unittests) { # This is needed for //flutter/third_party/googletest for linking zircon # symbols. if (is_fuchsia) { - libs = - [ "${fuchsia_arch_root}/sysroot/lib/libzircon.so" ] + libs = [ "${fuchsia_arch_root}/sysroot/lib/libzircon.so" ] } } } diff --git a/engine/src/flutter/third_party/txt/src/skia/paragraph_skia.cc b/engine/src/flutter/third_party/txt/src/skia/paragraph_skia.cc index 90193bd33d..1465289a09 100644 --- a/engine/src/flutter/third_party/txt/src/skia/paragraph_skia.cc +++ b/engine/src/flutter/third_party/txt/src/skia/paragraph_skia.cc @@ -87,6 +87,16 @@ class DisplayListParagraphPainter : public skt::ParagraphPainter { if (impeller_enabled_) { if (ShouldRenderAsPath(dl_paints_[paint_id])) { auto path = skia::textlayout::Paragraph::GetPath(blob.get()); + // If there is no path, this is an emoji and should be drawn as is, + // ignoring the color source. + if (path.isEmpty()) { + builder_->DrawTextFrame(impeller::MakeTextFrameFromTextBlobSkia( + blob, dl_paints_[paint_id].getColor()), + x, y, dl_paints_[paint_id]); + + return; + } + auto transformed = path.makeTransform(SkMatrix::Translate( x + blob->bounds().left(), y + blob->bounds().top())); builder_->DrawPath(transformed, dl_paints_[paint_id]); diff --git a/engine/src/flutter/third_party/txt/tests/paragraph_unittests.cc b/engine/src/flutter/third_party/txt/tests/paragraph_unittests.cc index 7eaf771c6c..181a7ef035 100644 --- a/engine/src/flutter/third_party/txt/tests/paragraph_unittests.cc +++ b/engine/src/flutter/third_party/txt/tests/paragraph_unittests.cc @@ -13,10 +13,27 @@ #include "runtime/test_font_data.h" #include "skia/paragraph_builder_skia.h" #include "testing/canvas_test.h" +#include "testing/testing.h" +#include "txt/platform.h" namespace flutter { namespace testing { +static const std::string kEmojiFontFile = +#if FML_OS_MACOSX + "Apple Color Emoji.ttc"; +#else + "NotoColorEmoji.ttf"; +#endif + +static const std::string kEmojiFontName = +#if FML_OS_MACOSX + "Apple Color Emoji"; +#else + "Noto Color Emoji"; +#endif + + //------------------------------------------------------------------------------ /// @brief A custom |DlOpReceiver| that records some |DlOps| it receives. class DlOpRecorder final : public virtual DlOpReceiver, @@ -85,6 +102,15 @@ class PainterTestBase : public CanvasTestBase { return t_style; } + txt::TextStyle makeEmoji() { + auto t_style = txt::TextStyle(); + t_style.color = SK_ColorBLACK; // default + t_style.font_weight = txt::FontWeight::w400; // normal + t_style.font_size = 14; // default + t_style.font_families.push_back(kEmojiFontName); + return t_style; + } + txt::TextStyle makeStyle() { auto t_style = txt::TextStyle(); t_style.color = SK_ColorBLACK; // default @@ -94,6 +120,20 @@ class PainterTestBase : public CanvasTestBase { return t_style; } + sk_sp drawText(txt::TextStyle style, std::u16string text) const { + auto pb_skia = makeParagraphBuilder(); + pb_skia.PushStyle(style); + pb_skia.AddText(text); + pb_skia.Pop(); + + auto builder = DisplayListBuilder(); + auto paragraph = pb_skia.Build(); + paragraph->Layout(10000); + paragraph->Paint(&builder, 0, 0); + + return builder.Build(); + } + sk_sp draw(txt::TextStyle style) const { auto pb_skia = makeParagraphBuilder(); pb_skia.PushStyle(style); @@ -115,6 +155,15 @@ class PainterTestBase : public CanvasTestBase { for (auto& font : GetTestFontData()) { font_provider->RegisterTypeface(font); } + // Load emoji font. + { + auto c_font_fixture = std::string(kEmojiFontFile); + auto mapping = + flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str()); + auto typeface = txt::GetDefaultFontManager()->makeFromData(mapping); + font_provider->RegisterTypeface(typeface); + } + auto manager = sk_make_sp(std::move(font_provider)); f_collection->SetAssetFontManager(manager); return f_collection; @@ -230,6 +279,27 @@ TEST_F(PainterTest, DrawTextWithGradientImpeller) { EXPECT_EQ(recorder.pathCount(), 1); } +TEST_F(PainterTest, DrawEmojiTextWithGradientImpeller) { + PretendImpellerIsEnabled(true); + + auto style = makeEmoji(); + // how do you like my shtyle? + DlPaint foreground; + std::vector colors = {DlColor::kRed(), DlColor::kCyan()}; + std::vector stops = {0.0, 1.0}; + foreground.setColorSource(DlColorSource::MakeLinear( + SkPoint::Make(0, 0), SkPoint::Make(100, 100), 2, colors.data(), + stops.data(), DlTileMode::kClamp)); + style.foreground = foreground; + + auto recorder = DlOpRecorder(); + drawText(style, u"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊")->Dispatch(recorder); + + EXPECT_EQ(recorder.textFrameCount(), 1); + EXPECT_EQ(recorder.blobCount(), 0); + EXPECT_EQ(recorder.pathCount(), 0); +} + TEST_F(PainterTest, DrawTextBlobNoImpeller) { PretendImpellerIsEnabled(false);