From 2f36dbf7e3d268d8b7b25ca46984b4b44de9436d Mon Sep 17 00:00:00 2001 From: YJSoft Date: Thu, 12 May 2016 20:47:30 +0900 Subject: [PATCH] Add font config at config.ini (#3569) --- src/config.c | 9 +++++++++ src/config.h | 8 ++++++++ src/localisation/language.cpp | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/config.c b/src/config.c index 3ac29d9f63..7fd8d1d67d 100644 --- a/src/config.c +++ b/src/config.c @@ -285,6 +285,13 @@ config_property_definition _notificationsDefinitions[] = { { offsetof(notification_configuration, guest_died), "guest_died", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, }; +config_property_definition _fontsDefinitions[] = { + { offsetof(font_configuration, file_name), "file_name", CONFIG_VALUE_TYPE_STRING, {.value_string = NULL }, NULL }, + { offsetof(font_configuration, font_name), "font_name", CONFIG_VALUE_TYPE_STRING, {.value_string = NULL }, NULL }, + { offsetof(font_configuration, x_offset), "x_offset", CONFIG_VALUE_TYPE_SINT8, {.value_string = NULL }, NULL }, + { offsetof(font_configuration, y_offset), "y_offset", CONFIG_VALUE_TYPE_SINT8, {.value_string = NULL }, NULL } +}; + config_section_definition _sectionDefinitions[] = { { &gConfigGeneral, "general", _generalDefinitions, countof(_generalDefinitions) }, { &gConfigInterface, "interface", _interfaceDefinitions, countof(_interfaceDefinitions) }, @@ -292,6 +299,7 @@ config_section_definition _sectionDefinitions[] = { { &gConfigTwitch, "twitch", _twitchDefinitions, countof(_twitchDefinitions) }, { &gConfigNetwork, "network", _networkDefinitions, countof(_networkDefinitions) }, { &gConfigNotifications, "notifications", _notificationsDefinitions, countof(_notificationsDefinitions) }, + { &gConfigFonts, "fonts", _fontsDefinitions, countof(_fontsDefinitions) } }; #pragma endregion @@ -302,6 +310,7 @@ sound_configuration gConfigSound; twitch_configuration gConfigTwitch; network_configuration gConfigNetwork; notification_configuration gConfigNotifications; +font_configuration gConfigFonts; title_sequences_configuration gConfigTitleSequences; static bool config_open(const utf8string path); diff --git a/src/config.h b/src/config.h index 34a2f9f9c0..8ec627e882 100644 --- a/src/config.h +++ b/src/config.h @@ -255,6 +255,13 @@ typedef struct { bool guest_died; } notification_configuration; +typedef struct { + utf8string file_name; + utf8string font_name; + sint8 x_offset; + sint8 y_offset; +} font_configuration; + // Define structures for any other settings here typedef struct { uint8 rct1_ride_lights; @@ -306,6 +313,7 @@ extern sound_configuration gConfigSound; extern twitch_configuration gConfigTwitch; extern network_configuration gConfigNetwork; extern notification_configuration gConfigNotifications; +extern font_configuration gConfigFonts; extern title_sequences_configuration gConfigTitleSequences; extern uint16 gShortcutKeys[SHORTCUT_COUNT]; diff --git a/src/localisation/language.cpp b/src/localisation/language.cpp index be7ff5d945..33baf78f29 100644 --- a/src/localisation/language.cpp +++ b/src/localisation/language.cpp @@ -19,6 +19,7 @@ extern "C" { #include "../addresses.h" +#include "../config.h" #include "../drawing/drawing.h" #include "../object.h" #include "../openrct2.h" @@ -174,6 +175,27 @@ int language_open(int id) gUseTrueTypeFont = false; gCurrentTTFFontSet = nullptr; } else { + if (gConfigFonts.file_name != nullptr) { + static TTFFontSetDescriptor TTFFontCustom = {{ + { gConfigFonts.file_name, gConfigFonts.font_name, 11, gConfigFonts.x_offset, gConfigFonts.y_offset, 15, nullptr }, + { gConfigFonts.file_name, gConfigFonts.font_name, 11, gConfigFonts.x_offset, gConfigFonts.y_offset, 17, nullptr }, + { gConfigFonts.file_name, gConfigFonts.font_name, 11, gConfigFonts.x_offset, gConfigFonts.y_offset, 17, nullptr }, + { gConfigFonts.file_name, gConfigFonts.font_name, 11, gConfigFonts.x_offset, gConfigFonts.y_offset, 20, nullptr }, + }}; + ttf_dispose(); + gUseTrueTypeFont = true; + gCurrentTTFFontSet = &TTFFontCustom; + + bool font_initialised = ttf_initialise(); + if(!font_initialised) { + log_warning("Unable to initialise configured TrueType font -- falling back to Language default."); + } else { + // Objects and their localized strings need to be refreshed + reset_loaded_objects(); + + return 1; + } + } ttf_dispose(); gUseTrueTypeFont = true; gCurrentTTFFontSet = LanguagesDescriptors[id].font;