bug 549190 - round dwrite font vertical metrics to improve rendering/spacing consistency. r=bas
authorJonathan Kew <jfkthame@gmail.com>
Tue, 06 Apr 2010 21:19:41 +0100
changeset 40505 4365eabf7fb0737b3055ae5f5e9da8a0cd0032c2
parent 40504 1cac391aec8cb87c8603052cd32e8594d733e8cd
child 40506 64ebf70ed4a201c96db2e65b6fda6ccd31b6e91d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbas
bugs549190
milestone1.9.3a4pre
bug 549190 - round dwrite font vertical metrics to improve rendering/spacing consistency. r=bas
gfx/thebes/src/gfxDWriteFonts.cpp
--- a/gfx/thebes/src/gfxDWriteFonts.cpp
+++ b/gfx/thebes/src/gfxDWriteFonts.cpp
@@ -119,36 +119,40 @@ gfxDWriteFont::ComputeMetrics()
         mAdjustedSize = mStyle.GetAdjustedSize(aspect);
     } else {
         mAdjustedSize = mStyle.size;
     }
 
     mMetrics.xHeight =
         ((gfxFloat)fontMetrics.xHeight /
                    fontMetrics.designUnitsPerEm) * mAdjustedSize;
-    mMetrics.emAscent = 
-        ((gfxFloat)fontMetrics.ascent /
-                   fontMetrics.designUnitsPerEm) * mAdjustedSize;
-    mMetrics.emDescent = 
-        ((gfxFloat)fontMetrics.descent /
-                   fontMetrics.designUnitsPerEm) * mAdjustedSize;
+
+    mMetrics.maxAscent = 
+        ceil(((gfxFloat)fontMetrics.ascent /
+                   fontMetrics.designUnitsPerEm) * mAdjustedSize);
+    mMetrics.maxDescent = 
+        ceil(((gfxFloat)fontMetrics.descent /
+                   fontMetrics.designUnitsPerEm) * mAdjustedSize);
+    mMetrics.maxHeight = mMetrics.maxAscent + mMetrics.maxDescent;
+
     mMetrics.emHeight = mAdjustedSize;
-    mMetrics.maxAscent = mMetrics.emAscent;
-    mMetrics.maxDescent = mMetrics.emDescent;
-    mMetrics.maxHeight = mMetrics.emHeight;
+    mMetrics.emAscent = mMetrics.emHeight *
+        mMetrics.maxAscent / mMetrics.maxHeight;
+    mMetrics.emDescent = mMetrics.emHeight - mMetrics.emAscent;
+
     mMetrics.maxAdvance = mAdjustedSize;
+
     mMetrics.internalLeading = 
-        ((gfxFloat)(fontMetrics.ascent + 
+        ceil(((gfxFloat)(fontMetrics.ascent + 
                     fontMetrics.descent - 
                     fontMetrics.designUnitsPerEm) / 
-                    fontMetrics.designUnitsPerEm) * mAdjustedSize;
-    
+                    fontMetrics.designUnitsPerEm) * mAdjustedSize);
     mMetrics.externalLeading = 
-        ((gfxFloat)fontMetrics.lineGap /
-                   fontMetrics.designUnitsPerEm) * mAdjustedSize;
+        ceil(((gfxFloat)fontMetrics.lineGap /
+                   fontMetrics.designUnitsPerEm) * mAdjustedSize);
 
     UINT16 glyph = (PRUint16)GetSpaceGlyph();
     DWRITE_GLYPH_METRICS metrics;
     mFontFace->GetDesignGlyphMetrics(&glyph, 1, &metrics);
     mMetrics.spaceWidth = 
         ((gfxFloat)metrics.advanceWidth /
                    fontMetrics.designUnitsPerEm) * mAdjustedSize;
     UINT32 ucs = L'x';