Skip to content

Commit bd9e0a7

Browse files
committed
fixed FONTCONFIG compilation
1 parent d6ec3b1 commit bd9e0a7

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

basegraph.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,26 @@ EX int font_id = 0;
250250
#ifdef FONTCONFIG
251251
TTF_Font* findfont(int siz) {
252252

253+
auto orig = cfont->filename;
254+
253255
FcPattern *pat;
254256
FcResult result;
255257
if (!FcInit()) return nullptr;
256-
pat = FcNameParse((FcChar8 *)cfont->filename.c_str());
258+
259+
string s =cfont->filename;
260+
auto rep = [&] (string what, string by) {
261+
int pos = s.size() - what.size();
262+
if(pos < 0) return;
263+
if(s.substr(pos) == what) s = s.substr(0, pos) + by;
264+
};
265+
rep(".ttf", "");
266+
rep(".otf", "");
267+
rep(".TTF", "");
268+
rep(".OTF", "");
269+
rep("-Bold", ":weight=bold");
270+
rep("-Regular", ":weight=regular");
271+
272+
pat = FcNameParse((FcChar8 *)s.c_str());
257273
FcConfigSubstitute(0, pat, FcMatchPattern);
258274
FcDefaultSubstitute(pat);
259275

@@ -270,7 +286,7 @@ TTF_Font* findfont(int siz) {
270286
FcFini();
271287
cfont->use_fontconfig = false;
272288
if(debugflags & DF_INIT) println(hlog, "fontpath is: ", cfont->filename);
273-
return TTF_OpenFont(cfont->filename, siz);
289+
return TTF_OpenFont(cfont->filename.c_str(), siz);
274290
}
275291
#endif
276292

@@ -282,7 +298,7 @@ void loadfont(int siz) {
282298

283299
#ifdef FONTCONFIG
284300
if(cf == NULL && cfont->use_fontconfig)
285-
cf = find_font_using_fontconfig(siz);
301+
cf = findfont(siz);
286302
#endif
287303

288304
if(cf == NULL) {

0 commit comments

Comments
 (0)