c语言读取字体库,如何使用fontconfig获取字体列表( c/C++ )?_c++_开发99编程知识库...

我有一個類似的問題,發現了這張文章( fontconfig文檔很難通過) 。 對mindaugasj的響應非常有用,但要注意調用 FcPatternPrint()的額外行,或者列印 FcNameUnparse()的結果。 此外,還需要向傳遞給 FcObjectSetBuild的參數列表中添加 FC_FILE 參數。 像這樣:FcConfig* config = FcInitLoadConfigAndFonts();

FcPattern* pat = FcPatternCreate();

FcObjectSet* os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_LANG, FC_FILE, (char *) 0);

FcFontSet* fs = FcFontList(config, pat, os);

printf("Total matching fonts: %dn", fs->nfont);

for (int i=0; fs && i nfont; ++i) {

FcPattern* font = fs->fonts[i];

FcChar8 *file, *style, *family;

if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch &&

FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch &&

FcPatternGetString(font, FC_STYLE, 0, &style) == FcResultMatch)

{

printf("Filename: %s (family %s, style %s)n", file, family, style);

}

}

if (fs) FcFontSetDestroy(fs);

我有一些不同的問題需要解決,我需要找到一個字體文件傳遞給 FC_New_Face() 函數的一個字體"姓名"。 這裡代碼可以使用fontconfig查找匹配名稱的最佳文件:FcConfig* config = FcInitLoadConfigAndFonts();

//configure the search pattern,

//assume"name" is a std::string with the desired font name in it

FcPattern* pat = FcNameParse((const FcChar8*)(name.c_str()));

FcConfigSubstitute(config, pat, FcMatchPattern);

FcDefaultSubstitute(pat);

//find the font

FcPattern* font = FcFontMatch(config, pat, NULL);

if (font)

{

FcChar8* file = NULL;

if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch)

{

//save the file to another std::string

fontFile = (char*)file;

}

FcPatternDestroy(font);

}

FcPatternDestroy(pat);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值