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

Unified Diff: ui/gfx/canvas_skia.cc

Issue 1013543006: [RenderText] Adding vertical alignment options (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed pixel tests on vertical alignment Created 5 years, 9 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
Index: ui/gfx/canvas_skia.cc
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index 428c32a8b590deb49f458eef18dba97d5ee3bbed..6834b17e76ad0231c4dcef6a72d109399a141dea 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -110,6 +110,15 @@ void UpdateRenderText(const Rect& rect,
else
render_text->SetHorizontalAlignment(ALIGN_LEFT);
+ render_text->SetMultiline((flags & Canvas::MULTI_LINE) != 0);
msw 2015/04/01 15:07:17 This will break RenderTextMac, which doesn't suppo
+
+ if (flags & Canvas::TEXT_ALIGN_TOP)
+ render_text->SetVerticalAlignment(VALIGN_TOP);
+ else if (flags & Canvas::TEXT_ALIGN_BOTTOM)
+ render_text->SetVerticalAlignment(VALIGN_BOTTOM);
+ else
+ render_text->SetVerticalAlignment(VALIGN_MIDDLE);
+
render_text->set_subpixel_rendering_suppressed(
(flags & Canvas::NO_SUBPIXEL_RENDERING) != 0);
@@ -193,75 +202,33 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text,
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->set_shadows(shadows);
- if (flags & MULTI_LINE) {
- WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS;
msw 2015/04/01 15:07:17 The new code should configure RenderText's word wr
- if (flags & CHARACTER_BREAK)
- wrap_behavior = WRAP_LONG_WORDS;
- else if (!(flags & NO_ELLIPSIS))
- wrap_behavior = ELIDE_LONG_WORDS;
msw 2015/04/01 15:07:17 RenderTextHarfBuzz doesn't yet support ELIDE_LONG_
-
- std::vector<base::string16> strings;
- ElideRectangleText(text, font_list,
- static_cast<float>(text_bounds.width()),
- text_bounds.height(), wrap_behavior, &strings);
-
- for (size_t i = 0; i < strings.size(); i++) {
- Range range = StripAcceleratorChars(flags, &strings[i]);
- UpdateRenderText(rect, strings[i], font_list, flags, color,
- render_text.get());
- 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 text_height = strings.size() * line_height - line_padding;
- rect += Vector2d(0, (text_bounds.height() - text_height) / 2);
- }
-#endif
-
- rect.set_height(line_height - line_padding);
-
- if (range.IsValid())
- render_text->ApplyStyle(UNDERLINE, true, range);
- render_text->SetDisplayRect(rect);
- render_text->Draw(this);
- rect += Vector2d(0, line_height);
- }
- } else {
- base::string16 adjusted_text = text;
- Range range = StripAcceleratorChars(flags, &adjusted_text);
- bool elide_text = ((flags & NO_ELLIPSIS) == 0);
+ base::string16 adjusted_text = text;
+ Range range = StripAcceleratorChars(flags, &adjusted_text);
+ bool elide_text = ((flags & NO_ELLIPSIS) == 0);
#if defined(OS_LINUX)
- // On Linux, eliding really means fading the end of the string. But only
- // for LTR text. RTL text is still elided (on the left) with "...".
- if (elide_text) {
- render_text->SetText(adjusted_text);
- if (render_text->GetDisplayTextDirection() == base::i18n::LEFT_TO_RIGHT) {
- render_text->SetElideBehavior(FADE_TAIL);
- elide_text = false;
- }
+ // On Linux, eliding really means fading the end of the string. But only
+ // for LTR text. RTL text is still elided (on the left) with "...".
+ if (elide_text) {
+ render_text->SetText(adjusted_text);
+ if (render_text->GetDisplayTextDirection() == base::i18n::LEFT_TO_RIGHT) {
+ render_text->SetElideBehavior(FADE_TAIL);
+ elide_text = false;
}
+ }
#endif
- if (elide_text) {
- ElideTextAndAdjustRange(font_list,
- static_cast<float>(text_bounds.width()),
- &adjusted_text, &range);
- }
-
- UpdateRenderText(rect, adjusted_text, font_list, flags, color,
- render_text.get());
- if (range.IsValid())
- render_text->ApplyStyle(UNDERLINE, true, range);
- render_text->Draw(this);
+ if (elide_text) {
+ ElideTextAndAdjustRange(font_list, static_cast<float>(text_bounds.width()),
+ &adjusted_text, &range);
}
+ UpdateRenderText(rect, adjusted_text, font_list, flags, color,
+ render_text.get());
+ if (range.IsValid())
+ render_text->ApplyStyle(UNDERLINE, true, range);
+ render_text->Draw(this);
+
canvas_->restore();
}

Powered by Google App Engine
This is Rietveld 408576698