Some metrics cleanup
authorromashin
Sat, 19 Apr 2008 18:40:28 +0300
changeset 16832 599de3e69d9343dcbe428d1b3c7c4c9ab36f099c
parent 16831 bf3473d519da0d3db7994541232640a4438e5a15
child 16833 9cb864376c9bee8048111d805a257d986feb898b
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
Some metrics cleanup
gfx/thebes/src/gfxQtFonts.cpp
--- a/gfx/thebes/src/gfxQtFonts.cpp
+++ b/gfx/thebes/src/gfxQtFonts.cpp
@@ -401,24 +401,26 @@ gfxQtFont::gfxQtFont(const nsAString &aN
     case FONT_STYLE_OBLIQUE:
         style = QFont::StyleOblique;
         break;
     case FONT_STYLE_NORMAL:
     default:
         style = QFont::StyleNormal;
     }
 
+//    PRInt8 weight, offset;
+//    GetStyle()->ComputeWeightAndOffset(&weight, &offset);
     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;
+        weight = QFont::DemiBold;
     case NS_STYLE_FONT_WEIGHT_LIGHTER:
         weight = QFont::Light;
     default:
         weight = QFont::Normal;
     }
     mQFont = new QFont();
     mQFont->setFamily(QString(NS_ConvertUTF16toUTF8(mName).get()));
     mQFont->setWeight(weight);
@@ -444,50 +446,41 @@ const gfxFont::Metrics&
 gfxQtFont::GetMetrics()
 {
     if (mHasMetrics)
         return mMetrics;
 
 
     mMetrics.emHeight = GetStyle()->size;
 
-    FT_UInt gid; // glyph ID
     QFontMetrics fontMetrics( *mQFont );
     FT_Face face = mQFont->freetypeFace();
 
     if (!face) {
         // Abort here already, otherwise we crash in the following
         // this can happen if the font-size requested is zero.
         // The metrics will be incomplete, but then we don't care.
         return mMetrics;
     }
 
-    double emUnit = 1.0 * face->units_per_EM;
-    double yScale = face->size->metrics.y_ppem / emUnit;
-
-    // properties of space
-    gid = FT_Get_Char_Index(face, ' ');
-    // Load glyph into glyph slot. Use load_default here to get results in
-    // 26.6 fractional pixel format which is what is used for all other
-    // characters in gfxOS2FontGroup::CreateGlyphRunsFT.
-    FT_Load_Glyph(face, gid, FT_LOAD_DEFAULT);
     // face->glyph->metrics.width doesn't work for spaces, use advance.x instead
     mMetrics.spaceWidth = fontMetrics.width( QChar(' ') );
     // save the space glyph
-    mSpaceGlyph = gid;
+    mSpaceGlyph = GetSpaceGlyph();
 
     mMetrics.xHeight = fontMetrics.xHeight();
     mMetrics.aveCharWidth = fontMetrics.averageCharWidth();
 
     // compute an adjusted size if we need to
     if (mAdjustedSize == 0 && GetStyle()->sizeAdjust != 0) {
         gfxFloat aspect = mMetrics.xHeight / GetStyle()->size;
         mAdjustedSize = GetStyle()->GetAdjustedSize(aspect);
         mMetrics.emHeight = mAdjustedSize;
-    }
+    } else 
+        mMetrics.emHeight = fontMetrics.height();
 
     if (face) {
         mMetrics.maxAdvance = face->size->metrics.max_advance / 64.0; // 26.6
         float val;
         TT_OS2 *os2 = (TT_OS2 *) FT_Get_Sfnt_Table(face, ft_sfnt_os2);
         if (os2 && os2->ySuperscriptYOffset) {
             val = CONVERT_DESIGN_UNITS_TO_PIXELS(os2->ySuperscriptYOffset,
                                                  face->size->metrics.y_scale);
@@ -500,36 +493,36 @@ gfxQtFont::GetMetrics()
             val = CONVERT_DESIGN_UNITS_TO_PIXELS(os2->ySubscriptYOffset,
                                                  face->size->metrics.y_scale);
             // some fonts have the incorrect sign..
             val = (val < 0) ? -val : val;
             mMetrics.subscriptOffset = PR_MAX(1, val);
         } else {
             mMetrics.subscriptOffset = mMetrics.xHeight;
         }
-    } else
-    {
+    } else {
         mMetrics.superscriptOffset = mMetrics.xHeight;
         mMetrics.subscriptOffset = mMetrics.xHeight;
     }
 
     mMetrics.strikeoutOffset = fontMetrics.strikeOutPos();
     mMetrics.strikeoutSize = fontMetrics.lineWidth();
     mMetrics.aveCharWidth = fontMetrics.averageCharWidth();
 
     // seems that underlineOffset really has to be negative
     mMetrics.underlineOffset = -fontMetrics.underlinePos();
     mMetrics.underlineSize = fontMetrics.lineWidth();
 
     // descents are negative in FT but Thebes wants them positive
-    mMetrics.emAscent        = face->ascender * yScale;
-    mMetrics.emDescent       = -face->descender * yScale;
-    mMetrics.maxHeight       = face->height * yScale;
     mMetrics.maxAscent       = fontMetrics.ascent();
-    mMetrics.maxDescent = fontMetrics.descent();
+    mMetrics.maxDescent      = fontMetrics.descent();
+    mMetrics.emAscent        = mMetrics.maxAscent;
+    mMetrics.emDescent       = mMetrics.maxDescent;
+    mMetrics.maxHeight       = mMetrics.maxAscent + mMetrics.maxDescent;
+
     mMetrics.maxAdvance = fontMetrics.maxWidth();
     // leading are not available directly (only for WinFNTs)
     double lineHeight = mMetrics.maxAscent + mMetrics.maxDescent;
     if (lineHeight > mMetrics.emHeight) {
         mMetrics.internalLeading = lineHeight - mMetrics.emHeight;
     } else {
         mMetrics.internalLeading = 0;
     }
@@ -578,16 +571,17 @@ PRUint32 gfxQtFont::GetSpaceGlyph ()
     NS_ASSERTION (GetStyle ()->size != 0,
     "forgot to short-circuit a text run with zero-sized font?");
 
     if(!mHasSpaceGlyph)
     {
         FT_UInt gid = 0; // glyph ID
         FT_Face face = mQFont->freetypeFace();
         gid = FT_Get_Char_Index(face, ' ');
+        FT_Load_Glyph(face, gid, FT_LOAD_DEFAULT);
         mSpaceGlyph = gid;
         mHasSpaceGlyph = PR_TRUE;
     }
     return mSpaceGlyph;
 }
 
 static const PRInt8 nFcWeight = 2; // 10; // length of weight list
 static const int fcWeight[] = {
@@ -711,17 +705,16 @@ gfxQtFont::CreateScaledFont(cairo_t *aCR
     cairo_font_options_destroy(fontOptions);
 
     return scaledFont;
 }
 
 PRBool
 gfxQtFont::SetupCairoFont(gfxContext *aContext)
 {
-
     cairo_t *cr = aContext->GetCairo();
     cairo_matrix_t currentCTM;
     cairo_get_matrix(cr, &currentCTM);
 
     if (mCairoFont) {
         // Need to validate that its CTM is OK
         cairo_matrix_t fontCTM;
         cairo_scaled_font_get_ctm(mCairoFont, &fontCTM);