Skip to content

Commit

Permalink
Merge branch 'lua-fallback-fonts' into lua-fallback-fonts-with-atlasc…
Browse files Browse the repository at this point in the history
…lear
  • Loading branch information
saurtron committed Dec 14, 2024
2 parents 2a11114 + 6f5da57 commit 2fc1dbc
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions rts/Rendering/Fonts/CFontTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class FtLibraryHandler {
, lib(nullptr)
#ifdef USE_FONTCONFIG
, gameFontSet(nullptr)
, fallbackPattern(nullptr)
, basePattern(nullptr)
#endif // USE_FONTCONFIG
{
const FT_Error error = FT_Init_FreeType(&lib);
Expand All @@ -117,8 +117,8 @@ class FtLibraryHandler {
if (gameFontSet) {
FcFontSetDestroy(gameFontSet);
}
if (fallbackPattern) {
FcPatternDestroy(fallbackPattern);
if (basePattern) {
FcPatternDestroy(basePattern);
}
FcFini();
config = nullptr;
Expand Down Expand Up @@ -209,7 +209,7 @@ class FtLibraryHandler {
}

gameFontSet = FcFontSetCreate();
fallbackPattern = FcPatternCreate();
basePattern = FcPatternCreate();

// init app fonts dir
res = FcConfigAppFontAddDir(config, reinterpret_cast<const FcChar8*>("fonts"));
Expand Down Expand Up @@ -270,24 +270,24 @@ class FtLibraryHandler {
static FcFontSet *GetGameFontSet() {
return singleton->gameFontSet;
}
static FcPattern *GetFallbackPattern() {
return singleton->fallbackPattern;
static FcPattern *GetBasePattern() {
return singleton->basePattern;
}
static void ClearGameFontSet() {
FcFontSetDestroy(singleton->gameFontSet);
singleton->gameFontSet = FcFontSetCreate();
}
static void ClearFallbackPattern() {
FcPatternDestroy(singleton->fallbackPattern);
singleton->fallbackPattern = FcPatternCreate();
static void ClearBasePattern() {
FcPatternDestroy(singleton->basePattern);
singleton->basePattern = FcPatternCreate();
}
#endif
private:
FcConfig* config;
FT_Library lib;
#ifdef USE_FONTCONFIG
FcFontSet *gameFontSet;
FcPattern *fallbackPattern;
FcPattern *basePattern;
#endif

static inline std::unique_ptr<FtLibraryHandler> singleton = nullptr;
Expand Down Expand Up @@ -450,7 +450,7 @@ static std::shared_ptr<FontFace> GetFontForCharacters(const std::vector<char32_t

// create properties of the wanted font starting from our priorities pattern.
auto pattern = spring::ScopedResource(
FcPatternDuplicate(FtLibraryHandler::GetFallbackPattern()),
FcPatternDuplicate(FtLibraryHandler::GetBasePattern()),
[](FcPattern* p) { if (p) FcPatternDestroy(p); }
);

Expand Down Expand Up @@ -748,8 +748,8 @@ bool CFontTexture::AddFallbackFont(const std::string& fontfile)
// Add to priority fonts pattern
FcChar8* family = nullptr;
if (FcPatternGetString( pattern, FC_FAMILY , 0, &family ) == FcResultMatch) {
FcPattern *fallbackPattern = FtLibraryHandler::GetFallbackPattern();
FcPatternAddString(fallbackPattern, FC_FAMILY, family);
FcPattern *basePattern = FtLibraryHandler::GetBasePattern();
FcPatternAddString(basePattern, FC_FAMILY, family);
} else {
LOG_L(L_WARNING, "[%s] could not add priority for %s", __func__, fontfile.c_str());
return false;
Expand All @@ -773,7 +773,7 @@ void CFontTexture::ClearFallbackFonts()
if (!FtLibraryHandler::CanUseFontConfig())
return;

FtLibraryHandler::ClearFallbackPattern();
FtLibraryHandler::ClearBasePattern();
FtLibraryHandler::ClearGameFontSet();

needsClearGlyphs = true;
Expand Down

0 comments on commit 2fc1dbc

Please sign in to comment.