diff --git a/gfx/thebes/public/gfxAtsuiFonts.h b/gfx/thebes/public/gfxAtsuiFonts.h index 768e6d52b1da..40a217c3bde1 100644 --- a/gfx/thebes/public/gfxAtsuiFonts.h +++ b/gfx/thebes/public/gfxAtsuiFonts.h @@ -54,7 +54,8 @@ public: virtual const gfxFont::Metrics& GetMetrics(); - float GetCharWidth (PRUnichar c); + float GetCharWidth(PRUnichar c); + float GetCharHeight(PRUnichar c); ATSUFontID GetATSUFontID() { return mATSUFontID; } diff --git a/gfx/thebes/src/gfxAtsuiFonts.cpp b/gfx/thebes/src/gfxAtsuiFonts.cpp index 0a1539e4a223..d614430b48ef 100644 --- a/gfx/thebes/src/gfxAtsuiFonts.cpp +++ b/gfx/thebes/src/gfxAtsuiFonts.cpp @@ -136,7 +136,11 @@ gfxAtsuiFont::gfxAtsuiFont(ATSUFontID fontID, mMetrics.emDescent = mMetrics.emHeight - mMetrics.emAscent; mMetrics.maxAdvance = atsMetrics.maxAdvanceWidth * size; - mMetrics.xHeight = atsMetrics.xHeight * size; + + if (atsMetrics.xHeight) + mMetrics.xHeight = atsMetrics.xHeight * size; + else + mMetrics.xHeight = GetCharHeight('x'); if (atsMetrics.avgAdvanceWidth != 0.0) mMetrics.aveCharWidth = @@ -201,6 +205,25 @@ gfxAtsuiFont::GetCharWidth(PRUnichar c) return f; } +float +gfxAtsuiFont::GetCharHeight(PRUnichar c) +{ + // this sucks. There is a faster way to go from a char -> glyphs, but it + // requires using oodles of apple private interfaces. If we start caching + // gfxAtsuiFonts, then it might make sense to do that. + ATSUTextLayout layout; + + UniCharCount one = 1; + ATSUCreateTextLayoutWithTextPtr(&c, 0, 1, 1, 1, &one, &mATSUStyle, &layout); + + Rect rect; + ATSUMeasureTextImage(layout, 0, 1, 0, 0, &rect); + + ATSUDisposeTextLayout(layout); + + return rect.bottom - rect.top; +} + gfxAtsuiFont::~gfxAtsuiFont() { cairo_scaled_font_destroy(mScaledFont);