diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-01 18:12:29 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-01 18:12:29 +0000 |
commit | 8c8a57001670985d823e1bddfb4f49b813ada694 (patch) | |
tree | ea25e4efc810d1e0a805df23756c0390c0368600 /app | |
parent | ec9ac0df1c02dc01550b1020ef7e74bd795a2008 (diff) | |
download | chromium_src-8c8a57001670985d823e1bddfb4f49b813ada694.zip chromium_src-8c8a57001670985d823e1bddfb4f49b813ada694.tar.gz chromium_src-8c8a57001670985d823e1bddfb4f49b813ada694.tar.bz2 |
Reverting recent font change, it seems to be causing problems with
test_shell and valgrind ui.
BUG=22791
TEST=none
TBR=agl
Review URL: http://codereview.chromium.org/251059
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27742 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/gfx/font_skia.cc | 40 | ||||
-rw-r--r-- | app/gfx/font_unittest.cc | 4 |
2 files changed, 16 insertions, 28 deletions
diff --git a/app/gfx/font_skia.cc b/app/gfx/font_skia.cc index 41c29c6..56851e0 100644 --- a/app/gfx/font_skia.cc +++ b/app/gfx/font_skia.cc @@ -4,9 +4,6 @@ #include "app/gfx/font.h" -#include <gdk/gdk.h> -#include <pango/pango.h> - #include "app/gfx/canvas.h" #include "base/logging.h" #include "base/string_piece.h" @@ -21,27 +18,6 @@ namespace { // IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp. const char* kFallbackFontFamilyName = "sans"; -// Pango scales font sizes. This returns the scale factor. See -// pango_cairo_context_set_resolution for details. -// NOTE: this isn't entirely accurate, in that Pango also consults the -// FC_PIXEL_SIZE first (see get_font_size in pangocairo-fcfont), but this -// seems to give us the same sizes as used by Pango for all our fonts in both -// English and Thia. -static double GetPangoScaleFactor() { - static float scale_factor = 0; - static bool determined_scale = false; - if (!determined_scale) { - PangoContext* context = gdk_pango_context_get(); - scale_factor = pango_cairo_context_get_resolution(context); - g_object_unref(context); - if (scale_factor <= 0) - scale_factor = 1; - else - scale_factor /= 72.0; - } - return scale_factor; -} - } // namespace namespace gfx { @@ -73,8 +49,18 @@ void Font::calculateMetrics() { PaintSetup(&paint); paint.getFontMetrics(&metrics); - ascent_ = SkScalarCeil(-metrics.fAscent); - height_ = ascent_ + SkScalarCeil(metrics.fDescent); + // NOTE: we don't use the ascent/descent as it doesn't match with how pango + // ends up drawing the text, in particular if we clip to the ascent/descent + // the text is clipped. This algorithm doesn't give us an exact match with + // the numbers returned from pango (we are off by 1 in some cases), but it + // is close enough that you won't notice clipping. + // + // NOTE2: I tried converting this to use Pango exclusively for measuring the + // text but it causes a startup regression. The best I could get it was + // ~10% slow down. Slow down appeared to be entirely in libfontconfig. + ascent_ = SkScalarCeil(-metrics.fTop); + height_ = SkScalarCeil(-metrics.fTop) + SkScalarCeil(metrics.fBottom) + + SkScalarCeil(metrics.fLeading); if (metrics.fAvgCharWidth) { avg_width_ = SkScalarRound(metrics.fAvgCharWidth); @@ -162,7 +148,7 @@ Font Font::DeriveFont(int size_delta, int style) const { void Font::PaintSetup(SkPaint* paint) const { paint->setAntiAlias(false); paint->setSubpixelText(false); - paint->setTextSize(SkFloatToScalar(font_size_ * GetPangoScaleFactor())); + paint->setTextSize(SkFloatToScalar(font_size_)); paint->setTypeface(typeface_); paint->setFakeBoldText((BOLD & style_) && !typeface_->isBold()); paint->setTextSkewX((ITALIC & style_) && !typeface_->isItalic() ? diff --git a/app/gfx/font_unittest.cc b/app/gfx/font_unittest.cc index 405c130..dc81ca8 100644 --- a/app/gfx/font_unittest.cc +++ b/app/gfx/font_unittest.cc @@ -31,11 +31,13 @@ TEST_F(FontTest, LoadArialBold) { TEST_F(FontTest, Ascent) { Font cf(Font::CreateFont(L"Arial", 16)); ASSERT_GT(cf.baseline(), 2); + ASSERT_LT(cf.baseline(), 20); } TEST_F(FontTest, Height) { Font cf(Font::CreateFont(L"Arial", 16)); - ASSERT_LT(cf.baseline(), 22); + ASSERT_GT(cf.baseline(), 2); + ASSERT_LT(cf.baseline(), 20); } TEST_F(FontTest, AvgWidths) { |