Bug 364058 [cocoa-cairo] css length unit 'ex' doesn't work on 10.3.9 r=vald

This commit is contained in:
masayuki%d-toybox.com 2007-01-05 20:00:04 +00:00
parent 0ea4e79fbc
commit dfe6f6a6aa
2 changed files with 26 additions and 2 deletions

View File

@ -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; }

View File

@ -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);