Index: ui/gfx/render_text.cc |
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
index d3c6bea6ffe682b03d68e8e071f991769e5edaa8..87759647264492f1b0ba8683a6cde08793f09404 100644 |
--- a/ui/gfx/render_text.cc |
+++ b/ui/gfx/render_text.cc |
@@ -856,11 +856,28 @@ Vector2d RenderText::GetAlignmentOffset() { |
if (horizontal_alignment_ == ALIGN_CENTER) |
offset.set_x(offset.x() / 2); |
} |
+ const Size& string_size = GetStringSize(); |
if (vertical_alignment_ != ALIGN_TOP) { |
- offset.set_y(display_rect().height() - GetStringSize().height()); |
+ offset.set_y(display_rect().height() - string_size.height()); |
Peter Kasting
2013/07/09 17:28:36
I think we should be subtracting the font height h
Yuki
2013/07/11 13:25:40
Done.
|
if (vertical_alignment_ == ALIGN_VCENTER) |
offset.set_y(offset.y() / 2); |
} |
+ // Vertically centerize text smaller than the font size. |
+ // Character height, returned by |pango_layout_get_pixel_size()|, varies |
+ // depending on character sets even when the font size is the same. |
+ // |
+ // Latin characters (e.g. q and y) have extra space below the baseline and |
+ // another extra space above the characters so it matches the space below |
+ // the baseline. |
+ // With the same font size, some non-Latin characters (e.g. Japanese) don't |
+ // have such extra space below the baseline or above the characters. In that |
+ // case, those characters' height could be smaller than the font size. |
+ // We'll add padding space in such case. |
+ const int font_height = GetFont().GetHeight(); |
+ const int string_height = string_size.height(); |
+ if (string_height < font_height) { |
+ offset.set_y(offset.y() + (font_height - string_height) / 2); |
+ } |
return offset; |
} |