Bug 1293210 - get cap height from platform APIs for non-sfnt fonts on Mac. draft
authorJeremy Chen <jeremychen@mozilla.com>
Thu, 18 Aug 2016 17:43:54 +0800
changeset 402509 6bbcafc1ae49f453cffd6182023791bc37f2b825
parent 402508 dd55125e365924d0796fc8e342a8b2e1a762494e
child 402510 31b7bdf2c96ab250aad70e3a3f5381372560f17c
push id26677
push userjichen@mozilla.com
push dateThu, 18 Aug 2016 09:44:38 +0000
bugs1293210
milestone51.0a1
Bug 1293210 - get cap height from platform APIs for non-sfnt fonts on Mac. MozReview-Commit-ID: IiHQQoIvQ3f
gfx/thebes/gfxMacFont.cpp
--- a/gfx/thebes/gfxMacFont.cpp
+++ b/gfx/thebes/gfxMacFont.cpp
@@ -251,16 +251,20 @@ gfxMacFont::InitMetrics()
     if (!mIsValid) {
         return;
     }
 
     if (mMetrics.xHeight == 0.0) {
         mMetrics.xHeight = ::CGFontGetXHeight(mCGFont) * cgConvFactor;
     }
 
+    if (mMetrics.capHeight == 0.0) {
+        mMetrics.capHeight = ::CGFontGetCapHeight(mCGFont) * cgConvFactor;
+    }
+
     if (mStyle.sizeAdjust > 0.0 && mStyle.size > 0.0 &&
         mMetrics.xHeight > 0.0) {
         // apply font-size-adjust, and recalculate metrics
         gfxFloat aspect = mMetrics.xHeight / mStyle.size;
         mAdjustedSize = mStyle.GetAdjustedSize(aspect);
         mFUnitsConvFactor = mAdjustedSize / upem;
         if (static_cast<MacOSFontEntry*>(mFontEntry.get())->IsCFF()) {
             cgConvFactor = mAdjustedSize / ::CGFontGetUnitsPerEm(mCGFont);
@@ -331,17 +335,17 @@ gfxMacFont::InitMetrics()
 
 #if 0
     fprintf (stderr, "Font: %p (%s) size: %f\n", this,
              NS_ConvertUTF16toUTF8(GetName()).get(), mStyle.size);
 //    fprintf (stderr, "    fbounds.origin.x %f y %f size.width %f height %f\n", fbounds.origin.x, fbounds.origin.y, fbounds.size.width, fbounds.size.height);
     fprintf (stderr, "    emHeight: %f emAscent: %f emDescent: %f\n", mMetrics.emHeight, mMetrics.emAscent, mMetrics.emDescent);
     fprintf (stderr, "    maxAscent: %f maxDescent: %f maxAdvance: %f\n", mMetrics.maxAscent, mMetrics.maxDescent, mMetrics.maxAdvance);
     fprintf (stderr, "    internalLeading: %f externalLeading: %f\n", mMetrics.internalLeading, mMetrics.externalLeading);
-    fprintf (stderr, "    spaceWidth: %f aveCharWidth: %f xHeight: %f\n", mMetrics.spaceWidth, mMetrics.aveCharWidth, mMetrics.xHeight);
+    fprintf (stderr, "    spaceWidth: %f aveCharWidth: %f xHeight: %f capHeight: %f\n", mMetrics.spaceWidth, mMetrics.aveCharWidth, mMetrics.xHeight, mMetrics.capHeight);
     fprintf (stderr, "    uOff: %f uSize: %f stOff: %f stSize: %f\n", mMetrics.underlineOffset, mMetrics.underlineSize, mMetrics.strikeoutOffset, mMetrics.strikeoutSize);
 #endif
 }
 
 gfxFloat
 gfxMacFont::GetCharWidth(CFDataRef aCmap, char16_t aUniChar,
                          uint32_t *aGlyphID, gfxFloat aConvFactor)
 {
@@ -418,16 +422,17 @@ gfxMacFont::InitMetricsFromPlatform()
     // (fallback code in gfxMacFont::InitMetrics will then try measuring 'x');
     // this could lead to less-than-"perfect" text field sizing when width is
     // specified as a number of characters, and the font in use is a non-sfnt
     // legacy font, but that's a sufficiently obscure edge case that we can
     // ignore the potential discrepancy.
     mMetrics.aveCharWidth = 0;
 
     mMetrics.xHeight = ::CTFontGetXHeight(ctFont);
+    mMetrics.capHeight = ::CTFontGetCapHeight(ctFont);
 
     ::CFRelease(ctFont);
 
     mIsValid = true;
 }
 
 already_AddRefed<ScaledFont>
 gfxMacFont::GetScaledFont(DrawTarget *aTarget)