Commit 6060457a authored by msw's avatar msw Committed by Commit bot

Use RenderText vertical centering on Label and CanvasSkia text.

Just use RenderText's cap-height vertical centering.
Do not use one-off naive font-height vertical centering.

BUG=411908
TEST=views::Label and gfx::Canvas::DrawString* text baselines look good and match Textfields.
R=sky@chromium.org

Review URL: https://codereview.chromium.org/585053002

Cr-Commit-Position: refs/heads/master@{#296008}
parent dfefffa1
...@@ -124,10 +124,7 @@ void UpdateRenderText(const Rect& rect, ...@@ -124,10 +124,7 @@ void UpdateRenderText(const Rect& rect,
render_text->SetFontList(font_list); render_text->SetFontList(font_list);
render_text->SetText(text); render_text->SetText(text);
render_text->SetCursorEnabled(false); render_text->SetCursorEnabled(false);
render_text->SetDisplayRect(rect);
Rect display_rect = rect;
display_rect.set_height(font_list.GetHeight());
render_text->SetDisplayRect(display_rect);
// Set the text alignment explicitly based on the directionality of the UI, // Set the text alignment explicitly based on the directionality of the UI,
// if not specified. // if not specified.
...@@ -303,11 +300,6 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text, ...@@ -303,11 +300,6 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text,
UpdateRenderText(rect, adjusted_text, font_list, flags, color, UpdateRenderText(rect, adjusted_text, font_list, flags, color,
render_text.get()); render_text.get());
const int text_height = render_text->GetStringSize().height();
rect += Vector2d(0, (text_bounds.height() - text_height) / 2);
rect.set_height(text_height);
render_text->SetDisplayRect(rect);
if (range.IsValid()) if (range.IsValid())
render_text->ApplyStyle(UNDERLINE, true, range); render_text->ApplyStyle(UNDERLINE, true, range);
render_text->Draw(this); render_text->Draw(this);
...@@ -396,11 +388,6 @@ void Canvas::DrawFadedString(const base::string16& text, ...@@ -396,11 +388,6 @@ void Canvas::DrawFadedString(const base::string16& text,
UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); UpdateRenderText(rect, text, font_list, flags, color, render_text.get());
render_text->SetElideBehavior(FADE_TAIL); render_text->SetElideBehavior(FADE_TAIL);
const int line_height = render_text->GetStringSize().height();
rect += Vector2d(0, (display_rect.height() - line_height) / 2);
rect.set_height(line_height);
render_text->SetDisplayRect(rect);
canvas_->save(); canvas_->save();
ClipRect(display_rect); ClipRect(display_rect);
render_text->Draw(this); render_text->Draw(this);
......
...@@ -427,7 +427,7 @@ gfx::Rect Label::GetTextBounds() const { ...@@ -427,7 +427,7 @@ gfx::Rect Label::GetTextBounds() const {
NOTREACHED(); NOTREACHED();
break; break;
} }
origin.Offset(0, std::max(0, (available.height() - text_size.height())) / 2); text_size.set_height(available.height());
return gfx::Rect(origin, text_size); return gfx::Rect(origin, text_size);
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment