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>
This commit is contained in:
Gabriel de Dietrich 2014-07-02 17:14:26 +02:00
parent 0afc80c922
commit e7839d9717

View File

@ -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));