diff --git a/basegraph.cpp b/basegraph.cpp index a5902965..91c3980a 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -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) {