Add: Automatically load fonts for missing glyphs. (#14856)
This commit is contained in:
@@ -75,6 +75,7 @@ int FontCache::GetDefaultFontHeight(FontSize fs)
|
||||
|
||||
for (const auto &fc : FontCache::caches) {
|
||||
if (fc == nullptr || fc->fs != fs) continue;
|
||||
if (fc->load_reason == FontLoadReason::MissingFallback) continue; // Avoid dynamically loaded fonts affecting widget sizes.
|
||||
ascender = std::max(ascender, fc->ascender);
|
||||
descender = std::min(descender, fc->descender);
|
||||
}
|
||||
@@ -269,10 +270,11 @@ std::string GetFontCacheFontName(FontSize fs)
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void FontCache::LoadFallbackFonts(FontSize fs)
|
||||
/* static */ void FontCache::LoadFallbackFonts(FontSize fs, FontLoadReason load_reason)
|
||||
{
|
||||
const FontCacheSubSetting *setting = GetFontCacheSubSetting(fs);
|
||||
for (auto it = setting->fallback_fonts.rbegin(); it != setting->fallback_fonts.rend(); ++it) {
|
||||
if (it->load_reason != load_reason) continue;
|
||||
FontCache::Register(FontProviderManager::LoadFont(fs, FontType::TrueType, false, it->name, it->os_handle), it->load_reason);
|
||||
}
|
||||
}
|
||||
@@ -318,12 +320,15 @@ std::string GetFontCacheFontName(FontSize fs)
|
||||
if (std::ranges::find(fontnames, extra_font) == std::end(fontnames)) fontnames.push_back(extra_font);
|
||||
}
|
||||
|
||||
/* First load fonts for missing glyphs discovered during string formatting. */
|
||||
FontCache::LoadFallbackFonts(fs, FontLoadReason::MissingFallback);
|
||||
|
||||
/* Load configured fonts in reverse order so that the first entry has priority. */
|
||||
for (auto it = fontnames.rbegin(); it != fontnames.rend(); ++it) {
|
||||
if (*it == DEFAULT_FONT) {
|
||||
FontCache::LoadDefaultFonts(fs);
|
||||
} else if (*it == FALLBACK_FONT) {
|
||||
FontCache::LoadFallbackFonts(fs);
|
||||
FontCache::LoadFallbackFonts(fs, FontLoadReason::LanguageFallback);
|
||||
} else {
|
||||
FontCache::Register(FontProviderManager::LoadFont(fs, FontType::TrueType, true, std::string{*it}, {}), FontLoadReason::Configured);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user