From c62c097f279e9579178f18c8496d7f57ff8aebef Mon Sep 17 00:00:00 2001 From: Saurtron Date: Fri, 15 Nov 2024 01:54:59 +0100 Subject: [PATCH 1/8] Initialize os config through FcInitLoadConfigAndFonts. --- rts/Rendering/Fonts/CFontTexture.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index 753d1e0b41..5737e583aa 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -120,7 +120,7 @@ class FtLibraryHandler { return; } - config = FcConfigCreate(); + config = FcInitLoadConfigAndFonts(); if (!config) return; @@ -192,7 +192,6 @@ class FtLibraryHandler { FcConfigAppFontClear(GetFCConfig()); FcConfigAppFontAddDir(GetFCConfig(), reinterpret_cast("fonts")); - FcConfigAppFontAddDir(GetFCConfig(), reinterpret_cast(osFontsDir)); { auto dirs = FcConfigGetCacheDirs(GetFCConfig()); From 39facaf059b637c58d01bf2d7a3a0dea753943fa Mon Sep 17 00:00:00 2001 From: Saurtron Date: Fri, 15 Nov 2024 02:03:55 +0100 Subject: [PATCH 2/8] Don't search by UKWN or ukwn foundries. --- rts/Rendering/Fonts/CFontTexture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index 5737e583aa..e939363471 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -460,7 +460,7 @@ static std::shared_ptr GetFontForCharacters(const std::vector(foundry)) != 0 && !strcmp("ukwn", reinterpret_cast(foundry)) != 0) FcPatternAddString(pattern, FC_FOUNDRY, foundry); } From 0d36013db32b09a922a5f6b007ef79659806fdf2 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Fri, 15 Nov 2024 02:33:57 +0100 Subject: [PATCH 3/8] Remove extraneous !. --- rts/Rendering/Fonts/CFontTexture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index e939363471..0fb58d1ba1 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -460,7 +460,7 @@ static std::shared_ptr GetFontForCharacters(const std::vector(foundry)) != 0 && !strcmp("ukwn", reinterpret_cast(foundry)) != 0) + if (foundry && strcmp("UKWN", reinterpret_cast(foundry)) != 0 && strcmp("ukwn", reinterpret_cast(foundry)) != 0) FcPatternAddString(pattern, FC_FOUNDRY, foundry); } From 7212358a496b630c07cb1080b0cbedc0b6405131 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Fri, 15 Nov 2024 11:56:38 +0100 Subject: [PATCH 4/8] Move foundry check to a separate function and use string_view.starts_with instead of strcmp. --- rts/Rendering/Fonts/CFontTexture.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index 0fb58d1ba1..05ab6eaac5 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -292,6 +292,16 @@ bool FtLibraryHandlerProxy::CheckGenFontConfigFull(bool console) /*******************************************************************************/ #ifndef HEADLESS +static bool IsFoundryOkay(std::string_view foundry) +{ + /* These foundry codes are defaults from some editors and can make pattern + * search fail to provide proper results on the first items. + */ + if (foundry.starts_with(std::string_view{"UKWN"}) || foundry.starts_with(std::string_view{"ukwn"})) + return false; + return true; +} + static inline uint64_t GetKerningHash(char32_t lchar, char32_t rchar) { RECOIL_DETAILED_TRACY_ZONE; @@ -460,7 +470,7 @@ static std::shared_ptr GetFontForCharacters(const std::vector(foundry)) != 0 && strcmp("ukwn", reinterpret_cast(foundry)) != 0) + if (foundry && IsFoundryOkay(reinterpret_cast(foundry))) FcPatternAddString(pattern, FC_FOUNDRY, foundry); } From 2ed31adfc6b7bc5af674114392387e6930674a26 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Sat, 16 Nov 2024 11:00:55 +0100 Subject: [PATCH 5/8] Do not add foundry to font search pattern. --- rts/Rendering/Fonts/CFontTexture.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index 05ab6eaac5..f20c9f6213 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -292,16 +292,6 @@ bool FtLibraryHandlerProxy::CheckGenFontConfigFull(bool console) /*******************************************************************************/ #ifndef HEADLESS -static bool IsFoundryOkay(std::string_view foundry) -{ - /* These foundry codes are defaults from some editors and can make pattern - * search fail to provide proper results on the first items. - */ - if (foundry.starts_with(std::string_view{"UKWN"}) || foundry.starts_with(std::string_view{"ukwn"})) - return false; - return true; -} - static inline uint64_t GetKerningHash(char32_t lchar, char32_t rchar) { RECOIL_DETAILED_TRACY_ZONE; @@ -436,7 +426,6 @@ static std::shared_ptr GetFontForCharacters(const std::vector("not used"); @@ -457,7 +446,6 @@ static std::shared_ptr GetFontForCharacters(const std::vector GetFontForCharacters(const std::vector(foundry))) - FcPatternAddString(pattern, FC_FOUNDRY, foundry); } FcDefaultSubstitute(pattern); From a83eab8d962aadaad4a3b2d70380a7cd3d83fad3 Mon Sep 17 00:00:00 2001 From: Saurtron Date: Mon, 18 Nov 2024 00:29:01 +0100 Subject: [PATCH 6/8] Remove all use of osFontsDir. --- rts/Rendering/Fonts/CFontTexture.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index f20c9f6213..cc13a62760 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -182,14 +182,6 @@ class FtLibraryHandler { return false; } - char osFontsDir[8192]; - - #ifdef _WIN32 - ExpandEnvironmentStrings("%WINDIR%\\fonts", osFontsDir, sizeof(osFontsDir)); // expands %HOME% etc. - #else - strncpy(osFontsDir, "/etc/fonts/", sizeof(osFontsDir)); - #endif - FcConfigAppFontClear(GetFCConfig()); FcConfigAppFontAddDir(GetFCConfig(), reinterpret_cast("fonts")); @@ -204,11 +196,11 @@ class FtLibraryHandler { } if (FtLibraryHandler::CheckFontConfig()) { - LOG_MSG("[%s] fontconfig for directory \"%s\" up to date", false, __func__, osFontsDir); + LOG_MSG("[%s] fontconfig up to date", false, __func__); return true; } - LOG_MSG("[%s] creating fontconfig for directory \"%s\"", false, __func__, osFontsDir); + LOG_MSG("[%s] creating fontconfig", false, __func__); return FcConfigBuildFonts(GetFCConfig()); #endif From db80ad8c771cc3f074cc99c7c24749b1a21baefb Mon Sep 17 00:00:00 2001 From: Saurtron Date: Mon, 18 Nov 2024 00:31:03 +0100 Subject: [PATCH 7/8] List all fontconfig cache dirs. --- rts/Rendering/Fonts/CFontTexture.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index cc13a62760..29bc7c008d 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -188,8 +188,7 @@ class FtLibraryHandler { { auto dirs = FcConfigGetCacheDirs(GetFCConfig()); FcStrListFirst(dirs); - for (FcChar8* dir = FcStrListNext(dirs), *prevDir = nullptr; dir != nullptr && dir != prevDir; ) { - prevDir = dir; + for (FcChar8* dir = FcStrListNext(dirs); dir != nullptr; dir = FcStrListNext(dirs)) { LOG_MSG("[%s] Using Fontconfig cache dir \"%s\"", false, __func__, dir); } FcStrListDone(dirs); From 31e80389825a87bd675a02c7897c6c6f5fa1483a Mon Sep 17 00:00:00 2001 From: Saurtron Date: Mon, 18 Nov 2024 00:33:06 +0100 Subject: [PATCH 8/8] Disable home folder usage so engine defined cache will be used instead. --- rts/Rendering/Fonts/CFontTexture.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index 29bc7c008d..7f872fcfcb 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -120,6 +120,7 @@ class FtLibraryHandler { return; } + FcConfigEnableHome(FcFalse); config = FcInitLoadConfigAndFonts(); if (!config) return;