summaryrefslogtreecommitdiff
path: root/src/strings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/strings.cpp')
-rw-r--r--src/strings.cpp54
1 files changed, 54 insertions, 0 deletions
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;
+ }
+ }
+ }
+ }
+}