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

Unified Diff: ui/gfx/render_text.cc

Issue 18848002: Shows Japanese and English mixed queries correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes RenderText::GetAlignmentOffset(). Created 7 years, 5 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698