src/gui/text/qfont_s60.cpp
changeset 37 758a864f9613
parent 30 5dc02b23752f
--- a/src/gui/text/qfont_s60.cpp	Fri Sep 17 08:34:18 2010 +0300
+++ b/src/gui/text/qfont_s60.cpp	Mon Oct 04 01:19:32 2010 +0300
@@ -40,15 +40,26 @@
 ****************************************************************************/
 
 #include "qfont.h"
+#include "qfont_p.h"
 #include <private/qt_s60_p.h>
 #include <private/qpixmap_s60_p.h>
 #include "qmutex.h"
 
 QT_BEGIN_NAMESPACE
 
-#if 1
 #ifdef QT_NO_FREETYPE
 Q_GLOBAL_STATIC(QMutex, lastResortFamilyMutex);
+Q_GLOBAL_STATIC_WITH_INITIALIZER(QStringList, fontFamiliesOnFontServer, {
+    QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
+    const int numTypeFaces = S60->screenDevice()->NumTypefaces();
+    for (int i = 0; i < numTypeFaces; i++) {
+        TTypefaceSupport typefaceSupport;
+        S60->screenDevice()->TypefaceSupport(typefaceSupport, i);
+        const QString familyName((const QChar *)typefaceSupport.iTypeface.iName.Ptr(), typefaceSupport.iTypeface.iName.Length());
+        x->append(familyName);
+    }
+    lock.relock();
+});
 #endif // QT_NO_FREETYPE
 
 QString QFont::lastResortFamily() const
@@ -70,7 +81,7 @@
         lock.relock();
     }
     return family;
-#else
+#else // QT_NO_FREETYPE
     // For the FreeType case we just hard code the face name, since otherwise on
     // East Asian systems we may get a name for a stroke based (non-ttf) font.
 
@@ -82,15 +93,24 @@
     return QLatin1String(isJapaneseOrChineseSystem?"Heisei Kaku Gothic S60":"Series 60 Sans");
 #endif // QT_NO_FREETYPE
 }
-#else // 0
-QString QFont::lastResortFamily() const
-{
-    return QLatin1String("Series 60 Sans");
-}
-#endif // 0
 
 QString QFont::defaultFamily() const
 {
+#ifdef QT_NO_FREETYPE
+    switch(d->request.styleHint) {
+        case QFont::SansSerif: {
+            static const char* const preferredSansSerif[] = {"Nokia Sans S60", "Series 60 Sans"};
+            for (int i = 0; i < sizeof preferredSansSerif / sizeof preferredSansSerif[0]; ++i) {
+                const QString sansSerif = QLatin1String(preferredSansSerif[i]);
+                if (fontFamiliesOnFontServer()->contains(sansSerif))
+                    return sansSerif;
+            }
+        }
+        // No break. Intentional fall through.
+        default:
+            return lastResortFamily();
+    }
+#endif // QT_NO_FREETYPE
     return lastResortFamily();
 }