mirror of https://github.com/OpenTTD/OpenTTD
(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.
parent
5e062d3f15
commit
ff7ff890f9
|
@ -342,6 +342,8 @@ static void LoadIntroGame()
|
||||||
_cursor.fix_at = false;
|
_cursor.fix_at = false;
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
|
|
||||||
|
CheckForMissingGlyphsInLoadedLanguagePack();
|
||||||
|
|
||||||
/* Play main theme */
|
/* Play main theme */
|
||||||
if (_music_driver->IsSongPlaying()) ResetMusic();
|
if (_music_driver->IsSongPlaying()) ResetMusic();
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,6 +255,7 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
|
||||||
break;
|
break;
|
||||||
case 24: /* Change interface language */
|
case 24: /* Change interface language */
|
||||||
ReadLanguagePack(e->we.dropdown.index);
|
ReadLanguagePack(e->we.dropdown.index);
|
||||||
|
CheckForMissingGlyphsInLoadedLanguagePack();
|
||||||
UpdateAllStationVirtCoord();
|
UpdateAllStationVirtCoord();
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include "signs.h"
|
#include "signs.h"
|
||||||
#include "vehicle.h"
|
#include "vehicle.h"
|
||||||
#include "newgrf_engine.h"
|
#include "newgrf_engine.h"
|
||||||
|
#include "fontcache.h"
|
||||||
|
#include "gui.h"
|
||||||
|
|
||||||
/* for opendir/readdir/closedir */
|
/* for opendir/readdir/closedir */
|
||||||
# include "fios.h"
|
# 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);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -83,4 +83,6 @@ void InitializeLanguagePacks();
|
||||||
|
|
||||||
int CDECL StringIDSorter(const void *a, const void *b);
|
int CDECL StringIDSorter(const void *a, const void *b);
|
||||||
|
|
||||||
|
void CheckForMissingGlyphsInLoadedLanguagePack();
|
||||||
|
|
||||||
#endif /* STRINGS_H */
|
#endif /* STRINGS_H */
|
||||||
|
|
Loading…
Reference in New Issue