gpt4 book ai didi

c++ - fontconfig 找不到字体

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:18:51 36 4
gpt4 key购买 nike

我试图让我的 C++ 程序检测我的 Win32 机器上安装的字体。我通过从 GTK+ 包中获取库来尝试 fontconfig。

我使用以下测试代码:



#include
    
     

FcBool success = FcInit();
如果(!成功){
返回假;
}

FcConfig *config = FcInitLoadConfigAndFonts();
如果(!配置){
返回假;
}

FcChar8 *s, *文件;

FcPattern *p = FcPatternCreate();
FcObjectSet *os = FcObjectSetBuild (FC_FAMILY,NULL);
FcFontSet *fs = FcFontList(config, p, os);

LOG("字体总数: %d\n", fs->nfont);
for (int i=0; fs && i < fs->nfont; i++) {
FcPattern *font = fs->fonts[i];

s = FcNameUnparse(字体);
LOG("字体: %s\n", s);
免费;

if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
LOG("文件名: %s\n", 文件);
}
}

//销毁这里的对象 ...

不幸的是这个测试应用程序只打印:

Total fonts: 0

我知道我的机器上安装了字体并且我知道 Gimp2.0 检测到它们,所以我的测试代码一定有问题。有人知道吗?

除了链接 fontconfig-1.dll,我什么也没做。我没有创建任何配置文件或任何东西,因为我无法在任何地方阅读关于必须这样做的内容。

我愿意接受您的建议,谢谢!

最佳答案

代替:

FcConfig *config = FcInitLoadConfigAndFonts ();

尝试:

FcConfig *config = FcConfigCreate();
FcConfigAppFontAddDir(config, (const FcChar8 *)"C:\\Windows\\Fonts");

(这是惰性版本,您应该调整它以关闭 GetWindowsDirectory...)

关于c++ - fontconfig 找不到字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13594787/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com