diff options
author | rubidium <rubidium@openttd.org> | 2007-12-16 18:38:19 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-12-16 18:38:19 +0000 |
commit | ff7ff890f9e22ae18a75394fb33ec78d8b5d266c (patch) | |
tree | ede1e6e23715e489baa36bf5cc28db1daf043bc4 /src | |
parent | 5e062d3f1505d4fc4191ab48ea8463a474f5288a (diff) | |
download | openttd-ff7ff890f9e22ae18a75394fb33ec78d8b5d266c.tar.xz |
(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.
Diffstat (limited to 'src')
-rw-r--r-- | src/openttd.cpp | 2 | ||||
-rw-r--r-- | src/settings_gui.cpp | 1 | ||||
-rw-r--r-- | src/strings.cpp | 54 | ||||
-rw-r--r-- | src/strings.h | 2 |
4 files changed, 59 insertions, 0 deletions
diff --git a/src/openttd.cpp b/src/openttd.cpp index 46f46c594..77d3bb2a4 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -342,6 +342,8 @@ static void LoadIntroGame() _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 index 46806bfca..f584e8541 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -255,6 +255,7 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e) 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 index d45a6a24e..e1c2ebb65 100644 --- 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 @@ void InitializeLanguagePacks() 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 index 7165f60a5..2307afc78 100644 --- a/src/strings.h +++ b/src/strings.h @@ -83,4 +83,6 @@ void InitializeLanguagePacks(); int CDECL StringIDSorter(const void *a, const void *b); +void CheckForMissingGlyphsInLoadedLanguagePack(); + #endif /* STRINGS_H */ |