From a26a3cfbc7cd5c87afeda63eb324a2ba2a4c8192 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 16 Aug 2017 13:20:33 +0200 Subject: macOS: Fix matching of font weights for application fonts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5ad2e1cea1b2c08950c91174840f542806954d99 exposed a latent bug when matching font weights that do not exactly match any of the canonical weights in the system . It seems that when we registered the font with FontManager, it would modify the font weight to match a system weight, while we now get raw values from the font instead. So for Roboto Medium, for instance, we would now get 0.2 instead of 0.23, and since our conversion logic would convert everything between Light (-0.4) to Medium (0.23) to QFont::Normal, we would regard this as normal weight instead of medium. But on a linear scale, it makes more sense to match to the closest canonical weight instead of requiring exact matches. Note that the definition says that the middle between two weights should tend upwards, therefore we do the comparisons in decreasing order. [ChangeLog][QtGui][Text] Fixed matching of non-regular font weights for application fonts on macOS. Task-number: QTBUG-61520 Change-Id: Ieda4927c2c69ec72125257340cf06c683b031d05 Reviewed-by: Tor Arne Vestbø --- .../fontdatabases/mac/qfontengine_coretext.mm | 45 +++++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 49a6049c4b..66baf162d9 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -112,25 +112,32 @@ bool QCoreTextFontEngine::ct_getSfntTable(void *user_data, uint tag, uchar *buff QFont::Weight QCoreTextFontEngine::qtWeightFromCFWeight(float value) { - if (value >= kCTFontWeightBlack) - return QFont::Black; - if (value >= kCTFontWeightHeavy) - return QFont::ExtraBold; - if (value >= kCTFontWeightBold) - return QFont::Bold; - if (value >= kCTFontWeightSemibold) - return QFont::DemiBold; - if (value >= kCTFontWeightMedium) - return QFont::Medium; - if (value == kCTFontWeightRegular) - return QFont::Normal; - if (value <= kCTFontWeightUltraLight) - return QFont::Thin; - if (value <= kCTFontWeightThin) - return QFont::ExtraLight; - if (value <= kCTFontWeightLight) - return QFont::Light; - return QFont::Normal; +#define COMPARE_WEIGHT_DISTANCE(ct_weight, qt_weight) \ + { \ + float d; \ + if ((d = qAbs(value - ct_weight)) < distance) { \ + distance = d; \ + ret = qt_weight; \ + } \ + } + + float distance = qAbs(value - kCTFontWeightBlack); + QFont::Weight ret = QFont::Black; + + // Compare distance to system weight to find the closest match. + // (Note: Must go from high to low, so that midpoints are rounded up) + COMPARE_WEIGHT_DISTANCE(kCTFontWeightHeavy, QFont::ExtraBold); + COMPARE_WEIGHT_DISTANCE(kCTFontWeightBold, QFont::Bold); + COMPARE_WEIGHT_DISTANCE(kCTFontWeightSemibold, QFont::DemiBold); + COMPARE_WEIGHT_DISTANCE(kCTFontWeightMedium, QFont::Medium); + COMPARE_WEIGHT_DISTANCE(kCTFontWeightRegular, QFont::Normal); + COMPARE_WEIGHT_DISTANCE(kCTFontWeightLight, QFont::Light); + COMPARE_WEIGHT_DISTANCE(kCTFontWeightThin, QFont::ExtraLight); + COMPARE_WEIGHT_DISTANCE(kCTFontWeightUltraLight, QFont::Thin); + +#undef COMPARE_WEIGHT_DISTANCE + + return ret; } static void loadAdvancesForGlyphs(CTFontRef ctfont, -- cgit v1.2.3 From d7438593a890749b72ec042b7817c59d6d99815c Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 18 Aug 2017 16:45:22 +0200 Subject: Remove QMAKE_LIBS_CORE variable Define the lib dependencies for corelib in corelib.pro, where they belong. Change-Id: I973d3b0c571782d869b27dea243e899db4dddc43 Reviewed-by: Oswald Buddenhagen --- src/platformsupport/fontdatabases/winrt/winrt.pri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fontdatabases/winrt/winrt.pri b/src/platformsupport/fontdatabases/winrt/winrt.pri index 4875338182..291ada220f 100644 --- a/src/platformsupport/fontdatabases/winrt/winrt.pri +++ b/src/platformsupport/fontdatabases/winrt/winrt.pri @@ -8,4 +8,4 @@ HEADERS += \ DEFINES += __WRL_NO_DEFAULT_LIB__ -LIBS += $$QMAKE_LIBS_CORE -ldwrite +LIBS += -lws2_32 -ldwrite -- cgit v1.2.3 From 63002b2f378e8b663276279fb304afa752171bee Mon Sep 17 00:00:00 2001 From: Dongmei Wang Date: Fri, 18 Aug 2017 11:28:33 -0700 Subject: QFbVtHandler: Remove unused sys/signalfd.h include Change-Id: Ia9fa3c4de0a1dbdd1b36730c82f5180c2128cbcf Reviewed-by: Oswald Buddenhagen Reviewed-by: Laszlo Agocs --- src/platformsupport/fbconvenience/qfbvthandler.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fbconvenience/qfbvthandler.cpp b/src/platformsupport/fbconvenience/qfbvthandler.cpp index 102bc91647..7bb9e28ac2 100644 --- a/src/platformsupport/fbconvenience/qfbvthandler.cpp +++ b/src/platformsupport/fbconvenience/qfbvthandler.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include #include -- cgit v1.2.3