【问题标题】:fontconfig finds no fontsfontconfig 找不到字体
【发布时间】:2012-11-27 23:02:26
【问题描述】:

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

我使用以下测试代码:

#include<fontconfig.h>

FcBool success = FcInit ();
if ( !success ) {
    return false;
}

FcConfig *config = FcInitLoadConfigAndFonts ();
if(!config) {
    return false;
}

FcChar8 *s, *file;

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

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

    s = FcNameUnparse(font);
    LOG("Font: %s\n", s);
    free(s);

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

// destroy objects here ...

很遗憾,这个测试应用程序只打印:

总字体:0

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

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

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

【问题讨论】:

    标签: c++ configuration fonts fontconfig


    【解决方案1】:

    代替:

    FcConfig *config = FcInitLoadConfigAndFonts ();
    

    试试:

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

    (这是懒惰的版本,你应该调整它以关闭GetWindowsDirectory...)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-19
      • 2018-03-02
      • 1970-01-01
      • 2019-03-01
      • 2017-06-25
      • 2018-11-28
      • 2018-12-07
      • 2015-11-04
      相关资源
      最近更新 更多