I imitated the code in this link, except that I wanted to add support for local fonts, so the code was adapted like this.
FcConfig* config = FcInitLoadConfigAndFonts();
FcConfigAppFontAddDir(config, (FcChar8*) "../fonts");
FcConfigSubstitute(config, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
FcStrList* dirs = FcConfigGetFontDirs(config);
FcChar8* current;
while ((current = FcStrListNext(dirs)) != NULL)
printf("%s\n", (char*) current);
FcResult res;
FcPattern* font = FcFontMatch(config, pat, &res);
if (font)
{
FcChar8* file = NULL;
if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch)
{
printf("%s\n", (char*) file);
}
FcPatternDestroy(font);
}
FcPatternDestroy(pat);
FcStrListDone(dirs);
However, I found the following situation:
- A
.uuid
file appears infonts
directory, meaning that the directory (along with font files in it) is correctly found. - The printed directories does not contain my custom directory.
- Even when I am referencing a font that I put into the custom directory and does not exist in system font directories, the system cannot find it, and instead a fallback font (Noto Sans CJK) is matched instead.
Update: The fonts can only be referenced through font name as opposed to file name. Case closed.