Fix weight parsing in QBasicUnixFontDatabase
authorJiang Jiang <jiang.jiang@nokia.com>
Fri, 5 Aug 2011 08:59:34 +0000 (10:59 +0200)
committerJiang Jiang <jiang.jiang@nokia.com>
Wed, 24 Aug 2011 07:45:35 +0000 (09:45 +0200)
First check the usWeightClass in OS/2 font table, then check
the weight byte in panose structure because Nokia Pure Text
fonts only have that set correctly.

Change-Id: Idce2626c8df17ce74ba78b317846cb42c3f1fe84
Reviewed-by: Jørgen Lind
Reviewed-on: http://codereview.qt.nokia.com/2682
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/3460

src/platformsupport/fontdatabases/basicunix/qbasicunixfontdatabase.cpp

index 1b0966d..af5234d 100644 (file)
@@ -308,6 +308,33 @@ QStringList QBasicUnixFontDatabase::addTTFile(const QByteArray &fontData, const
                     };
 
             writingSystems = determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange);
+
+            if (os2->usWeightClass == 0)
+                ;
+            else if (os2->usWeightClass < 350)
+                weight = QFont::Light;
+            else if (os2->usWeightClass < 450)
+                weight = QFont::Normal;
+            else if (os2->usWeightClass < 650)
+                weight = QFont::DemiBold;
+            else if (os2->usWeightClass < 750)
+                weight = QFont::Bold;
+            else if (os2->usWeightClass < 1000)
+                weight = QFont::Black;
+
+            if (os2->panose[2] >= 2) {
+                int w = os2->panose[2];
+                if (w <= 3)
+                    weight = QFont::Light;
+                else if (w <= 5)
+                    weight = QFont::Normal;
+                else if (w <= 7)
+                    weight = QFont::DemiBold;
+                else if (w <= 8)
+                    weight = QFont::Bold;
+                else if (w <= 10)
+                    weight = QFont::Black;
+            }
         }
 
         QString family = QString::fromAscii(face->family_name);