From 4cd96edd9ca2da49f6267722cf6ef0c8331aefcf Mon Sep 17 00:00:00 2001 From: Saurtron Date: Wed, 11 Dec 2024 02:36:46 +0100 Subject: [PATCH 1/5] Custom xml for windows since mingw doesn't work with the fontconfig special strings. --- rts/Rendering/Fonts/CFontTexture.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index b969389c18..53b0aec9c4 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -151,14 +151,17 @@ class FtLibraryHandler { #ifdef _WIN32 // fontconfig will resolve the special keys here. - static constexpr const char* configFmt = R"(WINDOWSFONTDIRfontcacheLOCAL_APPDATA_FONTCONFIG_CACHE)"; + std::array osFontsDir; + ExpandEnvironmentStrings("%WINDIR%\\fonts", osFontsDir.data(), osFontsDir.size()); // expands %HOME% etc. + static constexpr const char* configFmt = R"(%sfontcache)"; + std::string configFmtVar = fmt::sprintf(configFmt, osFontsDir.data()); #else static constexpr const char* configFmt = 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); From 2e6f6aa618bee11b79dc30b97eb253c18e7005ae Mon Sep 17 00:00:00 2001 From: Saurtron Date: Wed, 11 Dec 2024 02:47:20 +0100 Subject: [PATCH 2/5] Compatible formatVar for linux so we can use the same syntax everywhere. --- rts/Rendering/Fonts/CFontTexture.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index 53b0aec9c4..f7cb61a1ad 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -157,6 +157,7 @@ class FtLibraryHandler { std::string configFmtVar = fmt::sprintf(configFmt, osFontsDir.data()); #else static constexpr const char* configFmt = R"(fontcache)"; + std::string configFmtVar = configFmt; #endif #ifdef _WIN32 @@ -169,7 +170,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__); @@ -194,7 +195,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()); } From 23b27ff019294ed03afb9d37a1fac48ca12223e3 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Wed, 11 Dec 2024 03:06:14 +0100 Subject: [PATCH 3/5] Initialize configFmtVar directly and remove obsolete comment. --- rts/Rendering/Fonts/CFontTexture.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index f7cb61a1ad..a638eef365 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -150,14 +150,12 @@ 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. std::array osFontsDir; ExpandEnvironmentStrings("%WINDIR%\\fonts", osFontsDir.data(), osFontsDir.size()); // expands %HOME% etc. static constexpr const char* configFmt = R"(%sfontcache)"; std::string configFmtVar = fmt::sprintf(configFmt, osFontsDir.data()); #else - static constexpr const char* configFmt = R"(fontcache)"; - std::string configFmtVar = configFmt; + const std::string configFmtVar = R"(fontcache)"; #endif #ifdef _WIN32 From dab42a1afb881b8e7d0a7b50ae529545b45ecf5b Mon Sep 17 00:00:00 2001 From: saurtron Date: Wed, 11 Dec 2024 14:38:54 +0100 Subject: [PATCH 4/5] get proper size for osFontsDir Co-authored-by: sprunk --- rts/Rendering/Fonts/CFontTexture.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index a638eef365..7a66a7a4d8 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -150,8 +150,10 @@ class FtLibraryHandler { // and system fonts included. also linux actually has system config files that can be used by fontconfig. #ifdef _WIN32 - std::array osFontsDir; - ExpandEnvironmentStrings("%WINDIR%\\fonts", osFontsDir.data(), osFontsDir.size()); // expands %HOME% etc. + 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)"; std::string configFmtVar = fmt::sprintf(configFmt, osFontsDir.data()); #else From 279db2c447d9221142fcaef941cc73aedd1fe6ab Mon Sep 17 00:00:00 2001 From: Saurtron Date: Wed, 11 Dec 2024 14:40:01 +0100 Subject: [PATCH 5/5] Make configFmtVar const and add extra empty line. --- rts/Rendering/Fonts/CFontTexture.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index 7a66a7a4d8..33f7cbce7d 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -154,8 +154,9 @@ class FtLibraryHandler { const int neededSize = ExpandEnvironmentStrings(winFontPath, nullptr, 0); std::vector osFontsDir (neededSize); ExpandEnvironmentStrings(winFontPath, osFontsDir.data(), osFontsDir.size()); + static constexpr const char* configFmt = R"(%sfontcache)"; - std::string configFmtVar = fmt::sprintf(configFmt, osFontsDir.data()); + const std::string configFmtVar = fmt::sprintf(configFmt, osFontsDir.data()); #else const std::string configFmtVar = R"(fontcache)"; #endif