无法使用freetype获得某些特定.ttf字体的字距调整 [英] Cannot get the kerning of some specific .ttf fonts with freetype

查看:379
本文介绍了无法使用freetype获得某些特定.ttf字体的字距调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to extract kerning information out of some .ttf fonts with freetype 2.6 library.

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

This is how I get kerning informations (looping through characters):

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字体,字距调整信息已正确提取,我通过记录信息进行了检查.

I tried the program with some different fonts: "Times new roman.ttf", "Tymes.ttf", "minion.otf". For Times new Roman font only, the kerning information are correctly extracted, and I checked that by logging the info.

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

The problem is that I don't understand why the kerning is always 0 (i.e. FT_HAS_KERNING returns false, AND FT_GetKerning returns 0 anyway) for the other 2 fonts.

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

I checked with fontforge that kerning info are present for pairs "VA" and "To", and they are there! So they must be stored in the .ttf. Nevertheless, with the code above the kerning is always 0 for "VA" or "To", or FT_HAS_KERNING returns false.

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

Is there any freetype option or setting that I am missing here? Any kind of enlightenment is appreciated..

我正在使用设置脸部尺寸

I am setting the face size with

FT_Set_Pixel_Sizes( face->getFace(), 0, size);

fontforge中"tymes"字体的字距信息:

Kerning info for "tymes" font in fontforge:

推荐答案

Freetype只能从字体的kern表中检索字距调整值,而不能从更现代的实现中使用GPOS检索为OpenType功能.从文档:

Freetype can only retrieve kerning values from a font's kern table, not from the more modern implementation as an OpenType feature using GPOS. From the documentation:

请注意,OpenType字体(OTF)提供了两种不同的字距调整机制,分别使用了作为OTF文件一部分的"kern"和"GPOS"表.旧字体仅包含前者,而新字体仅包含两个表,甚至仅包含"GPOS"数据. FreeType仅通过(非常简单的)"kern"表支持字距调整.为了解释(高度复杂的)"GPOS"表中的字距调整数据,您需要一个更高级别的库,例如 ICU HarfBuzz ,因为它可能与上下文相关(也就是说,字距调整可能会根据文本字符串中的位置而有所不同,例如例如).

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:版本5.11(Microsoft)"),因为它包含两个表:

Your FreeType code works with Times New Roman (mine is "Monotype:Times New Roman Regular:Version 5.11 (Microsoft)") because it contains both tables:

tag 'GPOS'  checksum 5dfeb897  offset   778576  length    43506
tag 'kern'  checksum a677acd1  offset   734088  length     5220

,但其他字体不包含kern.

GPOS字距调整是首选,因为其表可以链接到特定的脚本和语言,并且可以提供更好的控制.

GPOS kerning is preferred over plain kern because its tables can be linked to a particular script and language, and it offers finer control.

还有很好的理由只包含一种类型的表-如果两种表都存在,则由字体渲染器选择一种.例如, Microsoft的OpenType字体建议指出:

There are also good reasons to contain only one type of table – if both are present, it's up to the font renderer to select one. Microsoft's Recommendations for OpenType Fonts, for example, states the following:

OFF规范允许CFF OT字体在字距表中表示字距.许多OFF文本布局引擎都支持此功能. Windows GDI的CFF OT驱动程序在准备字距调整对以通过其对字距调整API进行报告时,会忽略CFF OT字体中的字距表.
当字距表和GPOS表都以字体存在,并且要求OFF布局引擎将字距调整应用于特定脚本和语言系统的文本运行时:(a)如果已解析的字距特征查询数GPOS表中的语言系统为零,则应应用kern表,然后再请求所有剩余的GPOS功能. (b)如果GPOS表中已解析语言系统中的核子特征查找数不为零,则应按常规方式应用所有GPOS查找,包括核子查找,而忽略核子表数据.

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.

这篇关于无法使用freetype获得某些特定.ttf字体的字距调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆