gpt4 book ai didi

truetype - 无法获得某些带有Freetype的特定.ttf字体的字距调整

转载 作者:行者123 更新时间:2023-12-04 08:06:16 35 4
gpt4 key购买 nike

我正在尝试使用freetype 2.6库从某些.ttf字体中提取字距调整信息。

这是我获得字距调整信息(通过字符循环)的方式:

if( FT_HAS_KERNING(face->getFace()) && previous ){
FT_Vector delta;
FT_UInt glyph_index = FT_Get_Char_Index( face->getFace(), character );
FT_UInt prev_index = FT_Get_Char_Index( face->getFace(), previous );
FT_Get_Kerning( face->getFace(), prev_index, glyph_index,
FT_KERNING_DEFAULT, &delta );
kerning = delta.x >> 6;
}

我使用了一些不同的字体尝试了该程序:“Times new roman.ttf”,“Tymes.ttf”,“minion.otf”。
仅对于Times New Roman字体,字距调整信息已正确提取,我通过记录信息进行了检查。

问题是我不理解为什么其他2种字体的字距始终为0(即FT_HAS_KERNING返回false,而FT_GetKerning始终返回0)。

我用fontforge检查,“VA”和“To”对存在字距调整信息,并且它们在那里!因此,它们必须存储在.ttf中。但是,对于上面的代码,“VA”或“To”的字距调整始终为0,否则FT_HAS_KERNING返回false。

我在这里缺少任何freetype选项或设置吗?
任何启发都值得赞赏。

编辑:
我正在设定脸部尺寸
FT_Set_Pixel_Sizes( face->getFace(), 0, size);

编辑:
fontforge中“tymes”字体的字距信息:
enter image description here

最佳答案

Freetype只能从字体的kern表中检索字距调整值,而不能从更现代的实现(使用GPOS作为OpenType功能)中检索字距调整值。从documentation:

Note that OpenType fonts (OTF) provide two distinct mechanisms for kerning, using the ‘kern’ and ‘GPOS’ tables, respectively, which are part of the OTF files. Older fonts only contain the former, while recent fonts contain both tables or even ‘GPOS’ data only. FreeType only supports kerning via the (rather simple) ‘kern’ table. For the interpretation of kerning data in the (highly sophisticated) ‘GPOS’ table you need a higher-level library like ICU or HarfBuzz since it can be context dependent (this is, the kerning may vary depending on the position within a text string, for example).



您的FreeType代码可用于Times New Roman(我的名称是“Monotype:Times New Roman Regular:Version 5.11(Microsoft)”),因为它包含两个表:
tag 'GPOS'  checksum 5dfeb897  offset   778576  length    43506
tag 'kern' checksum a677acd1 offset 734088 length 5220

但其他字体不包含 kern

与普通的 GPOS相比, kern字距调整是首选,因为它的表可以链接到特定的脚本和语言,并且可以提供更好的控制。

也有充分的理由只包含一种类型的表-如果两种表都存在,则由字体渲染器选择一种。例如, Microsoft's Recommendations for OpenType Fonts声明以下内容:

The OFF specification allows CFF OT fonts to express their kerning in a kern table. Many OFF text layout engines support this. Windows GDI’s CFF OT driver, however, ignores the kern table in a CFF OT font when it prepares kerning pairs to report via its pair kerning API.
When a kern table and GPOS table are both present in a font, and an OFF layout engine is requested to apply kerning to a run of text of a particular script and language system: (a) If the number of kern feature lookups in the resolved language system in the GPOS table is zero, then the kern table should be applied, followed by any remaining GPOS features requested. (b) If the number of kern feature lookups in the resolved language system in the GPOS table is non-zero, then all GPOS lookups, including the kern lookups, should be applied in the usual way and the kern table data ignored.

关于truetype - 无法获得某些带有Freetype的特定.ttf字体的字距调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31782261/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com