Qt QFont Kerning - Not Affecting/Kerning Font
Asked Answered
B

1

3

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.

Bayless answered 2/9, 2016 at 18:45 Comment(3)
What do you want to do? enabling kerning or disabling it?Avidin
Enable kerning.Bayless
Your update seems to nail it. In TTFs, kerning is a simple table. In OpenType fonts the same can be used, but in addition it supports a much more complicated scheme. Because this offers more control on kerning, font designers prefer it over the old "2 characters at a time" approach.Bryson
B
5

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.

Bryson answered 11/9, 2016 at 23:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.