diff options
author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2014-07-02 17:14:26 +0200 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2014-07-29 17:33:19 +0200 |
commit | e7839d9717820a8f0049316c626d28fbcf252fa7 (patch) | |
tree | 9480032068358098e895179e27b4a2d21db563d8 /src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm | |
parent | 0afc80c9225ca9630f627fe1aea3d4fd7f958082 (diff) |
QCoreTextFontDatabase: Fix font weight value when populating a family
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ø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm')
-rw-r--r-- | src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm | 16 |
1 files 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)); |