qtfontsopentypekerning

Qt QFont Kerning - Not Affecting/Kerning Font


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

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.


Solution

  • 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.