# HG changeset patch # User rubidium # Date 1197830299 0 # Node ID b6bf6634fcca6d1a5a579169e191506102ee0c17 # Parent f0b9ed2487a0952788aa22c2bd2fbaa1d8493e41 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen. diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -342,6 +342,8 @@ _cursor.fix_at = false; MarkWholeScreenDirty(); + CheckForMissingGlyphsInLoadedLanguagePack(); + /* Play main theme */ if (_music_driver->IsSongPlaying()) ResetMusic(); } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -255,6 +255,7 @@ break; case 24: /* Change interface language */ ReadLanguagePack(e->we.dropdown.index); + CheckForMissingGlyphsInLoadedLanguagePack(); UpdateAllStationVirtCoord(); MarkWholeScreenDirty(); break; diff --git a/src/strings.cpp b/src/strings.cpp --- a/src/strings.cpp +++ b/src/strings.cpp @@ -32,6 +32,8 @@ #include "signs.h" #include "vehicle.h" #include "newgrf_engine.h" +#include "fontcache.h" +#include "gui.h" /* for opendir/readdir/closedir */ # include "fios.h" @@ -1435,3 +1437,55 @@ if (!ReadLanguagePack(chosen_language)) error("Can't read language pack '%s'", dl->ent[chosen_language].file); } + +/** + * Check whether the currently loaded language pack + * uses characters that the currently loaded font + * does not support. If this is the case an error + * message will be shown in English. The error + * message will not be localized because that would + * mean it might use characters that are not in the + * font, which is the whole reason this check has + * been added. + */ +void CheckForMissingGlyphsInLoadedLanguagePack() +{ + for (uint i = 0; i != 32; i++) { + for (uint j = 0; j < _langtab_num[i]; j++) { + const char *string = _langpack_offs[_langtab_start[i] + j]; + WChar c; + while ((c = Utf8Consume(&string)) != '\0') { + if (c == SCC_SETX) { + /* + * SetX is, together with SetXY as special character that + * uses the next (two) characters as data points. We have + * to skip those, otherwise the UTF8 reading will go + * haywire. + */ + string++; + } else if (c == SCC_SETXY) { + string += 2; + } else if (IsPrintable(c) && GetUnicodeGlyph(FS_NORMAL, c) == 0) { + /* + * The character is printable, but not in the normal font. + * This is the case we were testing for. In this case we + * have to show the error. As we do not want the string to + * be translated by the translators, we 'force' it into the + * binary and 'load' it via a BindCString. To do this + * properly we have to set the color of the string, + * otherwise we end up with a lot of artefacts. The color + * '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 color marker. + */ + static char *err_str = strdup("XXXThe current font misses characters used in the strings for this language. Read the readme to see how to solve this."); + Utf8Encode(err_str, SCC_YELLOW); + StringID err_msg = BindCString(err_str); + ShowErrorMessage(INVALID_STRING_ID, err_msg, 0, 0); + return; + } + } + } + } +} diff --git a/src/strings.h b/src/strings.h --- a/src/strings.h +++ b/src/strings.h @@ -83,4 +83,6 @@ int CDECL StringIDSorter(const void *a, const void *b); +void CheckForMissingGlyphsInLoadedLanguagePack(); + #endif /* STRINGS_H */