From 7ea0e2d6a3f01291b4fc9a02866b4c04ba4ca4f3 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Thu, 26 Nov 2015 18:28:52 +0000 Subject: [PATCH] improve language load fail behaviour improve currencies fix bug in supported glyph check --- data/language/english_uk.txt | 2 +- src/drawing/font.c | 5 ++++- src/drawing/string.c | 4 +++- src/localisation/currency.c | 4 ++-- src/localisation/language.cpp | 5 +++++ src/openrct2.c | 11 +++++++---- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 55dfe85182..ae11c8b0c9 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3899,7 +3899,7 @@ STR_5557 :Stay connected after desynchronisation (Multiplayer) STR_5558 :A restart is required for this setting to take effect STR_5559 :10 min. inspections STR_5560 :{SMALLFONT}{BLACK}Sets the inspection time to 'Every 10 minutes' on all rides -STR_5561 :Failed to load language file +STR_5561 :Failed to load language STR_5562 :WARNING! STR_5563 :This feature is currently unstable, take extra caution. STR_5564 :Insert Corrupt Element diff --git a/src/drawing/font.c b/src/drawing/font.c index 886af5bf43..d4b3b08090 100644 --- a/src/drawing/font.c +++ b/src/drawing/font.c @@ -134,7 +134,10 @@ bool font_supports_string(const utf8 *text, int fontSize) uint32 codepoint; while ((codepoint = utf8_get_next(src, &src)) != 0) { if (gUseTrueTypeFont) { - return TTF_GlyphIsProvided(gCurrentTTFFontSet->size[fontSize].font, (uint16)codepoint); + bool supported = TTF_GlyphIsProvided(gCurrentTTFFontSet->size[fontSize].font, (uint16)codepoint); + if (!supported) { + return false; + } } else { bool supported = false; switch (codepoint) { diff --git a/src/drawing/string.c b/src/drawing/string.c index 1472f4ca90..e1416ddf1b 100644 --- a/src/drawing/string.c +++ b/src/drawing/string.c @@ -881,8 +881,9 @@ static uint32 _ttf_getwidth_cache_get_or_add(TTF_Font *font, const utf8 *text) bool ttf_initialise() { if (!_ttfInitialised) { - if (TTF_Init() != 0) + if (TTF_Init() != 0) { return false; + } for (int i = 0; i < 4; i++) { TTFFontDescriptor *fontDesc = &(gCurrentTTFFontSet->size[i]); @@ -893,6 +894,7 @@ bool ttf_initialise() fontDesc->font = TTF_OpenFont(fontPath, fontDesc->ptSize); if (fontDesc->font == NULL) { log_error("Unable to load '%s'", fontPath); + return false; } } diff --git a/src/localisation/currency.c b/src/localisation/currency.c index defa1262a9..1dbd267e8b 100644 --- a/src/localisation/currency.c +++ b/src/localisation/currency.c @@ -29,10 +29,10 @@ const currency_descriptor CurrencyDescriptors[CURRENCY_END] = { { 1000 , CURRENCY_PREFIX, "\xC2\xA5" , CURRENCY_SUFFIX, "YEN" , STR_YEN }, // Japanese Yen { 10 , CURRENCY_SUFFIX, "Pts" , CURRENCY_SUFFIX, "Pts" , STR_PESETA }, // Spanish Peseta { 1000 , CURRENCY_PREFIX, "L" , CURRENCY_PREFIX, "L" , STR_LIRA }, // Italian Lira - { 10 , CURRENCY_PREFIX, "fl. " , CURRENCY_PREFIX, "fl." , STR_GUILDERS }, // Dutch Guilder + { 10 , CURRENCY_PREFIX, "\xC6\x92" , CURRENCY_PREFIX, "fl." , STR_GUILDERS }, // Dutch Guilder { 10 , CURRENCY_SUFFIX, "kr." , CURRENCY_SUFFIX, "kr." , STR_KRONA }, // Swedish Krona { 10 , CURRENCY_PREFIX, "\xE2\x82\xAC" , CURRENCY_SUFFIX, "EUR" , STR_EUROS }, // Euro { 10000 , CURRENCY_PREFIX, "\xE2\x82\xA9" , CURRENCY_PREFIX, "W" , STR_WON }, // South Korean Won { 1000 , CURRENCY_PREFIX, "R " , CURRENCY_PREFIX, "R " , STR_ROUBLE }, // Russian Rouble - { 100 , CURRENCY_SUFFIX, "K\xC4\x8D" , CURRENCY_SUFFIX, "Kc" , STR_CZECH_KORUNA }, // Czech koruna + { 100 , CURRENCY_SUFFIX, " K\xC4\x8D" , CURRENCY_SUFFIX, " Kc" , STR_CZECH_KORUNA }, // Czech koruna }; diff --git a/src/localisation/language.cpp b/src/localisation/language.cpp index 5c1bacd1b9..7e22900aa5 100644 --- a/src/localisation/language.cpp +++ b/src/localisation/language.cpp @@ -173,6 +173,11 @@ int language_open(int id) gCurrentTTFFontSet = LanguagesDescriptors[id].font; if (!ttf_initialise()) { log_warning("Unable to initialise TrueType fonts."); + + // Fall back to sprite font + gUseTrueTypeFont = false; + gCurrentTTFFontSet = nullptr; + return 0; } } diff --git a/src/openrct2.c b/src/openrct2.c index 54bfdac002..46f26d1fe0 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -251,10 +251,13 @@ bool openrct2_initialise() audio_init(); audio_populate_devices(); } - if (!language_open(gConfigGeneral.language)) - { - log_fatal("Failed to open language, exiting."); - return false; + if (!language_open(gConfigGeneral.language)) { + log_error("Failed to open configured language..."); + + if (!language_open(LANGUAGE_ENGLISH_UK)) { + log_fatal("Failed to open fallback language..."); + return false; + } } http_init();