diff --git a/engine/src/flutter/lib/ui/text/font_collection.cc b/engine/src/flutter/lib/ui/text/font_collection.cc index 68e0c02349b..d6407f9ed42 100644 --- a/engine/src/flutter/lib/ui/text/font_collection.cc +++ b/engine/src/flutter/lib/ui/text/font_collection.cc @@ -25,7 +25,7 @@ FontCollection& FontCollection::ForProcess() { FontCollection::FontCollection() : collection_(std::make_shared()) { - collection_->PushBack(SkFontMgr::RefDefault()); + collection_->SetDefaultFontManager(SkFontMgr::RefDefault()); } FontCollection::~FontCollection() = default; @@ -106,7 +106,7 @@ void FontCollection::RegisterFontsFromAssetProvider( } } - collection_->PushFront( + collection_->SetAssetFontManager( sk_make_sp(std::move(font_asset_data_provider))); } @@ -120,7 +120,7 @@ void FontCollection::RegisterTestFonts() { asset_data_provider->RegisterTypeface(std::move(test_typeface), GetTestFontFamilyName()); - collection_->PushFront(sk_make_sp( + collection_->SetTestFontManager(sk_make_sp( std::move(asset_data_provider), GetTestFontFamilyName())); collection_->DisableFontFallback(); diff --git a/engine/src/flutter/third_party/txt/benchmarks/utils.cc b/engine/src/flutter/third_party/txt/benchmarks/utils.cc index 16cfa81ebb6..f5164f2038b 100644 --- a/engine/src/flutter/third_party/txt/benchmarks/utils.cc +++ b/engine/src/flutter/third_party/txt/benchmarks/utils.cc @@ -44,7 +44,7 @@ void SetCommandLine(fxl::CommandLine cmd) { std::shared_ptr GetTestFontCollection() { auto collection = std::make_shared(); - collection->PushBack(sk_make_sp( + collection->SetAssetFontManager(sk_make_sp( std::make_unique(GetFontDir()))); return collection; } diff --git a/engine/src/flutter/third_party/txt/src/txt/font_collection.cc b/engine/src/flutter/third_party/txt/src/txt/font_collection.cc index ad92cf7748c..c74b0d913c4 100644 --- a/engine/src/flutter/third_party/txt/src/txt/font_collection.cc +++ b/engine/src/flutter/third_party/txt/src/txt/font_collection.cc @@ -60,23 +60,31 @@ FontCollection::FontCollection() : enable_font_fallback_(true) {} FontCollection::~FontCollection() = default; size_t FontCollection::GetFontManagersCount() const { - return skia_font_managers_.size(); + return GetFontManagerOrder().size(); } -void FontCollection::PushFront(sk_sp skia_font_manager) { - if (!skia_font_manager) { - return; - } - UpdateFallbackFonts(skia_font_manager); - skia_font_managers_.push_front(std::move(skia_font_manager)); +void FontCollection::SetDefaultFontManager(sk_sp font_manager) { + default_font_manager_ = font_manager; } -void FontCollection::PushBack(sk_sp skia_font_manager) { - if (!skia_font_manager) { - return; - } - UpdateFallbackFonts(skia_font_manager); - skia_font_managers_.push_back(std::move(skia_font_manager)); +void FontCollection::SetAssetFontManager(sk_sp font_manager) { + asset_font_manager_ = font_manager; +} + +void FontCollection::SetTestFontManager(sk_sp font_manager) { + test_font_manager_ = font_manager; +} + +// Return the available font managers in the order they should be queried. +std::vector> FontCollection::GetFontManagerOrder() const { + std::vector> order; + if (test_font_manager_) + order.push_back(test_font_manager_); + if (asset_font_manager_) + order.push_back(asset_font_manager_); + if (default_font_manager_) + order.push_back(default_font_manager_); + return order; } void FontCollection::DisableFontFallback() { @@ -91,7 +99,7 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { return cached->second; } - for (sk_sp manager : skia_font_managers_) { + for (sk_sp& manager : GetFontManagerOrder()) { auto font_style_set = manager->matchFamily(family.c_str()); if (font_style_set == nullptr || font_style_set->count() == 0) { continue; @@ -157,7 +165,7 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { const std::shared_ptr& FontCollection::MatchFallbackFont( uint32_t ch) { - for (const auto& manager : skia_font_managers_) { + for (const sk_sp& manager : GetFontManagerOrder()) { sk_sp typeface( manager->matchFamilyStyleCharacter(0, SkFontStyle(), nullptr, 0, ch)); if (!typeface) diff --git a/engine/src/flutter/third_party/txt/src/txt/font_collection.h b/engine/src/flutter/third_party/txt/src/txt/font_collection.h index 0f761affd7c..d3ddacc3856 100644 --- a/engine/src/flutter/third_party/txt/src/txt/font_collection.h +++ b/engine/src/flutter/third_party/txt/src/txt/font_collection.h @@ -39,9 +39,9 @@ class FontCollection : public std::enable_shared_from_this { size_t GetFontManagersCount() const; - void PushFront(sk_sp skia_font_manager); - - void PushBack(sk_sp skia_font_manager); + void SetDefaultFontManager(sk_sp font_manager); + void SetAssetFontManager(sk_sp font_manager); + void SetTestFontManager(sk_sp font_manager); std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family); @@ -53,7 +53,9 @@ class FontCollection : public std::enable_shared_from_this { void DisableFontFallback(); private: - std::deque> skia_font_managers_; + sk_sp default_font_manager_; + sk_sp asset_font_manager_; + sk_sp test_font_manager_; std::unordered_map> font_collections_cache_; std::unordered_map> @@ -61,6 +63,8 @@ class FontCollection : public std::enable_shared_from_this { std::shared_ptr null_family_; bool enable_font_fallback_; + std::vector> GetFontManagerOrder() const; + const std::shared_ptr& GetFontFamilyForTypeface( const sk_sp& typeface); diff --git a/engine/src/flutter/third_party/txt/tests/render_test.cc b/engine/src/flutter/third_party/txt/tests/render_test.cc index bab6c8e582e..802ebbfd6ce 100644 --- a/engine/src/flutter/third_party/txt/tests/render_test.cc +++ b/engine/src/flutter/third_party/txt/tests/render_test.cc @@ -30,7 +30,7 @@ namespace txt { RenderTest::RenderTest() : snapshots_(0), font_collection_(std::make_shared()) { - font_collection_->PushBack(sk_make_sp( + font_collection_->SetAssetFontManager(sk_make_sp( std::make_unique(GetFontDir()))); }