Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1661)

Unified Diff: app/gfx/font_skia.cc

Issue 183044: Workaround Skia and Pango measuring font heights differently by asking Pango... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/views/frame/status_area_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/gfx/font_skia.cc
===================================================================
--- app/gfx/font_skia.cc (revision 25038)
+++ app/gfx/font_skia.cc (working copy)
@@ -41,9 +41,13 @@
PaintSetup(&paint);
paint.getFontMetrics(&metrics);
- ascent_ = SkScalarRound(-metrics.fAscent);
- height_ = SkScalarRound(-metrics.fAscent + metrics.fDescent +
- metrics.fLeading);
+ // We need to know the number of whole pixels for these measurements. The
+ // height is the number of whole pixels above the baseline, plus the number
+ // of whole pixels below it.
+ ascent_ = SkScalarCeil(-metrics.fAscent);
+ height_ = ascent_ +
+ SkScalarCeil(metrics.fDescent) +
+ SkScalarCeil(metrics.fLeading);
if (metrics.fAvgCharWidth) {
avg_width_ = SkScalarRound(metrics.fAvgCharWidth);
@@ -54,6 +58,23 @@
avg_width_ = static_cast<int>(ceilf(SkScalarToFloat(width)));
}
+
+ // HACK ALERT! Skia and Pango don't agree about how to vertically size text.
+ // Since we use Pango in gfx::Canvas, we need to use its version of the
+ // height or various layouts will look weird.
+ //
+ // From debugging, it looks like Skia's notion of ascenders and descenders
+ // are correct from the pixel rendering, but includes no leading or other
+ // space around the text. Pango includes extra space (at least for the fonts
+ // tested). To hack around this, we now ask Pango to get the height of a
+ // string: we use "l" for the highest ascender, and "g" to get a descender.
+ //
+ // TODO(brettw/jhawkins): figure out how to get the real height that Pango
+ // will use in a reasonable way. This is a horrible hack!
+ int width, height;
+ Canvas cvs(1, 1, true);
+ cvs.SizeStringInt(L"lg", *this, &width, &height, 0);
+ height_ = height;
}
void Font::CopyFont(const Font& other) {
« no previous file with comments | « no previous file | chrome/browser/views/frame/status_area_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698