一个主要问题,几个下面的问题(抱歉)。
我正在尝试读取ttf字体中的GSUB信息(和其他表格)。如何做到这一点?我可以使用哪个库?
GSUB是一个替换表,告诉在同一邻域中使用的字形必须变形为另一个字形。它在许多语言中非常常见,在英语中更为罕见,但最好的例子是连字号。
对于OpenType字体(otf)有很好的文档记录,我知道它也存在于Truetype字体(ttf)中。
但是我该如何访问它?是否有像Freetype + Harfbuzz这样的库?似乎Freetype只提供对OTF表的访问,而不是TTF,我对吗?
FT_OpenType_Validate
: 此函数仅适用于OpenType字体
对于这种需求,Harfbuzz是可选还是强制的?
文档很贫乏(在我的视角中),因此我正在寻找经验和工作示例。
在Windows上使freetype + harfbuzz一起工作似乎也很困难,这真的有必要吗?如何做到这一点?
来源:
我的测试代码无法工作,因为Freetype说GSUB是一个“未实现的功能”:
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OPENTYPE_VALIDATE_H
#include <stdexcept>
int main(int argc, char* argv[])
{
FT_Library ftLibrary;
FT_Error errorLib = FT_Init_FreeType(&ftLibrary);
if (errorLib)
throw std::runtime_error("Couldn't initialize the library: FT_Init_FreeType() failed");
FT_Face ftFace;
FT_Error errorFace = FT_New_Face(ftLibrary, argv[1], 0, &ftFace); //getting first face
if (errorFace)
throw std::runtime_error("Couldn't load the font file: FT_New_Face() failed");
FT_Bytes BASE = NULL;
FT_Bytes GDEF = NULL;
FT_Bytes GPOS = NULL;
FT_Bytes GSUB = NULL;
FT_Bytes JSTF = NULL;
FT_Error errorValidate = FT_OpenType_Validate(ftFace, FT_VALIDATE_GSUB, &BASE, &GDEF, &GPOS, &GSUB, &JSTF);
if (errorValidate)
throw std::runtime_error("Couldn't validate opentype datas");
//7=Unimplemented_Feature
FT_OpenType_Free(ftFace, BASE);
FT_OpenType_Free(ftFace, GDEF);
FT_OpenType_Free(ftFace, GPOS);
FT_OpenType_Free(ftFace, GSUB);
FT_OpenType_Free(ftFace, JSTF);
FT_Done_Face(ftFace);
FT_Done_FreeType(ftLibrary);
return 0;
}