Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/canvas.h" | 5 #include "ui/gfx/canvas.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/base/range/range.h" | 10 #include "ui/base/range/range.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 SkColor color, | 131 SkColor color, |
| 132 gfx::RenderText* render_text) { | 132 gfx::RenderText* render_text) { |
| 133 render_text->SetFontList(gfx::FontList(font)); | 133 render_text->SetFontList(gfx::FontList(font)); |
| 134 render_text->SetText(text); | 134 render_text->SetText(text); |
| 135 render_text->SetCursorEnabled(false); | 135 render_text->SetCursorEnabled(false); |
| 136 | 136 |
| 137 gfx::Rect display_rect = rect; | 137 gfx::Rect display_rect = rect; |
| 138 display_rect.set_height(font.GetHeight()); | 138 display_rect.set_height(font.GetHeight()); |
| 139 render_text->SetDisplayRect(display_rect); | 139 render_text->SetDisplayRect(display_rect); |
| 140 | 140 |
| 141 // Set the text alignment explicitly based on the directionality of the UI, | |
| 142 // if not specified. | |
| 143 if (!(flags & (gfx::Canvas::TEXT_ALIGN_CENTER | | |
| 144 gfx::Canvas::TEXT_ALIGN_RIGHT | | |
| 145 gfx::Canvas::TEXT_ALIGN_LEFT))) { | |
| 146 flags |= gfx::Canvas::DefaultCanvasTextAlignment(); | |
| 147 } | |
| 148 | |
| 141 if (flags & gfx::Canvas::TEXT_ALIGN_RIGHT) | 149 if (flags & gfx::Canvas::TEXT_ALIGN_RIGHT) |
| 142 render_text->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 150 render_text->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 143 else if (flags & gfx::Canvas::TEXT_ALIGN_CENTER) | 151 else if (flags & gfx::Canvas::TEXT_ALIGN_CENTER) |
| 144 render_text->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 152 render_text->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 145 else | 153 else |
|
msw
2012/07/03 20:32:23
Make this "else if (flags & gfx::Canvas::TEXT_ALIG
Alexei Svitkine (slow)
2012/07/03 20:34:46
gfx::Canvas::DefaultCanvasTextAlignment() doesn't
msw
2012/07/03 21:06:10
Sigh, ok.
| |
| 146 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 154 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 147 | 155 |
| 148 if (flags & gfx::Canvas::NO_SUBPIXEL_RENDERING) | 156 if (flags & gfx::Canvas::NO_SUBPIXEL_RENDERING) |
| 149 render_text->set_background_is_transparent(true); | 157 render_text->set_background_is_transparent(true); |
| 150 | 158 |
| 151 gfx::StyleRange style; | 159 gfx::StyleRange style; |
| 152 style.foreground = color; | 160 style.foreground = color; |
| 153 style.font_style = font.GetStyle(); | 161 style.font_style = font.GetStyle(); |
| 154 if (font.GetStyle() & gfx::Font::UNDERLINED) | 162 if (font.GetStyle() & gfx::Font::UNDERLINED) |
| 155 style.underline = true; | 163 style.underline = true; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 render_text->SetDisplayRect(rect); | 471 render_text->SetDisplayRect(rect); |
| 464 | 472 |
| 465 canvas_->save(SkCanvas::kClip_SaveFlag); | 473 canvas_->save(SkCanvas::kClip_SaveFlag); |
| 466 ClipRect(display_rect); | 474 ClipRect(display_rect); |
| 467 render_text->Draw(this); | 475 render_text->Draw(this); |
| 468 canvas_->restore(); | 476 canvas_->restore(); |
| 469 } | 477 } |
| 470 #endif | 478 #endif |
| 471 | 479 |
| 472 } // namespace gfx | 480 } // namespace gfx |
| OLD | NEW |