Add more proper initialization of QFont, weight, styles...
authorromashin
Sat, 19 Apr 2008 18:40:20 +0300
changeset 16830 184e174f57aa1a28a11ea9da256bc81605eeae15
parent 16829 19257524576a4dfa1512ce715b954a3ea2a63d82
child 16831 bf3473d519da0d3db7994541232640a4438e5a15
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
Add more proper initialization of QFont, weight, styles...
gfx/thebes/src/gfxQtFonts.cpp
--- a/gfx/thebes/src/gfxQtFonts.cpp
+++ b/gfx/thebes/src/gfxQtFonts.cpp
@@ -40,16 +40,17 @@
 #include "qdebug.h"
 #include "qrect.h"
 #include <locale.h>
 #include <QFont>
 #include <QFontMetrics>
 #include <QFontMetricsF>
 #include "cairo-ft.h"
 #include <freetype/tttables.h>
+#include "nsStyleConsts.h"
 
 /**
  * gfxQtFontGroup
  */
 
 static int
 FFRECountHyphens (const nsAString &aFFREName)
 {
@@ -377,35 +378,56 @@ void gfxQtFontGroup::CreateGlyphRunsFT(g
     }
 }
 
 /**
  * gfxQtFont
  */
 gfxQtFont::gfxQtFont(const nsAString &aName,
                      const gfxFontStyle *aFontStyle)
-    : gfxFont(aName, aFontStyle),
-      mQFont(nsnull),
-      mCairoFont(nsnull),
-      mHasSpaceGlyph(PR_FALSE),
-      mSpaceGlyph(0),
-      mHasMetrics(PR_FALSE), 
-      mAdjustedSize(0)
+        : gfxFont(aName, aFontStyle),
+        mQFont(nsnull),
+        mCairoFont(nsnull),
+        mHasSpaceGlyph(PR_FALSE),
+        mSpaceGlyph(0),
+        mHasMetrics(PR_FALSE),
+        mAdjustedSize(0)
 {
+    QFont::Style style = QFont::StyleNormal;
+    // add style to pattern
+    switch (GetStyle()->style) {
+    case FONT_STYLE_ITALIC:
+        style = QFont::StyleItalic;
+        break;
+    case FONT_STYLE_OBLIQUE:
+        style = QFont::StyleOblique;
+        break;
+    case FONT_STYLE_NORMAL:
+    default:
+        style = QFont::StyleNormal;
+    }
+
+    PRInt16 weight = QFont::Normal;
+    switch (GetStyle()->weight) {
+    case NS_STYLE_FONT_WEIGHT_NORMAL:
+        weight = QFont::Normal;
+    case NS_STYLE_FONT_WEIGHT_BOLD:
+        weight = QFont::Bold;
+    case NS_STYLE_FONT_WEIGHT_BOLDER:
+        weight = QFont::Black;
+    case NS_STYLE_FONT_WEIGHT_LIGHTER:
+        weight = QFont::Light;
+    default:
+        weight = QFont::Normal;
+    }
     mQFont = new QFont();
-    mQFont->setFamily(QString( NS_ConvertUTF16toUTF8(mName).get() ) );
-    mQFont->setPixelSize(GetStyle()->size);
-    int weight = GetStyle()->weight/10;
-    if( weight > 99 )
-    {
-        // Max Weight for QFont is 99
-        weight = 99;
-    }
+    mQFont->setFamily(QString(NS_ConvertUTF16toUTF8(mName).get()));
     mQFont->setWeight(weight);
-    mQFont->setItalic(bool( GetStyle()->style == FONT_STYLE_ITALIC ));
+    mQFont->setStyle(style);
+    mQFont->setPixelSize (mAdjustedSize ? mAdjustedSize : GetStyle()->size);
 }
 
 gfxQtFont::~gfxQtFont()
 {
     delete mQFont;
     cairo_scaled_font_destroy(mCairoFont);
 }