-
Notifications
You must be signed in to change notification settings - Fork 5
/
fontconfig-resolve.c
38 lines (30 loc) · 996 Bytes
/
fontconfig-resolve.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// cc fontconfig-resolve.c `pkg-config --libs --cflags fontconfig` -Wall && ./a.out
// https://gist.github.com/CallumDev/7c66b3f9cf7a876ef75f#gistcomment-3355764
#include <stdio.h>
#include <stdlib.h>
#include <fontconfig/fontconfig.h>
int main() {
FcInit();
FcConfig *config = FcInitLoadConfigAndFonts();
// not necessarily has to be a specific name
FcPattern *pat = FcNameParse((const FcChar8 *)"Arial");
// NECESSARY; it increases the scope of possible fonts
FcConfigSubstitute(config, pat, FcMatchPattern);
// NECESSARY; it increases the scope of possible fonts
FcDefaultSubstitute(pat);
char *fontFile;
FcResult result;
FcPattern *font = FcFontMatch(config, pat, &result);
if (font) {
FcChar8 *file = NULL;
if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
fontFile = (char *)file;
printf("%s\n", fontFile);
}
}
FcPatternDestroy(font);
FcPatternDestroy(pat);
FcConfigDestroy(config);
FcFini();
return 0;
}