Chromium Code Reviews| Index: ui/gfx/canvas_skia.cc |
| diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc |
| index 2d995cfb8664f7367d398250342e4d9bc55f60b3..3dba2a3a35dbc57beac723a6ddb0a17bceb178e8 100644 |
| --- a/ui/gfx/canvas_skia.cc |
| +++ b/ui/gfx/canvas_skia.cc |
| @@ -169,6 +169,7 @@ int AdjustPlatformSpecificFlags(const string16& text, int flags) { |
| void Canvas::SizeStringInt(const string16& text, |
| const Font& font, |
| int* width, int* height, |
| + int line_height, |
| int flags) { |
| DCHECK_GE(*width, 0); |
| DCHECK_GE(*height, 0); |
| @@ -201,7 +202,7 @@ void Canvas::SizeStringInt(const string16& text, |
| render_text->SetText(strings[i]); |
| const Size string_size = render_text->GetStringSize(); |
| w = std::max(w, string_size.width()); |
| - h += string_size.height(); |
| + h += (i > 0 && line_height >= 0) ? line_height : string_size.height(); |
|
msw
2013/04/17 20:12:59
Should line_height really be ignored if the text i
dharcourt
2013/04/17 23:29:40
I think so. Changing the line height should change
|
| } |
| *width = w; |
| *height = h; |
| @@ -228,6 +229,7 @@ void Canvas::DrawStringWithShadows(const string16& text, |
| const Font& font, |
| SkColor color, |
| const Rect& text_bounds, |
| + int line_height, |
| int flags, |
| const ShadowValues& shadows) { |
| if (!IntersectsClipRect(text_bounds)) |
| @@ -268,18 +270,22 @@ void Canvas::DrawStringWithShadows(const string16& text, |
| for (size_t i = 0; i < strings.size(); i++) { |
| ui::Range range = StripAcceleratorChars(flags, &strings[i]); |
| UpdateRenderText(rect, strings[i], font, flags, color, render_text.get()); |
| - const int line_height = render_text->GetStringSize().height(); |
| + int line_padding = 0; |
| + if (line_height >= 0) |
| + line_padding = line_height - render_text->GetStringSize().height(); |
| + else |
| + line_height = render_text->GetStringSize().height(); |
| // TODO(msw|asvitkine): Center Windows multi-line text: crbug.com/107357 |
| #if !defined(OS_WIN) |
| if (i == 0) { |
| // TODO(msw|asvitkine): Support multi-line text with varied heights. |
| - const int aggregate_height = strings.size() * line_height; |
| - rect += Vector2d(0, (text_bounds.height() - aggregate_height) / 2); |
| + const int text_height = strings.size() * line_height - line_padding; |
| + rect += Vector2d(0, (text_bounds.height() - text_height) / 2); |
| } |
| #endif |
| - rect.set_height(line_height); |
| + rect.set_height(line_height - line_padding); |
| if (range.IsValid()) |
| render_text->ApplyStyle(UNDERLINE, true, range); |
| @@ -313,10 +319,10 @@ void Canvas::DrawStringWithShadows(const string16& text, |
| UpdateRenderText(rect, adjusted_text, font, flags, color, |
| render_text.get()); |
| - const int line_height = render_text->GetStringSize().height(); |
| + const int text_height = render_text->GetStringSize().height(); |
|
msw
2013/04/17 20:12:59
nit: Move this above to use in line_height/line_pa
dharcourt
2013/04/17 23:29:40
I don't think I can do that because the line heigh
|
| // Center the text vertically. |
| - rect += Vector2d(0, (text_bounds.height() - line_height) / 2); |
| - rect.set_height(line_height); |
| + rect += Vector2d(0, (text_bounds.height() - text_height) / 2); |
|
msw
2013/04/17 20:12:59
Again, Should line_height really be ignored if the
dharcourt
2013/04/17 23:29:40
I think so, as described above.
|
| + rect.set_height(text_height); |
| render_text->SetDisplayRect(rect); |
| if (range.IsValid()) |
| render_text->ApplyStyle(UNDERLINE, true, range); |