问题描述
问题:如我的QApplication
所示,对我的QFont
进行字距调整对字体的字距没有影响.
Problem: Kerning my QFont
has no affect on the font's kerning as displayed in my QApplication
.
- 在Qt中,字距调整默认情况下应用于
QFont
- 尝试失败
QFont.setKerning(True)
-
QFont.setKerning(False)
对字体显示也没有影响 - 字体为OpenType(
.otf
),并且QFont.kerning()
返回True
- 在其他应用程序(例如Microsoft Word中成功)调整该字体
- 其他
QFont
方法(例如QFont.setLetterSpacing
)可以成功使用此字体 - 字体为空,文件名为
Idler-Inner.otf
- 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
) andQFont.kerning()
returnsTrue
- Kerning this font in other applications e.g., Microsoft Word is successful
- Other
QFont
methods, such asQFont.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.
这似乎与字体类型有关.我能够使用ttf字体,也无法使用Qt中的其他otf字体.尽管otf> ttf转换是某些字体的解决方案-对于像我这样的其他字体,它似乎破坏了字体.
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.
令人惊讶的是,Qt不支持主要字体类型的字距调整.否则,我唯一想到的解决方案就是破解字体(转换为ttx并以某种方式手动转换为ttf,而不会过时).
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.
推荐答案
看qfontengine.cpp
中的源代码,我发现了一个函数loadKerningPairs
.这包含一行
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'));
看起来似乎是从字体的主表列表中加载了旧样式的TTF 字距调整表.
which appears to load an old style TTF kerning table from the font's main list of tables.
此字距调整表包含成对的字符及其关联的调整值.它被存储在QFont
中,并且在绘制时,通过简单的查找就可以检索这些值.
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.
但是,在现代的OpenType字体(TrueType或Type-1样式)中,kern
子表可能不存在,因为OpenType的功能 GPOS
的功能要强大得多.该表的二进制格式也更加复杂.例如,可以为左,右或两个要紧缩的字符定义字符类,而不是单个字符.似乎此功能以及其他OpenType功能尚未在QFont中实现(目前,根据2016年9月11日).
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
不仅定义字距调整,而且还定义了许多其他功能,例如大写字母的自定义跟踪,上标和下标定位以及字符上或下的重音符号自动放置,您可以为所有这些功能指定不同的脚本类型甚至不同的语言都可以使用不同的值.
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.
这篇关于Qt QFont字距-不影响/字距字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!