summaryrefslogtreecommitdiffstats
path: root/app/gfx/font_skia.cc
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 17:15:22 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 17:15:22 +0000
commit5275c3dbc87f48da96a2880c2ac12e956c18784c (patch)
tree1c1a15bba4f850e55fcc444ba5f53a488082a97d /app/gfx/font_skia.cc
parentc6f26b5d3fb527d4731b08553fd2ba8272df550f (diff)
downloadchromium_src-5275c3dbc87f48da96a2880c2ac12e956c18784c.zip
chromium_src-5275c3dbc87f48da96a2880c2ac12e956c18784c.tar.gz
chromium_src-5275c3dbc87f48da96a2880c2ac12e956c18784c.tar.bz2
Do work necessary to make Views About panel work on Chrome OS. This is to be used for forcing Chrome OS updates.
There were many things that needed to be fixed for this to work. Make skia's canvas return height of font for size of strings, instead of the actual height of the characters to bring it in line with Windows. Make average character widths use pango metrics and windows dialog units. Make this lazy, to avoid most calls. Fix bug in About panel that failed to adjust the embedded links to allow for the padding that Link adds so they can be focused. Support gtk about panel in regular build, views in chrome os only. Fix WindowGtk to call WindowClosing() Fix canvas_linux::SetupPangoLayout() to wrap correctly, if passed a width Fix Label::ComputeMultiLineFlags() to turn off eliding. With eliding the pango routines always return 1 line. Enable focus manager in dialogs. Version loader crashed in debug. Review URL: http://codereview.chromium.org/282002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gfx/font_skia.cc')
-rw-r--r--app/gfx/font_skia.cc43
1 files changed, 30 insertions, 13 deletions
diff --git a/app/gfx/font_skia.cc b/app/gfx/font_skia.cc
index 41c29c6..70d6cf2 100644
--- a/app/gfx/font_skia.cc
+++ b/app/gfx/font_skia.cc
@@ -69,22 +69,14 @@ Font::Font(SkTypeface* tf, const std::wstring& font_family, int font_size,
void Font::calculateMetrics() {
SkPaint paint;
SkPaint::FontMetrics metrics;
-
PaintSetup(&paint);
paint.getFontMetrics(&metrics);
ascent_ = SkScalarCeil(-metrics.fAscent);
height_ = ascent_ + SkScalarCeil(metrics.fDescent);
+ // avg_width_ is calculated lazily, as it's expensive and not used often.
+ avg_width_ = -1.0;
- if (metrics.fAvgCharWidth) {
- avg_width_ = SkScalarRound(metrics.fAvgCharWidth);
- } else {
- static const char x_char = 'x';
- paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
- SkScalar width = paint.measureText(&x_char, 1);
-
- avg_width_ = static_cast<int>(ceilf(SkScalarToFloat(width)));
- }
}
void Font::CopyFont(const Font& other) {
@@ -108,7 +100,7 @@ int Font::baseline() const {
}
int Font::ave_char_width() const {
- return avg_width_;
+ return SkScalarRound(const_cast<Font*>(this)->avg_width());
}
Font Font::CreateFont(const std::wstring& font_family, int font_size) {
@@ -176,10 +168,35 @@ int Font::GetStringWidth(const std::wstring& text) const {
return width;
}
-int Font::GetExpectedTextWidth(int length) const {
- return length * avg_width_;
+double Font::avg_width() {
+ if (avg_width_ < 0) {
+ // First get the pango based width
+ PangoFontDescription* pango_desc = gfx::Font::PangoFontFromGfxFont(*this);
+ PangoContext* context =
+ gdk_pango_context_get_for_screen(gdk_screen_get_default());
+ PangoFontMetrics* pango_metrics =
+ pango_context_get_metrics(context,
+ pango_desc,
+ pango_language_get_default());
+ double pango_width =
+ pango_font_metrics_get_approximate_char_width(pango_metrics);
+ pango_width /= PANGO_SCALE;
+
+ // Yes, this is how Microsoft recommends calculating the dialog unit
+ // conversions.
+ int text_width = GetStringWidth(
+ L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
+ double dialog_units = (text_width / 26 + 1) / 2;
+
+ avg_width_ = std::min(pango_width, dialog_units);
+ }
+ return avg_width_;
}
+int Font::GetExpectedTextWidth(int length) const {
+ double char_width = const_cast<Font*>(this)->avg_width();
+ return round(static_cast<float>(length) * char_width);
+}
int Font::style() const {
return style_;