如何访问ttf字体(不是otf)的GDEF / GPOS / GSUB?

问题描述 投票:1回答:1

一个主要问题,几个承保问题(抱歉)。

我正在尝试用ttf字体读取GSUB信息(和其他表格)。怎么做?我可以使用哪个lib?

GSUB是一个替换表,用于说明在同一邻域中使用的字形必须如何变换为另一个字形。在许多语言中是很常见的,而在英语中,它更为罕见,但最好的例子是连字。

OpenType fonts (otf)有很好的记录,我知道它存在于Truetype字体(ttf)中。

但我怎么能访问它?有没有像Freetype + Harfbuzz这样的图书馆?看起来Freetype只能访问OTF表,而不是TTF,对吗?

FT_OpenType_Validate:此功能仅适用于OpenType字体

Harfbuzz是否可选择或强制要求满足这些需求?

文件很差(在我的pov),所以我正在寻找经验,工作的例子。

似乎很难让freetype + harfbuzz在Windows上一起工作,它真的需要吗?如何?

资料来源:

mactype

official poor example

我的测试代码没有用,因为GSUB是一个“未实现的功能”,Freetype说:

#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;
}
c++ windows true-type-fonts freetype freetype2
1个回答
0
投票

在Windows上,您必须启用OpenType验证模块。如果您使用Visual Studio构建FreeType,请按照以下步骤操作。

freetype/config/ftmodule.h中添加:

FT_USE_MODULE( FT_Module_Class, otv_module_class )

然后在Solution Explorer中将src/otvalid/otvalid.c添加到项目中。

您已准备好构建库。不要忘记使用新库或目标文件更新项目。

使用这个我能够访问GPOS表。但不要非常乐观。 FreeType中的OpenType表支持超级有限。所以,你真正得到的是指向字节的原始指针。为了获得一些有用的数据,你必须根据OpenType规范解析这些字节。我会说考虑到OpenType规范的复杂性,这不是一项微不足道的任务。我甚至会说它过于复杂,但仍有可能。

如果您决定这样做,请记住您必须反转从任何表中读取的数据的字节顺序。

© www.soinside.com 2019 - 2024. All rights reserved.