(svn r21298) -Fix [FS#4261]: fonts set in openttd.cfg were not properly checked for missing glyphs on language change

This commit is contained in:
glx
2010-11-23 17:59:50 +00:00
parent c72fdad0bb
commit d9173858a2
3 changed files with 79 additions and 81 deletions

View File

@@ -1568,16 +1568,19 @@ const char *GetCurrentLanguageIsoCode()
* Check whether there are glyphs missing in the current language.
* @param Pointer to an address for storing the text pointer.
* @return If glyphs are missing, return \c true, else return \false.
* @pre *str must not be \c NULL.
* @post If \c true is returned, *str points to a string that is found to contain at least one missing glyph.
* @post If \c true is returned and str is not NULL, *str points to a string that is found to contain at least one missing glyph.
*/
static bool FindMissingGlyphs(const char **str)
{
#ifdef WITH_FREETYPE
UninitFreeType();
InitFreeType();
#endif
const Sprite *question_mark = GetGlyph(FS_NORMAL, '?');
for (uint i = 0; i != 32; i++) {
for (uint j = 0; j < _langtab_num[i]; j++) {
const char *text = _langpack_offs[_langtab_start[i] + j];
*str = text;
if (str != NULL) *str = text;
for (WChar c = Utf8Consume(&text); c != '\0'; c = Utf8Consume(&text)) {
if (c == SCC_SETX) {
/* SetX is, together with SetXY as special character that
@@ -1608,15 +1611,7 @@ static bool FindMissingGlyphs(const char **str)
*/
void CheckForMissingGlyphsInLoadedLanguagePack()
{
#ifdef WITH_FREETYPE
/* Reset to the original state; switching languages might cause us to
* automatically choose another font. This resets that choice. */
UninitFreeType();
InitFreeType();
#endif
const char *str;
bool bad_font = FindMissingGlyphs(&str);
bool bad_font = FindMissingGlyphs(NULL);
#ifdef WITH_FREETYPE
if (bad_font) {
/* We found an unprintable character... lets try whether we can find
@@ -1624,23 +1619,16 @@ void CheckForMissingGlyphsInLoadedLanguagePack()
FreeTypeSettings backup;
memcpy(&backup, &_freetype, sizeof(backup));
bool success = SetFallbackFont(&_freetype, _langpack->isocode, _langpack->winlangid, str);
if (success) {
UninitFreeType();
InitFreeType();
}
bad_font = !SetFallbackFont(&_freetype, _langpack->isocode, _langpack->winlangid, &FindMissingGlyphs);
memcpy(&_freetype, &backup, sizeof(backup));
if (success) {
bad_font = FindMissingGlyphs(&str);
if (bad_font) {
/* Our fallback font does miss characters too, so keep the
* user chosen font as that is more likely to be any good than
* the wild guess we made */
UninitFreeType();
InitFreeType();
}
if (bad_font) {
/* Our fallback font does miss characters too, so keep the
* user chosen font as that is more likely to be any good than
* the wild guess we made */
UninitFreeType();
InitFreeType();
}
}
#endif