src/strings.cpp
changeset 8085 5b58f6315fb8
parent 7954 57b51c69c072
child 8086 48da1cf8f7d1
equal deleted inserted replaced
8084:aa5d431209a9 8085:5b58f6315fb8
    30 #include "debug.h"
    30 #include "debug.h"
    31 #include "newgrf_townname.h"
    31 #include "newgrf_townname.h"
    32 #include "signs.h"
    32 #include "signs.h"
    33 #include "vehicle.h"
    33 #include "vehicle.h"
    34 #include "newgrf_engine.h"
    34 #include "newgrf_engine.h"
       
    35 #include "fontcache.h"
       
    36 #include "gui.h"
    35 
    37 
    36 /* for opendir/readdir/closedir */
    38 /* for opendir/readdir/closedir */
    37 # include "fios.h"
    39 # include "fios.h"
    38 
    40 
    39 DynamicLanguages _dynlang;
    41 DynamicLanguages _dynlang;
  1433 		chosen_language = (language_fallback != -1) ? language_fallback : en_GB_fallback;
  1435 		chosen_language = (language_fallback != -1) ? language_fallback : en_GB_fallback;
  1434 	}
  1436 	}
  1435 
  1437 
  1436 	if (!ReadLanguagePack(chosen_language)) error("Can't read language pack '%s'", dl->ent[chosen_language].file);
  1438 	if (!ReadLanguagePack(chosen_language)) error("Can't read language pack '%s'", dl->ent[chosen_language].file);
  1437 }
  1439 }
       
  1440 
       
  1441 /**
       
  1442  * Check whether the currently loaded language pack
       
  1443  * uses characters that the currently loaded font
       
  1444  * does not support. If this is the case an error
       
  1445  * message will be shown in English. The error
       
  1446  * message will not be localized because that would
       
  1447  * mean it might use characters that are not in the
       
  1448  * font, which is the whole reason this check has
       
  1449  * been added.
       
  1450  */
       
  1451 void CheckForMissingGlyphsInLoadedLanguagePack()
       
  1452 {
       
  1453 	for (uint i = 0; i != 32; i++) {
       
  1454 		for (uint j = 0; j < _langtab_num[i]; j++) {
       
  1455 			const char *string = _langpack_offs[_langtab_start[i] + j];
       
  1456 			WChar c;
       
  1457 			while ((c = Utf8Consume(&string)) != '\0') {
       
  1458 				if (c == SCC_SETX) {
       
  1459 					/*
       
  1460 					 * SetX is, together with SetXY as special character that
       
  1461 					 * uses the next (two) characters as data points. We have
       
  1462 					 * to skip those, otherwise the UTF8 reading will go
       
  1463 					 * haywire.
       
  1464 					 */
       
  1465 					string++;
       
  1466 				} else if (c == SCC_SETXY) {
       
  1467 					string += 2;
       
  1468 				} else if (IsPrintable(c) && GetUnicodeGlyph(FS_NORMAL, c) == 0) {
       
  1469 					/*
       
  1470 					 * The character is printable, but not in the normal font.
       
  1471 					 * This is the case we were testing for. In this case we
       
  1472 					 * have to show the error. As we do not want the string to
       
  1473 					 * be translated by the translators, we 'force' it into the
       
  1474 					 * binary and 'load' it via a BindCString. To do this
       
  1475 					 * properly we have to set the color of the string,
       
  1476 					 * otherwise we end up with a lot of artefacts. The color
       
  1477 					 * 'character' might change in the future, so for safety
       
  1478 					 * we just Utf8 Encode it into the string, which takes
       
  1479 					 * exactly three characters, so it replaces the "XXX" with
       
  1480 					 * the color marker.
       
  1481 					 */
       
  1482 					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.");
       
  1483 					Utf8Encode(err_str, SCC_YELLOW);
       
  1484 					StringID err_msg = BindCString(err_str);
       
  1485 					ShowErrorMessage(INVALID_STRING_ID, err_msg, 0, 0);
       
  1486 					return;
       
  1487 				}
       
  1488 			}
       
  1489 		}
       
  1490 	}
       
  1491 }