From c6fd6cfd1580f0f743ddb91a0d161758e3f8c7ac Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Tue, 12 Jan 2021 20:05:47 +0100 Subject: [PATCH] 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. --- src/strings.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/strings.cpp b/src/strings.cpp index a98d7e966c..fa039fdb97 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -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