diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2015-11-25 13:47:27 +0100 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2015-11-25 19:53:46 +0000 |
commit | 50cd0daf29d434b78cc70bbf732ee33b2bc18600 (patch) | |
tree | e2683bddf4ed9edb0846a9967c6b6de5f0b6a223 /src/platformsupport/fontdatabases | |
parent | 0325842b9926f87f22beb3b8dda32c20b2f994ec (diff) |
Fix kerned advances in QRawFont on OS X and Windows
On Windows, the wrong value was used to calculate the
design-to-device scale. The assumption has been that tmHeight
in the TEXTMETRIC is the pixel size of the em square, but
it is not, it's the height of the font (ascent + descent).
The pixel size of the font is defined to be the em square size
in pixels.
On OS X, the kerning data was never actually read from the
font. I've added a lazy initialization for this similar to
the one in the FT engine.
This was discovered when investigating QTBUG-48546, as it turned
out that the kerning information extracted by Qt in this case was
different from the one used by Harfbuzz.
I've changed testfont.ttf to kern "_2" so that the digit is positioned
directly on top of the underscore and constructed a test.
[ChangeLog][QRawFont] Fixed kerning on advances in QRawFont for
OS X and Windows.
Change-Id: Ic9a321ad119ea880cef89b861c75a820ab8d3182
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'src/platformsupport/fontdatabases')
-rw-r--r-- | src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm | 15 | ||||
-rw-r--r-- | src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 732aead62a..be1696dfe8 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -215,6 +215,8 @@ void QCoreTextFontEngine::init() Q_ASSERT((void *)(&ctfont + 1) == (void *)&cgFont); faceData.user_data = &ctfont; faceData.get_font_table = ct_getSfntTable; + + kerningPairsLoaded = false; } glyph_t QCoreTextFontEngine::glyphIndex(uint ucs4) const @@ -788,4 +790,17 @@ QFontEngine::Properties QCoreTextFontEngine::properties() const return result; } +void QCoreTextFontEngine::doKerning(QGlyphLayout *g, ShaperFlags flags) const +{ + if (!kerningPairsLoaded) { + kerningPairsLoaded = true; + qreal emSquare = CTFontGetUnitsPerEm(ctfont); + qreal scale = emSquare / CTFontGetSize(ctfont); + + const_cast<QCoreTextFontEngine *>(this)->loadKerningPairs(QFixed::fromReal(scale)); + } + + QFontEngine::doKerning(g, flags); +} + QT_END_NAMESPACE diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 1c33ae7d84..c22d1ddc0a 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -97,6 +97,7 @@ public: glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed, const QTransform &matrix, GlyphFormat) Q_DECL_OVERRIDE; QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) Q_DECL_OVERRIDE; QFixed emSquareSize() const Q_DECL_OVERRIDE; + void doKerning(QGlyphLayout *g, ShaperFlags flags) const Q_DECL_OVERRIDE; bool supportsTransformation(const QTransform &transform) const Q_DECL_OVERRIDE; @@ -134,6 +135,7 @@ private: CGAffineTransform transform; QFixed avgCharWidth; QFontEngine::FaceId face_id; + mutable bool kerningPairsLoaded; }; CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef); |