Index: /trunk/src/gui/text/qfontdatabase.cpp
===================================================================
--- /trunk/src/gui/text/qfontdatabase.cpp	(revision 222)
+++ /trunk/src/gui/text/qfontdatabase.cpp	(revision 223)
@@ -446,5 +446,5 @@
 // ### copied to tools/makeqpf/qpf2.cpp
 
-#if (defined(Q_WS_QWS) && !defined(QT_NO_FREETYPE)) || defined(Q_WS_WIN) || defined(Q_WS_MAC)
+#if ((defined(Q_WS_QWS) || defined(Q_WS_PM)) && !defined(QT_NO_FREETYPE)) || defined(Q_WS_WIN) || defined(Q_WS_MAC)
 // see the Unicode subset bitfields in the MSDN docs
 static int requiredUnicodeBits[QFontDatabase::WritingSystemsCount][2] = {
Index: /trunk/src/gui/text/qfontdatabase_pm.cpp
===================================================================
--- /trunk/src/gui/text/qfontdatabase_pm.cpp	(revision 222)
+++ /trunk/src/gui/text/qfontdatabase_pm.cpp	(revision 223)
@@ -133,8 +133,14 @@
             QString familyName = QString::fromLatin1(face->family_name);
 
+            // familyName may contain extra spaces (at least this is true for
+            // TNR.PFB that is reported as "Times New Roman ". Trim them.
+            familyName = familyName.trimmed();
+
             QtFontStyle::Key styleKey;
 
             styleKey.style = face->style_flags & FT_STYLE_FLAG_ITALIC ?
                 QFont::StyleItalic : QFont::StyleNormal;
+
+            QList<QFontDatabase::WritingSystem> systems;
 
             TT_OS2 *os2_table = 0;
@@ -167,4 +173,13 @@
                     default: styleKey.stretch = QFont::Unstretched; break;
                 }
+
+                quint32 unicodeRange[4] = {
+                    os2_table->ulUnicodeRange1, os2_table->ulUnicodeRange2,
+                    os2_table->ulUnicodeRange3, os2_table->ulUnicodeRange4
+                };
+                quint32 codePageRange[2] = {
+                    os2_table->ulCodePageRange1, os2_table->ulCodePageRange2
+                };
+                systems = determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange);
             } else {
                 // we've only got simple weight information and no stretch
@@ -180,6 +195,17 @@
             family->fixedPitch = face->face_flags & FT_FACE_FLAG_FIXED_WIDTH;
 
-            // writing systems aren't used ATM, let's support just Any
-            family->writingSystems[QFontDatabase::Any] = QtFontFamily::Supported;
+            if (systems.isEmpty()) {
+                // it was hard or impossible to determine the actual writing system
+                // of the font (as in case of OS/2 bitmap and PFB fonts for which it is
+                // usually simply reported that they support standard/system codepages).
+                // Pretend that we support all writing systems to not miss the one.
+                // @todo find a way to detect it properly to make sure these fonts
+                // are not matched for scripts they don't support
+                for (int ws = 0; ws < QFontDatabase::WritingSystemsCount; ++ws)
+                    family->writingSystems[ws] = QtFontFamily::Supported;
+            } else {
+                for (int i = 0; i < systems.count(); ++i)
+                    family->writingSystems[systems.at(i)] = QtFontFamily::Supported;
+            }
 
             QtFontFoundry *foundry = family->foundry(foundryName, true);
@@ -235,8 +261,10 @@
         populateDatabase(family->name);
 #if 1
-        qDebug("        scripts supported:");
-        for (int i = 0; i < QUnicodeTables::ScriptCount; i++)
-            if(family->writingSystems[i] & QtFontFamily::Supported)
-                qDebug("            %d", i);
+        qDebug("        writing systems supported:");
+        QStringList systems;
+        for (int ws = 0; ws < QFontDatabase::WritingSystemsCount; ++ws)
+            if (family->writingSystems[ws] & QtFontFamily::Supported)
+                systems << QFontDatabase::writingSystemName((QFontDatabase::WritingSystem)ws);
+        qDebug() << "            " << systems;
         for (int fd = 0; fd < family->count; fd++) {
             QtFontFoundry *foundry = family->foundries[fd];
