From e7839d9717820a8f0049316c626d28fbcf252fa7 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 2 Jul 2014 17:14:26 +0200 Subject: [PATCH] QCoreTextFontDatabase: Fix font weight value when populating a family MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kCTFontWeightTrait returns a normalized value between -1.0 (lightest) and 1.0 (heaviest), 0.0 being the regular font weight. The threshold values used in this change have been estimated from the weight values of fonts from the Helvetica Neue and Myriad Pro font families. Change-Id: I49de8e8bd5894107de4842aeda7ace2e83f95be3 Reviewed-by: Tor Arne Vestbø --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 9248785696..4aa4253773 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -245,9 +245,19 @@ void QCoreTextFontDatabase::populateFromDescriptor(CTFontDescriptorRef font) if (styles) { if (CFNumberRef weightValue = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontWeightTrait)) { Q_ASSERT(CFNumberIsFloatType(weightValue)); - double d; - if (CFNumberGetValue(weightValue, kCFNumberDoubleType, &d)) - weight = (d > 0.0) ? QFont::Bold : QFont::Normal; + double normalizedWeight; + if (CFNumberGetValue(weightValue, kCFNumberDoubleType, &normalizedWeight)) { + if (normalizedWeight >= 0.62) + weight = QFont::Black; + else if (normalizedWeight >= 0.4) + weight = QFont::Bold; + else if (normalizedWeight >= 0.3) + weight = QFont::DemiBold; + else if (normalizedWeight == 0.0) + weight = QFont::Normal; + else if (normalizedWeight <= -0.4) + weight = QFont::Light; + } } if (CFNumberRef italic = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontSlantTrait)) { Q_ASSERT(CFNumberIsFloatType(italic));