diff --git a/engine/src/flutter/lib/ui/text/font_collection.cc b/engine/src/flutter/lib/ui/text/font_collection.cc index cc47fe0613..5a8baa3d25 100644 --- a/engine/src/flutter/lib/ui/text/font_collection.cc +++ b/engine/src/flutter/lib/ui/text/font_collection.cc @@ -122,6 +122,8 @@ void FontCollection::RegisterTestFonts() { collection_->PushFront(sk_make_sp( std::move(asset_data_provider), GetTestFontFamilyName())); + + collection_->DisableFontFallback(); } } // namespace blink 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 1bca40a08e..46b9a8fcfa 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 @@ -64,7 +64,7 @@ class TxtFallbackFontProvider std::shared_ptr font_collection_; }; -FontCollection::FontCollection() = default; +FontCollection::FontCollection() : enable_font_fallback_(true) {} FontCollection::~FontCollection() = default; @@ -88,6 +88,10 @@ void FontCollection::PushBack(sk_sp skia_font_manager) { skia_font_managers_.push_back(std::move(skia_font_manager)); } +void FontCollection::DisableFontFallback() { + enable_font_fallback_ = false; +} + std::shared_ptr FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { // Look inside the font collections cache first. @@ -132,14 +136,18 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { std::vector> minikin_families = { minikin_family, }; - for (const auto& fallback : fallback_fonts_) - minikin_families.push_back(fallback.second); + if (enable_font_fallback_) { + for (const auto& fallback : fallback_fonts_) + minikin_families.push_back(fallback.second); + } // Create the minikin font collection. auto font_collection = std::make_shared(std::move(minikin_families)); - font_collection->set_fallback_font_provider( - std::make_unique(shared_from_this())); + if (enable_font_fallback_) { + font_collection->set_fallback_font_provider( + std::make_unique(shared_from_this())); + } // Cache the font collection for future queries. font_collections_cache_[family] = font_collection; 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 ccb52f5ecb..0f761affd7 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 @@ -48,6 +48,10 @@ class FontCollection : public std::enable_shared_from_this { const std::shared_ptr& MatchFallbackFont(uint32_t ch); + // Do not provide alternative fonts that can match characters which are + // missing from the requested font family. + void DisableFontFallback(); + private: std::deque> skia_font_managers_; std::unordered_map> @@ -55,6 +59,7 @@ class FontCollection : public std::enable_shared_from_this { std::unordered_map> fallback_fonts_; std::shared_ptr null_family_; + bool enable_font_fallback_; const std::shared_ptr& GetFontFamilyForTypeface( const sk_sp& typeface);