summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 23:09:31 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 23:09:31 +0000
commit00e7029ffd28402c5f9ed59c26536f084d46f232 (patch)
tree6b488d8df9a8b2343d5527bbe00f569f497126e7
parent21415977868b59b883370ceaba6dcbc7e4fe08c7 (diff)
downloadchromium_src-00e7029ffd28402c5f9ed59c26536f084d46f232.zip
chromium_src-00e7029ffd28402c5f9ed59c26536f084d46f232.tar.gz
chromium_src-00e7029ffd28402c5f9ed59c26536f084d46f232.tar.bz2
Landing font change again. I don't believe early flakiness was the
result of my change. test_shell doesn't use font at all. This is exactly the same change as was earlier landed. BUG=22791 TEST=see bug TBR=agl Review URL: http://codereview.chromium.org/242111 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27790 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/gfx/font_skia.cc40
-rw-r--r--app/gfx/font_unittest.cc4
2 files changed, 28 insertions, 16 deletions
diff --git a/app/gfx/font_skia.cc b/app/gfx/font_skia.cc
index 56851e0..41c29c6 100644
--- a/app/gfx/font_skia.cc
+++ b/app/gfx/font_skia.cc
@@ -4,6 +4,9 @@
#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"
@@ -18,6 +21,27 @@ 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 {
@@ -49,18 +73,8 @@ void Font::calculateMetrics() {
PaintSetup(&paint);
paint.getFontMetrics(&metrics);
- // 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);
+ ascent_ = SkScalarCeil(-metrics.fAscent);
+ height_ = ascent_ + SkScalarCeil(metrics.fDescent);
if (metrics.fAvgCharWidth) {
avg_width_ = SkScalarRound(metrics.fAvgCharWidth);
@@ -148,7 +162,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_));
+ paint->setTextSize(SkFloatToScalar(font_size_ * GetPangoScaleFactor()));
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 dc81ca8..405c130 100644
--- a/app/gfx/font_unittest.cc
+++ b/app/gfx/font_unittest.cc
@@ -31,13 +31,11 @@ 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_GT(cf.baseline(), 2);
- ASSERT_LT(cf.baseline(), 20);
+ ASSERT_LT(cf.baseline(), 22);
}
TEST_F(FontTest, AvgWidths) {