Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linux fontconfig #1771

Merged
merged 8 commits into from
Nov 24, 2024
23 changes: 5 additions & 18 deletions rts/Rendering/Fonts/CFontTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class FtLibraryHandler {
return;
}

config = FcConfigCreate();
FcConfigEnableHome(FcFalse);
config = FcInitLoadConfigAndFonts();
if (!config)
return;

Expand Down Expand Up @@ -182,34 +183,24 @@ 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<const FcChar8*>("fonts"));
FcConfigAppFontAddDir(GetFCConfig(), reinterpret_cast<const FcChar8*>(osFontsDir));

{
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);
}

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
Expand Down Expand Up @@ -427,7 +418,6 @@ static std::shared_ptr<FontFace> GetFontForCharacters(const std::vector<char32_t
FcBool outline = FcFalse;

FcChar8* family = nullptr;
FcChar8* foundry = nullptr;

const FcChar8* ftname = reinterpret_cast<const FcChar8*>("not used");

Expand All @@ -448,7 +438,6 @@ static std::shared_ptr<FontFace> GetFontForCharacters(const std::vector<char32_t
FcPatternGetDouble( origPattern, FC_PIXEL_SIZE, 0, &pixelSize);

FcPatternGetString( origPattern, FC_FAMILY , 0, &family );
FcPatternGetString( origPattern, FC_FOUNDRY, 0, &foundry);

}

Expand All @@ -461,8 +450,6 @@ static std::shared_ptr<FontFace> GetFontForCharacters(const std::vector<char32_t

if (family)
FcPatternAddString(pattern, FC_FAMILY, family);
if (foundry)
FcPatternAddString(pattern, FC_FOUNDRY, foundry);
}

FcDefaultSubstitute(pattern);
Expand Down