summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-01-12 20:05:47 +0100
committerPatric Stout <github@truebrain.nl>2021-01-13 14:27:39 +0100
commitc6fd6cfd1580f0f743ddb91a0d161758e3f8c7ac (patch)
treec75c1cef9867a609b8a5445d80454eaaa5f1bf8e
parent98400974a9e6a482f71e9aaaca3c3062af8d887d (diff)
downloadopenttd-c6fd6cfd1580f0f743ddb91a0d161758e3f8c7ac.tar.xz
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.
-rw-r--r--src/strings.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/strings.cpp b/src/strings.cpp
index a98d7e966..fa039fdb9 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