From 46ebb42fa8d68e0c1e6ebdecbd2894aeba953cf9 Mon Sep 17 00:00:00 2001 From: Sadie del Solar Date: Sun, 12 May 2024 16:36:05 -0700 Subject: [PATCH] Codechange: Add ResizeFont function to the fontcache class. --- src/fontcache.cpp | 23 +++++++++++++++++++++++ src/fontcache.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 80972fc722..071ca34472 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -148,6 +148,29 @@ static void LoadFontHelper(FontSize fs) #endif } +/** + * Called to change the size setting of a font in OpenTTD. + * @param font_size FontSize(enum not pixel size) of the font to change. + * @param size The new pixel size to use for this font. + */ +void ResizeFont(FontSize font_size, uint size) +{ + FontCacheSubSetting *setting = GetFontCacheSubSetting(font_size); + + if (setting->size == size) return; + + setting->size = size; + + FontCache *loaded_font = FontCache::Get(font_size); + loaded_font->SetFontSize(size); + + LoadStringWidthTable(); + UpdateAllVirtCoords(); + ReInitAllWindows(true); + + if (_save_config) SaveToConfig(); +} + void SetFont(FontSize font_size, const std::string &font, uint size) { FontCacheSubSetting *setting = GetFontCacheSubSetting(font_size); diff --git a/src/fontcache.h b/src/fontcache.h index 5e64378d21..b1105acbe2 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -232,6 +232,7 @@ std::string GetFontCacheFontName(FontSize fs); void DebugPrintFontSettings(const std::string &desc); bool GetFontAAState(); void InitFontCache(); +void ResizeFont(FontSize font_size, uint size); void SetFont(FontSize fontsize, const std::string &font, uint size); void UninitFontCache();