Qt QFont Kerning - Not Affecting/Kerning Font

≯℡__Kan透↙ 提交于 2019-12-23 22:12:47

问题


Problem: Kerning my QFont has no affect on the font's kerning as displayed in my QApplication.

  • In Qt, kerning is applied to a QFont by default
  • Tried QFont.setKerning(True) unsuccessfully
  • QFont.setKerning(False) also has no affect on font display
  • Font is OpenType (.otf) and QFont.kerning() returns True
  • Kerning this font in other applications e.g., Microsoft Word is successful
  • Other QFont methods, such as QFont.setLetterSpacing work successfully on this font
  • Font is Idler, filename is Idler-Inner.otf

Apparently no one else is having this problem. Can't find anything on this topic.

Update

This seems related to the font type. I'm able to kern ttf fonts and am unable to kern other otf fonts in Qt. While otf>ttf conversion is a solution for some fonts- for others like mine it seems to destroy the font.

It's surprising that Qt isn't supporting kerning of a major font type. Otherwise the only solution I can think of is hacking the font (converting to ttx and somehow manually converting to ttf in a way that doesn't deprecate it).

Too much work for a font; at least for a developer for a font.


回答1:


Looking at the source code in qfontengine.cpp, I find a function loadKerningPairs. This contains the line

QByteArray tab = getSfntTable(MAKE_TAG('k', 'e', 'r', 'n'));

which appears to load an old style TTF kerning table from the font's main list of tables.

This kerning table contains pairs of characters and their associated adjust value. It gets stored in the QFont, and when drawing, a simple look-up retrieves the values.

However, in modern OpenType fonts (either TrueType or Type-1 flavour), the kern subtable may not be present because the OpenType feature GPOS is much more powerful. The binary format of this table is also much more complicated; for instance, rather than individual characters, one can define character classes for left, right, or both characters to be kerned. It seems this, as well as other OpenType features, have not been implemented in QFont (yet, per 11-Sep-2016).

GPOS does not only define kerning, but lots of other functionality as well, such as custom tracking for capitals, superscript and subscript positioning, and automatic placement of accents on or under characters, and for all these features you can specify different values for different script types and even distinct languages.



来源:https://stackoverflow.com/questions/39298916/qt-qfont-kerning-not-affecting-kerning-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!