@@ -2299,36 +2299,37 @@ std::string_view GetCurrentLanguageIsoCode()
22992299 return _langpack.langpack ->isocode ;
23002300}
23012301
2302- /* *
2303- * Check whether there are glyphs missing in the current language.
2304- * @return If glyphs are missing, return \c true, else return \c false.
2305- */
2306- bool MissingGlyphSearcher::FindMissingGlyphs ()
2302+ MissingGlyphs BaseStringMissingGlyphSearcher::GetRequiredGlyphs (FontSizes fontsizes)
23072303{
2308- FontCache::LoadFontCaches ( this -> fontsizes ) ;
2304+ MissingGlyphs res{} ;
23092305
23102306 this ->Reset ();
23112307 for (auto text = this ->NextString (); text.has_value (); text = this ->NextString ()) {
2312- FontSize size = this ->DefaultSize ();
2313- FontCache *fc = FontCache::Get (size );
2308+ FontSize fs = this ->DefaultSize ();
2309+ FontCache *fc = FontCache::Get (fs );
23142310 for (char32_t c : Utf8View (*text)) {
23152311 if (c >= SCC_FIRST_FONT && c <= SCC_LAST_FONT) {
2316- size = (FontSize)(c - SCC_FIRST_FONT);
2317- fc = FontCache::Get (size);
2318- } else if (!IsInsideMM (c, SCC_SPRITE_START, SCC_SPRITE_END) && IsPrintable (c) && !IsTextDirectionChar (c) && fc->MapCharToGlyph (c, false ) == 0 ) {
2319- /* The character is printable, but not in the normal font. This is the case we were testing for. */
2320- Debug (fontcache, 0 , " Font is missing glyphs to display char 0x{:X} in {} font size" , static_cast <uint32_t >(c), FontSizeToName (size));
2321- return true ;
2312+ fs = (FontSize)(c - SCC_FIRST_FONT);
2313+ fc = FontCache::Get (fs);
2314+ continue ;
23222315 }
2316+
2317+ if (!fontsizes.Test (fs)) continue ;
2318+ if (!IsPrintable (c) || IsTextDirectionChar (c)) continue ;
2319+ if (IsInsideMM (c, SCC_SPRITE_START, SCC_SPRITE_END)) continue ;
2320+ if (fc->MapCharToGlyph (c, false ) != 0 ) continue ;
2321+
2322+ res.fontsizes .Set (fs);
2323+ res.glyphs .insert (c);
23232324 }
23242325 }
2325- return false ;
2326+ return res ;
23262327}
23272328
23282329/* * Helper for searching through the language pack. */
2329- class LanguagePackGlyphSearcher : public MissingGlyphSearcher {
2330+ class LanguagePackGlyphSearcher : public BaseStringMissingGlyphSearcher {
23302331public:
2331- LanguagePackGlyphSearcher () : MissingGlyphSearcher (FONTSIZES_REQUIRED) {}
2332+ LanguagePackGlyphSearcher () : BaseStringMissingGlyphSearcher (FONTSIZES_REQUIRED) {}
23322333
23332334private:
23342335 uint i; // /< Iterator for the primary language tables.
@@ -2377,15 +2378,20 @@ void CheckForMissingGlyphs(MissingGlyphSearcher *searcher)
23772378{
23782379 static LanguagePackGlyphSearcher pack_searcher;
23792380 if (searcher == nullptr ) searcher = &pack_searcher;
2380- bool bad_font = searcher->FindMissingGlyphs ();
2381+
2382+ FontCache::LoadFontCaches (searcher->fontsizes );
2383+
2384+ auto missing_glyphs = searcher->GetRequiredGlyphs (searcher->fontsizes );
2385+ bool bad_font = missing_glyphs.fontsizes .Any ();
2386+
23812387#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
23822388 if (bad_font) {
23832389 /* We found an unprintable character... lets try whether we can find
23842390 * a fallback font that can print the characters in the current language. */
23852391 bool any_font_configured = !_fcsettings.medium .font .empty ();
23862392 FontCacheSettings backup = _fcsettings;
23872393
2388- bad_font = !FontProviderManager::FindFallbackFont (_langpack.langpack ->isocode , searcher-> fontsizes , searcher);
2394+ bad_font = !FontProviderManager::FindFallbackFont (_langpack.langpack ->isocode , missing_glyphs , searcher);
23892395
23902396 _fcsettings = std::move (backup);
23912397
@@ -2404,7 +2410,7 @@ void CheckForMissingGlyphs(MissingGlyphSearcher *searcher)
24042410 /* Our fallback font does miss characters too, so keep the
24052411 * user chosen font as that is more likely to be any good than
24062412 * the wild guess we made */
2407- FontCache::LoadFontCaches (searcher-> fontsizes );
2413+ FontCache::LoadFontCaches (missing_glyphs. fontsizes );
24082414 }
24092415 }
24102416#endif
@@ -2421,12 +2427,12 @@ void CheckForMissingGlyphs(MissingGlyphSearcher *searcher)
24212427 ShowErrorMessage (GetEncodedString (STR_JUST_RAW_STRING, std::move (err_str)), {}, WL_WARNING);
24222428
24232429 /* Reset the font width */
2424- LoadStringWidthTable (searcher-> fontsizes );
2430+ LoadStringWidthTable (missing_glyphs. fontsizes );
24252431 return ;
24262432 }
24272433
24282434 /* Update the font with cache */
2429- LoadStringWidthTable (searcher-> fontsizes );
2435+ LoadStringWidthTable (missing_glyphs. fontsizes );
24302436
24312437#if !(defined(WITH_ICU_I18N) && defined(WITH_HARFBUZZ)) && !defined(WITH_UNISCRIBE) && !defined(WITH_COCOA)
24322438 /*
0 commit comments