diff options
-rw-r--r-- | skia/include/SkPaint.h | 1 | ||||
-rw-r--r-- | skia/ports/SkFontHost_FreeType.cpp | 13 | ||||
-rw-r--r-- | webkit/port/platform/graphics/chromium/FontCacheLinux.cpp | 3 | ||||
-rw-r--r-- | webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp | 9 |
4 files changed, 19 insertions, 7 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 diff --git a/webkit/port/platform/graphics/chromium/FontCacheLinux.cpp b/webkit/port/platform/graphics/chromium/FontCacheLinux.cpp index 7a0606c..ab37374 100644 --- a/webkit/port/platform/graphics/chromium/FontCacheLinux.cpp +++ b/webkit/port/platform/graphics/chromium/FontCacheLinux.cpp @@ -42,7 +42,6 @@ const AtomicString& FontCache::alternateFamilyName(const AtomicString& familyNam FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font) { - notImplemented(); return 0; } @@ -111,7 +110,7 @@ AtomicString FontCache::getGenericFontForScript(UScriptCode script, const FontDescription&) { notImplemented(); - return AtomicString(); + return AtomicString("Times New Roman"); } } // namespace WebCore diff --git a/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp b/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp index 8e0e3f6..7b8a75e 100644 --- a/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp +++ b/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp @@ -52,10 +52,15 @@ void SimpleFontData::platformInit() if (!glyphPageZero) return; - static const UChar32 e_char = 'e'; static const UChar32 M_char = 'M'; - m_avgCharWidth = widthForGlyph(glyphPageZero->glyphDataForCharacter(e_char).glyph); m_maxCharWidth = widthForGlyph(glyphPageZero->glyphDataForCharacter(M_char).glyph); + + if (metrics.fAvgCharWidth) { + m_avgCharWidth = SkScalarRound(metrics.fAvgCharWidth); + } else { + static const UChar32 x_char = 'x'; + m_avgCharWidth = widthForGlyph(glyphPageZero->glyphDataForCharacter(x_char).glyph); + } } void SimpleFontData::platformDestroy() |