英文:
Fontconfig: cannot find application font
问题
我模仿了这个链接中的代码(https://stackoverflow.com/questions/10542832/how-to-use-fontconfig-to-get-font-list-c-c),只是我想要添加对本地字体的支持,所以代码被修改如下。
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);
然而,我发现了以下情况:
- 在
fonts
目录中出现了一个.uuid
文件,表示该目录(以及其中的字体文件)被正确找到。 - 打印的目录不包含我的自定义目录。
- 即使我引用了我放入自定义目录中的字体,并且在系统字体目录中不存在,系统仍然找不到它,而是匹配了一个备用字体(Noto Sans CJK)。
更新:
只能通过字体名称而不是文件名引用字体。案件已结。
英文:
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.
答案1
得分: 2
更新: 字体只能通过字体名称引用,而不是文件名称。案件已结案。
英文:
Update: The fonts can only be referenced through font name as opposed to file name. Case closed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论