libtxt: disable font fallback when test font mode is enabled (flutter/engine#4661)
This commit is contained in:
@@ -122,6 +122,8 @@ void FontCollection::RegisterTestFonts() {
|
||||
|
||||
collection_->PushFront(sk_make_sp<txt::TestFontManager>(
|
||||
std::move(asset_data_provider), GetTestFontFamilyName()));
|
||||
|
||||
collection_->DisableFontFallback();
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@@ -64,7 +64,7 @@ class TxtFallbackFontProvider
|
||||
std::shared_ptr<FontCollection> font_collection_;
|
||||
};
|
||||
|
||||
FontCollection::FontCollection() = default;
|
||||
FontCollection::FontCollection() : enable_font_fallback_(true) {}
|
||||
|
||||
FontCollection::~FontCollection() = default;
|
||||
|
||||
@@ -88,6 +88,10 @@ void FontCollection::PushBack(sk_sp<SkFontMgr> skia_font_manager) {
|
||||
skia_font_managers_.push_back(std::move(skia_font_manager));
|
||||
}
|
||||
|
||||
void FontCollection::DisableFontFallback() {
|
||||
enable_font_fallback_ = false;
|
||||
}
|
||||
|
||||
std::shared_ptr<minikin::FontCollection>
|
||||
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<std::shared_ptr<minikin::FontFamily>> 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<minikin::FontCollection>(std::move(minikin_families));
|
||||
font_collection->set_fallback_font_provider(
|
||||
std::make_unique<TxtFallbackFontProvider>(shared_from_this()));
|
||||
if (enable_font_fallback_) {
|
||||
font_collection->set_fallback_font_provider(
|
||||
std::make_unique<TxtFallbackFontProvider>(shared_from_this()));
|
||||
}
|
||||
|
||||
// Cache the font collection for future queries.
|
||||
font_collections_cache_[family] = font_collection;
|
||||
|
||||
@@ -48,6 +48,10 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {
|
||||
|
||||
const std::shared_ptr<minikin::FontFamily>& 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<sk_sp<SkFontMgr>> skia_font_managers_;
|
||||
std::unordered_map<std::string, std::shared_ptr<minikin::FontCollection>>
|
||||
@@ -55,6 +59,7 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {
|
||||
std::unordered_map<SkFontID, std::shared_ptr<minikin::FontFamily>>
|
||||
fallback_fonts_;
|
||||
std::shared_ptr<minikin::FontFamily> null_family_;
|
||||
bool enable_font_fallback_;
|
||||
|
||||
const std::shared_ptr<minikin::FontFamily>& GetFontFamilyForTypeface(
|
||||
const sk_sp<SkTypeface>& typeface);
|
||||
|
||||
Reference in New Issue
Block a user