1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-30 07:29:54 +00:00

fixed FONTCONFIG compilation

This commit is contained in:
Zeno Rogue 2024-11-03 21:35:05 +01:00
parent d6ec3b1fcc
commit bd9e0a7469

View File

@ -250,10 +250,26 @@ EX int font_id = 0;
#ifdef FONTCONFIG
TTF_Font* findfont(int siz) {
auto orig = cfont->filename;
FcPattern *pat;
FcResult result;
if (!FcInit()) return nullptr;
pat = FcNameParse((FcChar8 *)cfont->filename.c_str());
string s =cfont->filename;
auto rep = [&] (string what, string by) {
int pos = s.size() - what.size();
if(pos < 0) return;
if(s.substr(pos) == what) s = s.substr(0, pos) + by;
};
rep(".ttf", "");
rep(".otf", "");
rep(".TTF", "");
rep(".OTF", "");
rep("-Bold", ":weight=bold");
rep("-Regular", ":weight=regular");
pat = FcNameParse((FcChar8 *)s.c_str());
FcConfigSubstitute(0, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
@ -270,7 +286,7 @@ TTF_Font* findfont(int siz) {
FcFini();
cfont->use_fontconfig = false;
if(debugflags & DF_INIT) println(hlog, "fontpath is: ", cfont->filename);
return TTF_OpenFont(cfont->filename, siz);
return TTF_OpenFont(cfont->filename.c_str(), siz);
}
#endif
@ -282,7 +298,7 @@ void loadfont(int siz) {
#ifdef FONTCONFIG
if(cf == NULL && cfont->use_fontconfig)
cf = find_font_using_fontconfig(siz);
cf = findfont(siz);
#endif
if(cf == NULL) {