From 1d5c29da59f2007b3aa75dbceae1bacfabf84da2 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 24 Feb 2016 11:55:50 +0100 Subject: [PATCH] Use correct underline thickness on OS X MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the calculated underline thickness would be approximately correct for many fonts and sizes, it was sometimes incorrect, e.g. for 18 pt Helvetica. Found while investigating QTBUG-33708. Change-Id: Ic1d8f2d809c02235d8f15f0414536e04c2a7b844 Reviewed-by: Konstantin Ritt Reviewed-by: Tor Arne Vestbø --- .../fontdatabases/mac/qfontengine_coretext.mm | 7 +++++++ .../fontdatabases/mac/qfontengine_coretext_p.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 92430c35bd..db26209b2b 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -215,6 +215,8 @@ void QCoreTextFontEngine::init() } else avgCharWidth = QFontEngine::averageCharWidth(); + underlineThickness = QFixed::fromReal(CTFontGetUnderlineThickness(ctfont)); + cache_cost = (CTFontGetAscent(ctfont) + CTFontGetDescent(ctfont)) * avgCharWidth.toInt() * 2000; // HACK hb_coretext requires both CTFont and CGFont but user_data is only void* @@ -757,6 +759,11 @@ bool QCoreTextFontEngine::supportsTransformation(const QTransform &transform) co return false; } +QFixed QCoreTextFontEngine::lineThickness() const +{ + return underlineThickness; +} + QFontEngine::Properties QCoreTextFontEngine::properties() const { Properties result; diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h index 6f12f5a705..4ad062b699 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h @@ -92,6 +92,8 @@ public: int synthesized() const Q_DECL_OVERRIDE { return synthesisFlags; } bool supportsSubPixelPositions() const Q_DECL_OVERRIDE { return true; } + QFixed lineThickness() const Q_DECL_OVERRIDE; + void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight); FaceId faceId() const Q_DECL_OVERRIDE; @@ -140,6 +142,7 @@ private: int synthesisFlags; CGAffineTransform transform; QFixed avgCharWidth; + QFixed underlineThickness; QFontEngine::FaceId face_id; mutable bool kerningPairsLoaded; };