summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/fontdatabases
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@digia.com>2014-10-21 17:11:58 +0200
committerPierre Rossi <pierre.rossi@gmail.com>2014-10-24 23:19:11 +0200
commit0c482869fb342d7a7ed44d8101e84aec9f981549 (patch)
tree973a605eb7959425a68a8b15f23f42129141b3d2 /src/platformsupport/fontdatabases
parent0f3323ce0194b271024d423bec861d51dc55063f (diff)
Add support for more font weights internally
We should have more font weights in QFont::Weight to allow for finer grained control. For the time being, we can simply use intermediate weights to better support the different font weights falling in between the ones defined in QFont::Weight. Also amend the documentation to clarify the fact that QFont supports and can return weights falling outside the predefined values, which is already the case (e.g. when using fontconfig). Done-with: Gabriel de Dietrich Change-Id: I693cdd48b8b77e7ed550cdf991227bcb819d8e7b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/platformsupport/fontdatabases')
-rw-r--r--src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp14
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm6
2 files changed, 19 insertions, 1 deletions
diff --git a/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp b/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp
index fb9ec0f2e4..43903acfe1 100644
--- a/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp
+++ b/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp
@@ -277,10 +277,16 @@ QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByt
if (os2->usWeightClass == 0)
;
+ else if (os2->usWeightClass < 150)
+ weight = qt_thinFontWeight;
+ else if (os2->usWeightClass < 250)
+ weight = qt_extralightFontWeight;
else if (os2->usWeightClass < 350)
weight = QFont::Light;
else if (os2->usWeightClass < 450)
weight = QFont::Normal;
+ else if (os2->usWeightClass < 550)
+ weight = qt_mediumFontWeight;
else if (os2->usWeightClass < 650)
weight = QFont::DemiBold;
else if (os2->usWeightClass < 750)
@@ -290,10 +296,16 @@ QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByt
if (os2->panose[2] >= 2) {
int w = os2->panose[2];
- if (w <= 3)
+ if (w <= 1)
+ weight = qt_thinFontWeight;
+ else if (w <= 2)
+ weight = qt_extralightFontWeight;
+ else if (w <= 3)
weight = QFont::Light;
else if (w <= 5)
weight = QFont::Normal;
+ else if (w <= 6)
+ weight = qt_mediumFontWeight;
else if (w <= 7)
weight = QFont::DemiBold;
else if (w <= 8)
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
index fc289579ea..9f2ff10a21 100644
--- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
+++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
@@ -294,10 +294,16 @@ static void getFontDescription(CTFontDescriptorRef font, FontDescription *fd)
fd->weight = QFont::Bold;
else if (normalizedWeight >= 0.3)
fd->weight = QFont::DemiBold;
+ else if (normalizedWeight >= 0.2)
+ fd->weight = qt_mediumFontWeight;
else if (normalizedWeight == 0.0)
fd->weight = QFont::Normal;
else if (normalizedWeight <= -0.4)
fd->weight = QFont::Light;
+ else if (normalizedWeight <= -0.6)
+ fd->weight = qt_extralightFontWeight;
+ else if (normalizedWeight <= -0.8)
+ fd->weight = qt_thinFontWeight;
}
}
if (CFNumberRef italic = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontSlantTrait)) {