Bug 1316262 - Guard against failure applying font-size-adjust to tiny font sizes with GDI backend, where metrics round to zero so we cannot compute aspect ratio. r=mchang
authorJonathan Kew <jkew@mozilla.com>
Mon, 14 Nov 2016 13:42:06 +0000
changeset 322505 c6e0621b81552eb3c20275b3ae5c25e2f15db1eb
parent 322504 91db8a985f7fadecde63e3a4e20a4529fcdcc456
child 322506 f35b3bbdd3c57a5b4b6d4384b22ac774ac423886
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersmchang
bugs1316262
milestone52.0a1
Bug 1316262 - Guard against failure applying font-size-adjust to tiny font sizes with GDI backend, where metrics round to zero so we cannot compute aspect ratio. r=mchang
gfx/thebes/gfxGDIFont.cpp
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -186,20 +186,23 @@ gfxGDIFont::Initialize()
             // to implement font-size-adjust, we first create the "unadjusted" font
             FillLogFont(logFont, mAdjustedSize,
                         wantFakeItalic && !useCairoFakeItalic);
             mFont = ::CreateFontIndirectW(&logFont);
 
             // initialize its metrics so we can calculate size adjustment
             Initialize();
 
+            // Unless the font was so small that GDI metrics rounded to zero,
             // calculate the properly adjusted size, and then proceed
             // to recreate mFont and recalculate metrics
-            gfxFloat aspect = mMetrics->xHeight / mMetrics->emHeight;
-            mAdjustedSize = mStyle.GetAdjustedSize(aspect);
+            if (mMetrics->xHeight > 0.0 && mMetrics->emHeight > 0.0) {
+                gfxFloat aspect = mMetrics->xHeight / mMetrics->emHeight;
+                mAdjustedSize = mStyle.GetAdjustedSize(aspect);
+            }
 
             // delete the temporary font and metrics
             ::DeleteObject(mFont);
             mFont = nullptr;
             delete mMetrics;
             mMetrics = nullptr;
         } else if (mStyle.sizeAdjust == 0.0) {
             mAdjustedSize = 0.0;