diff --git a/display_list/BUILD.gn b/display_list/BUILD.gn index 6c55f2c835741..2e93c2002b0f5 100644 --- a/display_list/BUILD.gn +++ b/display_list/BUILD.gn @@ -158,6 +158,7 @@ if (enable_unittests) { "//flutter/display_list/testing:display_list_testing", "//flutter/impeller/typographer/backends/skia:typographer_skia_backend", "//flutter/testing", + "//flutter/third_party/txt", ] if (!defined(defines)) { diff --git a/display_list/testing/BUILD.gn b/display_list/testing/BUILD.gn index 57b0794a8bac6..f94799b9729af 100644 --- a/display_list/testing/BUILD.gn +++ b/display_list/testing/BUILD.gn @@ -17,6 +17,7 @@ source_set("display_list_testing") { deps = [ "//flutter/skia", "//flutter/testing:testing_lib", + "//flutter/third_party/txt", ] public_deps = [ "//flutter/display_list:display_list" ] diff --git a/display_list/testing/dl_rendering_unittests.cc b/display_list/testing/dl_rendering_unittests.cc index fbc81029e65a0..e2b7707a20048 100644 --- a/display_list/testing/dl_rendering_unittests.cc +++ b/display_list/testing/dl_rendering_unittests.cc @@ -23,15 +23,18 @@ #include "third_party/skia/include/core/SkBBHFactory.h" #include "third_party/skia/include/core/SkColorFilter.h" +#include "third_party/skia/include/core/SkFontMgr.h" #include "third_party/skia/include/core/SkPictureRecorder.h" #include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkSurface.h" +#include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "third_party/skia/include/effects/SkImageFilters.h" #include "third_party/skia/include/encode/SkPngEncoder.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/GrRecordingContext.h" #include "third_party/skia/include/gpu/GrTypes.h" +#include "txt/platform.h" namespace flutter { namespace testing { @@ -2747,7 +2750,8 @@ class CanvasCompareTester { static sk_sp MakeTextBlob(const std::string& string, SkScalar font_height) { - SkFont font(SkTypeface::MakeFromName("ahem", SkFontStyle::Normal()), + SkFont font(txt::GetDefaultFontManager()->matchFamilyStyle( + "ahem", SkFontStyle::Normal()), font_height); return SkTextBlob::MakeFromText(string.c_str(), string.size(), font, SkTextEncoding::kUTF8); diff --git a/display_list/testing/dl_test_snippets.cc b/display_list/testing/dl_test_snippets.cc index 76d8a875d7180..c831005482cbb 100644 --- a/display_list/testing/dl_test_snippets.cc +++ b/display_list/testing/dl_test_snippets.cc @@ -5,6 +5,9 @@ #include "flutter/display_list/testing/dl_test_snippets.h" #include "flutter/display_list/dl_builder.h" #include "flutter/display_list/dl_op_receiver.h" +#include "third_party/skia/include/core/SkFontMgr.h" +#include "third_party/skia/include/core/SkTypeface.h" +#include "txt/platform.h" namespace flutter { namespace testing { @@ -978,7 +981,7 @@ SkFont CreateTestFontOfSize(SkScalar scalar) { static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf"; auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture); FML_CHECK(mapping); - return SkFont{SkTypeface::MakeFromData(mapping), scalar}; + return SkFont{txt::GetDefaultFontManager()->makeFromData(mapping), scalar}; } sk_sp GetTestTextBlob(int index) { diff --git a/flow/BUILD.gn b/flow/BUILD.gn index e82db9624925a..c8a59f4a3c00e 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -94,6 +94,7 @@ source_set("flow") { "//flutter/common/graphics", "//flutter/display_list", "//flutter/fml", + "//flutter/third_party/txt", ] deps = [ "//flutter/skia" ] diff --git a/flow/layers/performance_overlay_layer.cc b/flow/layers/performance_overlay_layer.cc index 55d056476f029..e2bfd9e473f41 100644 --- a/flow/layers/performance_overlay_layer.cc +++ b/flow/layers/performance_overlay_layer.cc @@ -13,7 +13,10 @@ #include "flow/stopwatch_dl.h" #include "flow/stopwatch_sk.h" #include "third_party/skia/include/core/SkFont.h" +#include "third_party/skia/include/core/SkFontMgr.h" #include "third_party/skia/include/core/SkTextBlob.h" +#include "third_party/skia/include/core/SkTypeface.h" +#include "txt/platform.h" #ifdef IMPELLER_SUPPORTS_RENDERING #include "impeller/typographer/backends/skia/text_frame_skia.h" // nogncheck #endif // IMPELLER_SUPPORTS_RENDERING @@ -72,7 +75,8 @@ sk_sp PerformanceOverlayLayer::MakeStatisticsText( const std::string& font_path) { SkFont font; if (font_path != "") { - font = SkFont(SkTypeface::MakeFromFile(font_path.c_str())); + sk_sp font_mgr = txt::GetDefaultFontManager(); + font = SkFont(font_mgr->makeFromFile(font_path.c_str())); } font.setSize(15); diff --git a/impeller/aiks/BUILD.gn b/impeller/aiks/BUILD.gn index f341021bdf5d3..bee4bd84c795f 100644 --- a/impeller/aiks/BUILD.gn +++ b/impeller/aiks/BUILD.gn @@ -88,6 +88,7 @@ impeller_component("aiks_unittests") { "//flutter/impeller/scene", "//flutter/impeller/typographer/backends/stb:typographer_stb_backend", "//flutter/testing:testing_lib", + "//flutter/third_party/txt", ] if (!impeller_trace_canvas) { @@ -119,5 +120,6 @@ impeller_component("aiks_unittests_golden") { "//flutter/impeller/scene", "//flutter/impeller/typographer/backends/stb:typographer_stb_backend", "//flutter/testing:testing_lib", + "//flutter/third_party/txt", ] } diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 445340a8c32b9..372c34f563223 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -46,6 +46,9 @@ #include "impeller/typographer/backends/stb/typographer_context_stb.h" #include "third_party/imgui/imgui.h" #include "third_party/skia/include/core/SkData.h" +#include "third_party/skia/include/core/SkFontMgr.h" +#include "third_party/skia/include/core/SkTypeface.h" +#include "txt/platform.h" namespace impeller { namespace testing { @@ -1398,7 +1401,8 @@ bool RenderTextInCanvasSkia(const std::shared_ptr& context, if (!mapping) { return false; } - SkFont sk_font(SkTypeface::MakeFromData(mapping), options.font_size); + sk_sp font_mgr = txt::GetDefaultFontManager(); + SkFont sk_font(font_mgr->makeFromData(mapping), options.font_size); auto blob = SkTextBlob::MakeFromString(text.c_str(), sk_font); if (!blob) { return false; @@ -1576,7 +1580,8 @@ TEST_P(AiksTest, CanRenderTextOutsideBoundaries) { ASSERT_NE(mapping, nullptr); Scalar font_size = 80; - SkFont sk_font(SkTypeface::MakeFromData(mapping), font_size); + sk_sp font_mgr = txt::GetDefaultFontManager(); + SkFont sk_font(font_mgr->makeFromData(mapping), font_size); Paint text_paint; text_paint.color = Color::Blue().WithAlpha(0.8); @@ -3449,7 +3454,8 @@ TEST_P(AiksTest, TextForegroundShaderWithTransform) { ASSERT_NE(mapping, nullptr); Scalar font_size = 100; - SkFont sk_font(SkTypeface::MakeFromData(mapping), font_size); + sk_sp font_mgr = txt::GetDefaultFontManager(); + SkFont sk_font(font_mgr->makeFromData(mapping), font_size); Paint text_paint; text_paint.color = Color::Blue(); diff --git a/impeller/display_list/BUILD.gn b/impeller/display_list/BUILD.gn index daa2dc10168f4..d5acdc83a74ae 100644 --- a/impeller/display_list/BUILD.gn +++ b/impeller/display_list/BUILD.gn @@ -63,6 +63,7 @@ impeller_component("display_list_unittests") { "../playground:playground_test", "//flutter/impeller/scene", "//flutter/impeller/typographer/backends/stb:typographer_stb_backend", + "//flutter/third_party/txt", ] if (!defined(defines)) { diff --git a/impeller/display_list/dl_playground.cc b/impeller/display_list/dl_playground.cc index 8565e9b1f9cbc..ba94de2be370a 100644 --- a/impeller/display_list/dl_playground.cc +++ b/impeller/display_list/dl_playground.cc @@ -10,6 +10,9 @@ #include "impeller/typographer/backends/skia/typographer_context_skia.h" #include "third_party/imgui/imgui.h" #include "third_party/skia/include/core/SkData.h" +#include "third_party/skia/include/core/SkFontMgr.h" +#include "third_party/skia/include/core/SkTypeface.h" +#include "txt/platform.h" namespace impeller { @@ -56,7 +59,8 @@ SkFont DlPlayground::CreateTestFontOfSize(SkScalar scalar) { static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf"; auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture); FML_CHECK(mapping); - return SkFont{SkTypeface::MakeFromData(mapping), scalar}; + sk_sp font_mgr = txt::GetDefaultFontManager(); + return SkFont{font_mgr->makeFromData(mapping), scalar}; } SkFont DlPlayground::CreateTestFont() { diff --git a/impeller/typographer/typographer_unittests.cc b/impeller/typographer/typographer_unittests.cc index f8fa84eb8fc91..c1b2575e4478c 100644 --- a/impeller/typographer/typographer_unittests.cc +++ b/impeller/typographer/typographer_unittests.cc @@ -12,6 +12,7 @@ #include "third_party/skia/include/core/SkFontMgr.h" #include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkTextBlob.h" +#include "third_party/skia/include/core/SkTypeface.h" #include "txt/platform.h" // TODO(zanderso): https://github.com/flutter/flutter/issues/127701 @@ -94,7 +95,8 @@ TEST_P(TypographerTest, LazyAtlasTracksColor) { auto mapping = flutter::testing::OpenFixtureAsSkData("NotoColorEmoji.ttf"); #endif ASSERT_TRUE(mapping); - SkFont emoji_font(SkTypeface::MakeFromData(mapping), 50.0); + sk_sp font_mgr = txt::GetDefaultFontManager(); + SkFont emoji_font(font_mgr->makeFromData(mapping), 50.0); SkFont sk_font; auto blob = SkTextBlob::MakeFromString("hello", sk_font); diff --git a/lib/ui/text/asset_manager_font_provider.cc b/lib/ui/text/asset_manager_font_provider.cc index 92f9b88c55bf6..519da3726e676 100644 --- a/lib/ui/text/asset_manager_font_provider.cc +++ b/lib/ui/text/asset_manager_font_provider.cc @@ -8,9 +8,11 @@ #include "flutter/fml/logging.h" #include "third_party/skia/include/core/SkData.h" +#include "third_party/skia/include/core/SkFontMgr.h" #include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkString.h" #include "third_party/skia/include/core/SkTypeface.h" +#include "txt/platform.h" namespace flutter { @@ -116,8 +118,9 @@ auto AssetManagerFontStyleSet::createTypeface(int i) -> CreateTypefaceRet { MappingReleaseProc, asset_mapping_ptr); std::unique_ptr stream = SkMemoryStream::Make(asset_data); + sk_sp font_mgr = txt::GetDefaultFontManager(); // Ownership of the stream is transferred. - asset.typeface = SkTypeface::MakeFromStream(std::move(stream)); + asset.typeface = font_mgr->makeFromStream(std::move(stream)); if (!asset.typeface) { FML_DLOG(ERROR) << "Unable to load font asset for family: " << family_name_; diff --git a/lib/ui/text/font_collection.cc b/lib/ui/text/font_collection.cc index 86225d4ad8df9..34ff63ea87df6 100644 --- a/lib/ui/text/font_collection.cc +++ b/lib/ui/text/font_collection.cc @@ -21,7 +21,9 @@ #include "third_party/tonic/logging/dart_invoke.h" #include "third_party/tonic/typed_data/typed_list.h" #include "txt/asset_font_manager.h" +#include "txt/platform.h" #include "txt/test_font_manager.h" + #if FML_OS_MACOSX || FML_OS_IOS #include "txt/platform_mac.h" #endif @@ -158,8 +160,8 @@ void FontCollection::LoadFontFromList(Dart_Handle font_data_handle, std::unique_ptr font_stream = std::make_unique( font_data.data(), font_data.num_elements(), true); - sk_sp typeface = - SkTypeface::MakeFromStream(std::move(font_stream)); + sk_sp font_mgr = txt::GetDefaultFontManager(); + sk_sp typeface = font_mgr->makeFromStream(std::move(font_stream)); txt::TypefaceFontAssetProvider& font_provider = font_collection.dynamic_font_manager_->font_provider(); if (family_name.empty()) { diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index a5d7874fb873e..160b3f6bc536f 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -10,7 +10,10 @@ source_set("test_font") { "test_font_data.cc", "test_font_data.h", ] - deps = [ "//flutter/skia" ] + deps = [ + "//flutter/skia", + "//flutter/third_party/txt", + ] public_configs = [ "//flutter:config" ] defines = [] if (flutter_runtime_mode == "debug" || current_toolchain == host_toolchain) { diff --git a/runtime/test_font_data.cc b/runtime/test_font_data.cc index 3dbe58f2548bd..17a0d0c6db003 100644 --- a/runtime/test_font_data.cc +++ b/runtime/test_font_data.cc @@ -46,6 +46,10 @@ #if EMBED_TEST_FONT_DATA +#include "third_party/skia/include/core/SkFontMgr.h" +#include "third_party/skia/include/core/SkTypeface.h" +#include "txt/platform.h" + static const unsigned char kAhemFont[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x80, 0x00, 0x03, 0x00, 0x30, 0x4f, 0x53, 0x2f, 0x32, 0x77, 0x60, 0xf9, 0x6f, 0x00, 0x00, 0x01, 0x38, @@ -1621,11 +1625,12 @@ namespace flutter { std::vector> GetTestFontData() { std::vector> typefaces; #if EMBED_TEST_FONT_DATA - typefaces.push_back(SkTypeface::MakeFromStream( + sk_sp font_mgr = txt::GetDefaultFontManager(); + typefaces.push_back(font_mgr->makeFromStream( SkMemoryStream::MakeDirect(kFlutterTestFont, kFlutterTestFontLength))); - typefaces.push_back(SkTypeface::MakeFromStream( + typefaces.push_back(font_mgr->makeFromStream( SkMemoryStream::MakeDirect(kAhemFont, kAhemFontLength))); - typefaces.push_back(SkTypeface::MakeFromStream( + typefaces.push_back(font_mgr->makeFromStream( SkMemoryStream::MakeDirect(kCoughFont, kCoughFontLength))); #endif // EMBED_TEST_FONT_DATA return typefaces;