From 05c5724c3178571cb3bcdcc7d910dd6b13d6af21 Mon Sep 17 00:00:00 2001 From: saurtron Date: Wed, 11 Dec 2024 15:14:30 +0100 Subject: [PATCH] Fontconfig windows workaround v2 (#1809) * Custom xml for windows since mingw builds won't work with the fontconfig special strings. --------- Co-authored-by: sprunk --- rts/Rendering/Fonts/CFontTexture.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index b969389c18..33f7cbce7d 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -150,15 +150,20 @@ class FtLibraryHandler { // and system fonts included. also linux actually has system config files that can be used by fontconfig. #ifdef _WIN32 - // fontconfig will resolve the special keys here. - static constexpr const char* configFmt = R"(WINDOWSFONTDIRfontcacheLOCAL_APPDATA_FONTCONFIG_CACHE)"; + static constexpr auto winFontPath = "%WINDIR%\\fonts"; + const int neededSize = ExpandEnvironmentStrings(winFontPath, nullptr, 0); + std::vector osFontsDir (neededSize); + ExpandEnvironmentStrings(winFontPath, osFontsDir.data(), osFontsDir.size()); + + static constexpr const char* configFmt = R"(%sfontcache)"; + const std::string configFmtVar = fmt::sprintf(configFmt, osFontsDir.data()); #else - static constexpr const char* configFmt = R"(fontcache)"; + const std::string configFmtVar = R"(fontcache)"; #endif #ifdef _WIN32 // Explicitly set the config with xml for windows. - res = FcConfigParseAndLoadFromMemory(config, reinterpret_cast(configFmt), FcTrue); + res = FcConfigParseAndLoadFromMemory(config, reinterpret_cast(configFmtVar.c_str()), FcTrue); #else // Load system configuration (passing 0 here so fc will use the default os config file if possible). res = FcConfigParseAndLoad(config, 0, true); @@ -166,7 +171,7 @@ class FtLibraryHandler { if (res) { #ifndef _WIN32 // add local cache after system config for linux - FcConfigParseAndLoadFromMemory(config, reinterpret_cast(configFmt), FcTrue); + FcConfigParseAndLoadFromMemory(config, reinterpret_cast(configFmtVar.c_str()), FcTrue); #endif LOG_MSG("[%s] Using Fontconfig light init", false, __func__); @@ -191,7 +196,7 @@ class FtLibraryHandler { config = fcConfig; // add our cache at the back of the new config. - FcConfigParseAndLoadFromMemory(config, reinterpret_cast(configFmt), FcTrue); + FcConfigParseAndLoadFromMemory(config, reinterpret_cast(configFmtVar.c_str()), FcTrue); } else { LOG_MSG("%s config and fonts. No system fallbacks will be available", false, errprefix.c_str()); }