diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-04 01:30:08 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-04 01:30:08 +0000 |
commit | 7accba0ab620be684308e40ff342c3a57bbd9241 (patch) | |
tree | 0a48a322626f9ff7e1ea304ec69f2baca52b14bf /skia | |
parent | 2ecc3274a76dd709e2aaf74d385f57b499d843b5 (diff) | |
download | chromium_src-7accba0ab620be684308e40ff342c3a57bbd9241.zip chromium_src-7accba0ab620be684308e40ff342c3a57bbd9241.tar.gz chromium_src-7accba0ab620be684308e40ff342c3a57bbd9241.tar.bz2 |
Linux: calculate fractional xheight
We need to push the calculation of the x-height into Skia. For one of
the layout tests, it assumes that 2.5ex of Ahem is exactly 32px.
Previously we calculated the x-height of Ahem to be 13px, so 2.5*13 was
33px.
Now we use the 26.6 fixed point number from freetype's hinter and turn
that directly into a floating point value (x-height is the only WebKit
metric which is a floating point value).
This lets us pass LayoutTests/css2.1/t1507-c526-font-sz-02-b-a.html
(although the Windows baseline is wrong)
Review URL: http://codereview.chromium.org/13112
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/include/SkPaint.h | 1 | ||||
-rw-r--r-- | skia/ports/SkFontHost_FreeType.cpp | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/skia/include/SkPaint.h b/skia/include/SkPaint.h index 9529dd0..cc6f760 100644 --- a/skia/include/SkPaint.h +++ b/skia/include/SkPaint.h @@ -592,6 +592,7 @@ public: // in units of em. It's used to calculate a value which // matches Windows's GetTextMetrics tmMaxCharWidth // member exactly. + SkScalar fXHeight; //!< the height of an 'x' in px, or 0 if no 'x' in face // VDMX values are exact ascent and descent values for scalable fonts at // a certain pixel size. diff --git a/skia/ports/SkFontHost_FreeType.cpp b/skia/ports/SkFontHost_FreeType.cpp index 46c86b6..ac938ec 100644 --- a/skia/ports/SkFontHost_FreeType.cpp +++ b/skia/ports/SkFontHost_FreeType.cpp @@ -810,6 +810,17 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx, SkP ys[5] = face->height; ys[6] = os2 ? os2->xAvgCharWidth : 0; + SkScalar x_height; + const FT_UInt x_glyph = FT_Get_Char_Index(fFace, 'x'); + if (x_glyph) { + FT_BBox bbox; + FT_Load_Glyph(fFace, x_glyph, fLoadGlyphFlags); + FT_Outline_Get_CBox(&fFace->glyph->outline, &bbox); + x_height = static_cast<SkScalar>(bbox.yMax) / 64; + } else { + x_height = 0; + } + // convert upem-y values into scalar points for (int i = 0; i < 7; i++) { @@ -829,6 +840,7 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx, SkP mx->fHeight = pts[5].fX; mx->fAvgCharWidth = pts[6].fX; mx->fXRange = xrange; + mx->fXHeight = x_height; // The VDMX metrics only make sense in the horizontal direction // I believe @@ -844,6 +856,7 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx, SkP my->fHeight = pts[5].fY; my->fAvgCharWidth = pts[6].fY; my->fXRange = xrange; + my->fXHeight = x_height; my->fVDMXMetricsValid = false; // Attempt to parse the VDMX table to get exact metrics |