Skip to content

Commit

Permalink
Fix: tell the user if a font fails to load and fallback is about to b…
Browse files Browse the repository at this point in the history
…e 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.
  • Loading branch information
TrueBrain committed Jan 12, 2021
1 parent 4e36fea commit a5ae74e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,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;
}
}
Expand Down Expand Up @@ -2112,6 +2123,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
Expand Down

0 comments on commit a5ae74e

Please sign in to comment.