如何获取具有 Freetype2 的真正类型字体支持的代码点列表 C++



如何使用 Freetype2 库获取真类型字体支持的字形或代码点列表?

Freetype 提供了两个函数来完成此任务。第一个是FT_Get_First_Char(FT_Face脸,FT_UInt * agindex(。

此函数将返回字体支持的第一个字符的代码。它还会将 agindex 指向的变量设置为字形在字体中的索引。请注意,如果设置为 0,则表示字体中没有其他字符。

你需要的下一个函数是FT_Get_Next_Char(FT_Face face、FT_ULong char_code FT_UInt * agindex(。这将允许您通过返回其值来获取字体中的下一个可用字符。请注意,与FT_Get_First_Char一样,这也会在返回最终字形时将 agindex 设置为零。

所以现在举一个工作的例子:

// Load freetype library before hand.
FT_Face face;
// Load the face by whatever means you feel are best.
FT_UInt index;
FT_ULong c = FT_Get_First_Char(face, &index);
while (index) {
std::cout << "Supported Code: " << c << std::endl;
// Load character glyph.
FT_Load_Char(face, c, FT_LOAD_RENDER);
// You can now access the glyph with:
// face->glyph;
// Now grab the next charecter.
c = FT_Get_Next_Char(face, c, &index);
}
// Make sure to clean up your mess.

最新更新