本文介绍了无法使用freetype获得某些特定.ttf字体的字距调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试使用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 withFT_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:您的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 43506tag '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: 这篇关于无法使用freetype获得某些特定.ttf字体的字距调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!