diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-26 00:23:23 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-26 00:23:23 +0000 |
commit | f42d28c678cd72979d64eebed9ea879c59e2576a (patch) | |
tree | f5212da1c6af24ec4b4dd82acea43b0335725b7b /skia | |
parent | 5374a134f5547566ed821cceb9393201e4f68606 (diff) | |
download | chromium_src-f42d28c678cd72979d64eebed9ea879c59e2576a.zip chromium_src-f42d28c678cd72979d64eebed9ea879c59e2576a.tar.gz chromium_src-f42d28c678cd72979d64eebed9ea879c59e2576a.tar.bz2 |
Linux: match average char width with Windows
Review URL: http://codereview.chromium.org/12656
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6017 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, 11 insertions, 3 deletions
diff --git a/skia/include/SkPaint.h b/skia/include/SkPaint.h index 06009cb..921245b 100644 --- a/skia/include/SkPaint.h +++ b/skia/include/SkPaint.h @@ -587,6 +587,7 @@ public: SkScalar fBottom; //!< The greatest distance below the baseline for any glyph (will be >= 0) SkScalar fLeading; //!< The recommended distance to add between lines of text (will be >= 0) SkScalar fHeight; //!< the vertical distance between two consecutive baselines (>= 0) + SkScalar fAvgCharWidth; //!< the average charactor width (>= 0) // 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 43b6295..3011811 100644 --- a/skia/ports/SkFontHost_FreeType.cpp +++ b/skia/ports/SkFontHost_FreeType.cpp @@ -785,8 +785,8 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx, SkP return; } - SkPoint pts[6]; - SkFixed ys[6]; + SkPoint pts[7]; + SkFixed ys[7]; FT_Face face = fFace; int upem = face->units_per_EM; SkFixed scaleY = fScaleY; @@ -797,15 +797,20 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx, SkP if (leading < 0) leading = 0; + // Try to get the OS/2 table from the font. This contains the specific + // average font width metrics which Windows uses. + TT_OS2* os2 = (TT_OS2*) FT_Get_Sfnt_Table(face, ft_sfnt_os2); + ys[0] = -face->bbox.yMax; ys[1] = -face->ascender; ys[2] = -face->descender; ys[3] = -face->bbox.yMin; ys[4] = leading; ys[5] = face->height; + ys[6] = os2 ? os2->xAvgCharWidth : 0; // convert upem-y values into scalar points - for (int i = 0; i < 6; i++) + for (int i = 0; i < 7; i++) { SkFixed y = SkMulDiv(scaleY, ys[i], upem); SkFixed x = SkFixedMul(mxy, y); @@ -821,6 +826,7 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx, SkP mx->fBottom = pts[3].fX; mx->fLeading = pts[4].fX; mx->fHeight = pts[5].fX; + mx->fAvgCharWidth = pts[6].fX; // The VDMX metrics only make sense in the horizontal direction // I believe @@ -834,6 +840,7 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx, SkP my->fBottom = pts[3].fY; my->fLeading = pts[4].fY; my->fHeight = pts[5].fY; + my->fAvgCharWidth = pts[6].fY; my->fVDMXMetricsValid = false; // Attempt to parse the VDMX table to get exact metrics |