Bug 964512 - Check for existence of character before trying to get its metrics in gfxGDIFont::Initialize. r=jdaggett, a=sledru
authorJonathan Kew <jkew@mozilla.com>
Mon, 01 Jun 2015 09:13:29 +0100
changeset 275356 14ba9a819a10fe19fc47b48c9898ecad369bbb81
parent 275355 a212800c773ff220b3d2d9d8f27f4c158c907264
child 275357 18db52aa1286b505af4b28480aad0925d1924381
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett, sledru
bugs964512
milestone40.0
Bug 964512 - Check for existence of character before trying to get its metrics in gfxGDIFont::Initialize. r=jdaggett, a=sledru
gfx/thebes/gfxGDIFont.cpp
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -299,36 +299,37 @@ gfxGDIFont::Initialize()
         mMetrics->maxAdvance = metrics.tmMaxCharWidth;
         mMetrics->aveCharWidth = std::max<gfxFloat>(1, metrics.tmAveCharWidth);
         // The font is monospace when TMPF_FIXED_PITCH is *not* set!
         // See http://msdn2.microsoft.com/en-us/library/ms534202(VS.85).aspx
         if (!(metrics.tmPitchAndFamily & TMPF_FIXED_PITCH)) {
             mMetrics->maxAdvance = mMetrics->aveCharWidth;
         }
 
-        // Cache the width of a single space.
+        WORD glyph;
         SIZE size;
-        GetTextExtentPoint32W(dc.GetDC(), L" ", 1, &size);
-        mMetrics->spaceWidth = ROUND(size.cx);
-
-        // Cache the width of digit zero.
-        // XXX MSDN (http://msdn.microsoft.com/en-us/library/ms534223.aspx)
-        // does not say what the failure modes for GetTextExtentPoint32 are -
-        // is it safe to assume it will fail iff the font has no '0'?
-        if (GetTextExtentPoint32W(dc.GetDC(), L"0", 1, &size)) {
-            mMetrics->zeroOrAveCharWidth = ROUND(size.cx);
-        } else {
-            mMetrics->zeroOrAveCharWidth = mMetrics->aveCharWidth;
-        }
-
-        WORD glyph;
         DWORD ret = GetGlyphIndicesW(dc.GetDC(), L" ", 1, &glyph,
                                      GGI_MARK_NONEXISTING_GLYPHS);
         if (ret != GDI_ERROR && glyph != 0xFFFF) {
             mSpaceGlyph = glyph;
+            // Cache the width of a single space.
+            GetTextExtentPoint32W(dc.GetDC(), L" ", 1, &size);
+            mMetrics->spaceWidth = ROUND(size.cx);
+        } else {
+            mMetrics->spaceWidth = mMetrics->aveCharWidth;
+        }
+
+        // Cache the width of digit zero, if available.
+        ret = GetGlyphIndicesW(dc.GetDC(), L"0", 1, &glyph,
+                               GGI_MARK_NONEXISTING_GLYPHS);
+        if (ret != GDI_ERROR && glyph != 0xFFFF) {
+            GetTextExtentPoint32W(dc.GetDC(), L"0", 1, &size);
+            mMetrics->zeroOrAveCharWidth = ROUND(size.cx);
+        } else {
+            mMetrics->zeroOrAveCharWidth = mMetrics->aveCharWidth;
         }
 
         SanitizeMetrics(mMetrics, GetFontEntry()->mIsBadUnderlineFont);
     }
 
     if (IsSyntheticBold()) {
         mMetrics->aveCharWidth += GetSyntheticBoldOffset();
         mMetrics->maxAdvance += GetSyntheticBoldOffset();