1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-01-11 18:00:34 +00:00

improvement to fontconfig support

This commit is contained in:
Zeno Rogue 2023-05-15 19:33:32 +02:00
parent c03e9cfeb4
commit 24cd670de0
2 changed files with 26 additions and 13 deletions

View File

@ -220,21 +220,25 @@ EX void present_screen() {
#if CAP_SDLTTF #if CAP_SDLTTF
string fontdefault = "DejaVuSans-Bold.ttf"; #define DEFAULT_FONT "DejaVuSans-Bold.ttf"
EX string fontpath = ISWEB ? "sans-serif" : string(HYPERFONTPATH) + fontdefault;
string findfont() { #ifdef FONTCONFIG
string answer = fontpath; /** if this is non-empty, find the font using fontconfig */
EX string font_to_find = DEFAULT_FONT;
#endif
/** actual font path */
EX string fontpath = ISWEB ? "sans-serif" : string(HYPERFONTPATH) + DEFAULT_FONT;
const string& findfont() {
#ifdef FONTCONFIG #ifdef FONTCONFIG
if ((answer.length() < fontdefault.length()) || (0 != answer.compare(answer.length() - fontdefault.length(), fontdefault.length(), fontdefault))) { if(font_to_find == "") return fontpath;
return answer;
}
FcPattern *pat; FcPattern *pat;
FcResult result; FcResult result;
if (!FcInit()) { if (!FcInit()) {
return answer; return fontpath;
} }
pat = FcNameParse((FcChar8 *)fontdefault.c_str()); pat = FcNameParse((FcChar8 *)font_to_find.c_str());
FcConfigSubstitute(0, pat, FcMatchPattern); FcConfigSubstitute(0, pat, FcMatchPattern);
FcDefaultSubstitute(pat); FcDefaultSubstitute(pat);
@ -243,15 +247,17 @@ string findfont() {
if (match) { if (match) {
FcChar8 *file; FcChar8 *file;
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch) { if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch) {
answer = (const char *)file; fontpath = (const char *)file;
} }
FcPatternDestroy(match); FcPatternDestroy(match);
} }
FcPatternDestroy(pat); FcPatternDestroy(pat);
FcFini(); FcFini();
font_to_find = "";
println(hlog, "fontpath is: ", fontpath);
#endif #endif
return answer; return fontpath;
} }
void loadfont(int siz) { void loadfont(int siz) {
fix_font_size(siz); fix_font_size(siz);

View File

@ -175,7 +175,14 @@ int arg::readCommon() {
else if(argis("-nogui")) { PHASE(1); noGUI = true; } else if(argis("-nogui")) { PHASE(1); noGUI = true; }
#ifndef EMSCRIPTEN #ifndef EMSCRIPTEN
#if CAP_SDL #if CAP_SDL
else if(argis("-font")) { PHASE(1); shift(); fontpath = args(); } else if(argis("-font")) { PHASE(1); shift(); fontpath = args();
#ifdef FONTCONFIG
font_to_find = "";
#endif
}
#ifdef FONTCONFIG
else if(argis("-find-font")) { PHASE(1); shift(); font_to_find = args(); }
#endif
#endif #endif
#endif #endif