Optimized font retrieval
authorpekka.vanhoja
Sat, 19 Apr 2008 18:40:42 +0300
changeset 16835 f64b501d7d781d8a2a8c4d81e5e2b731ecdc2fdd
parent 16834 da845b1dacca369f7b813a9a40ba2c354252c537
child 16836 26a480c8630e66b6627388ba1d5fab1abc5fbab7
push id1298
push userpavlov@mozilla.com
push dateSun, 17 Aug 2008 05:03:09 +0000
treeherderautoland@4a506fa751d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0a1pre
Optimized font retrieval
gfx/src/thebes/nsSystemFontsQt.cpp
gfx/src/thebes/nsSystemFontsQt.h
--- a/gfx/src/thebes/nsSystemFontsQt.cpp
+++ b/gfx/src/thebes/nsSystemFontsQt.cpp
@@ -31,80 +31,58 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-// for strtod()
-#include <stdlib.h>
-
 #include "nsIDeviceContext.h"
 #include "nsIRenderingContext.h"
-#include "prlink.h"
 
-#include <fontconfig/fontconfig.h>
 #include "nsSystemFontsQt.h"
 #include "gfxPlatformQt.h"
-#include <QLabel>
-#include <QLineEdit>
-#include <QMenu>
-#include <QAction>
-#include <QPushButton>
+#include <QApplication>
+#include <QFont>
 
 nsSystemFontsQt::nsSystemFontsQt()
   : mDefaultFontName(NS_LITERAL_STRING("sans-serif"))
   , mButtonFontName(NS_LITERAL_STRING("sans-serif"))
   , mFieldFontName(NS_LITERAL_STRING("sans-serif"))
   , mMenuFontName(NS_LITERAL_STRING("sans-serif"))
 {
    // What about using QFontInfo? is it faster or what?
-   QLabel *label = new QLabel();
-   if (label) {
-       GetSystemFontInfo(label->font(), &mDefaultFontName, &mDefaultFontStyle);
-       delete label;
-   }
+   GetSystemFontInfo("Qlabel", &mDefaultFontName, &mDefaultFontStyle);
 
-   QLineEdit *entry = new QLineEdit();
-   if (entry) {
-      GetSystemFontInfo(entry->font(), &mFieldFontName, &mFieldFontStyle);
-      delete entry;
-   }
+   GetSystemFontInfo("QlineEdit", &mFieldFontName, &mFieldFontStyle);
 
-   QMenu *menu = new QMenu();
-   QAction *action = new QAction(menu);
-   if (action) {
-      GetSystemFontInfo(action->font(), &mMenuFontName, &mMenuFontStyle);
-      delete action;
-   }
-
-   QPushButton *button = new QPushButton();
-   if (button) {
-      GetSystemFontInfo(button->font(), &mButtonFontName, &mButtonFontStyle);
-      delete button;
-   }
+   GetSystemFontInfo("QAction", &mMenuFontName, &mMenuFontStyle);
+  
+   GetSystemFontInfo("QPushButton", &mButtonFontName, &mButtonFontStyle);
 }
 
 nsSystemFontsQt::~nsSystemFontsQt()
 {
+    // No implementation needed
 }
 
 nsresult
-nsSystemFontsQt::GetSystemFontInfo(const QFont &aFont, nsString *aFontName,
-                                     gfxFontStyle *aFontStyle) const
+nsSystemFontsQt::GetSystemFontInfo(const char *aClassName, nsString *aFontName,
+                                   gfxFontStyle *aFontStyle) const
 {
-    aFontStyle->style       = FONT_STYLE_NORMAL;
-    aFontStyle->systemFont  = PR_TRUE;
+    QFont qFont = QApplication::font(aClassName);
+
+    aFontStyle->style = FONT_STYLE_NORMAL;
+    aFontStyle->systemFont = PR_TRUE;
     NS_NAMED_LITERAL_STRING(quote, "\"");
-    nsString family((PRUnichar*)aFont.family().data());
+    nsString family((PRUnichar*)qFont.family().data());
     *aFontName = quote + family + quote;
-    aFontStyle->weight = aFont.weight();
-    aFontStyle->size = aFont.pointSizeF() * float(gfxPlatformQt::DPI()) / 72.0f;
+    aFontStyle->weight = qFont.weight();
+    aFontStyle->size = qFont.pointSizeF() * float(gfxPlatformQt::DPI()) / 72.0f;
     return NS_OK;
 }
 
 
 nsresult
 nsSystemFontsQt::GetSystemFont(nsSystemFontID anID, nsString *aFontName,
                                  gfxFontStyle *aFontStyle) const
 {
--- a/gfx/src/thebes/nsSystemFontsQt.h
+++ b/gfx/src/thebes/nsSystemFontsQt.h
@@ -49,17 +49,17 @@ public:
     nsSystemFontsQt();
     ~nsSystemFontsQt();
 
     nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
                            gfxFontStyle *aFontStyle) const;
 
 private:
 
-    nsresult GetSystemFontInfo(const QFont &aFont, nsString *aFontName,
+    nsresult GetSystemFontInfo(const char *aClassName, nsString *aFontName,
                                gfxFontStyle *aFontStyle) const;
 
     /*
      * The following system font constants exist:
      *
      * css2: http://www.w3.org/TR/REC-CSS2/fonts.html#x27
      * eSystemFont_Caption, eSystemFont_Icon, eSystemFont_Menu,
      * eSystemFont_MessageBox, eSystemFont_SmallCaption,