Fix: tell the user if a font fails to load and fallback is about to be used

Additionally, tell exactly why the font failed to load, which
glyph was missing from the font. This hopefully helps the user
a bit more in the right direction.
This commit is contained in:
Patric Stout 2021-01-12 20:05:47 +01:00 committed by Patric Stout
parent 98400974a9
commit c6fd6cfd15
1 changed files with 24 additions and 0 deletions

View File

@ -2017,6 +2017,17 @@ bool MissingGlyphSearcher::FindMissingGlyphs()
size = (FontSize)(c - SCC_FIRST_FONT);
} else if (!IsInsideMM(c, SCC_SPRITE_START, SCC_SPRITE_END) && IsPrintable(c) && !IsTextDirectionChar(c) && c != '?' && GetGlyph(size, c) == question_mark[size]) {
/* The character is printable, but not in the normal font. This is the case we were testing for. */
std::string size_name;
switch (size) {
case 0: size_name = "medium"; break;
case 1: size_name = "small"; break;
case 2: size_name = "large"; break;
case 3: size_name = "mono"; break;
default: NOT_REACHED();
}
DEBUG(freetype, 0, "Font is missing glyphs to display char 0x%X in %s font size", c, size_name.c_str());
return true;
}
}
@ -2110,6 +2121,19 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
memcpy(&_freetype, &backup, sizeof(backup));
if (!bad_font) {
/* Show that we loaded fallback font. To do this properly we have
* to set the colour of the string, otherwise we end up with a lot
* of artifacts.* The colour 'character' might change in the
* future, so for safety we just Utf8 Encode it into the string,
* which takes exactly three characters, so it replaces the "XXX"
* with the colour marker. */
static char *err_str = stredup("XXXThe current font is missing some of the characters used in the texts for this language. Using system fallback font instead.");
Utf8Encode(err_str, SCC_YELLOW);
SetDParamStr(0, err_str);
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_WARNING);
}
if (bad_font && base_font) {
/* Our fallback font does miss characters too, so keep the
* user chosen font as that is more likely to be any good than