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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/effects/SkGradientShader.h" | 12 #include "third_party/skia/include/effects/SkGradientShader.h" |
13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font_list.h" |
15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
16 #include "ui/gfx/size_conversions.h" | 16 #include "ui/gfx/size_conversions.h" |
17 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
18 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
19 | 19 |
20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
21 #include "ui/gfx/canvas_skia_paint.h" | 21 #include "ui/gfx/canvas_skia_paint.h" |
22 #endif | 22 #endif |
23 | 23 |
24 namespace gfx { | 24 namespace gfx { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); | 80 gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); |
81 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), | 81 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), |
82 pixel_size.height(), | 82 pixel_size.height(), |
83 is_opaque)); | 83 is_opaque)); |
84 canvas_ = owned_canvas_.get(); | 84 canvas_ = owned_canvas_.get(); |
85 SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_)); | 85 SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_)); |
86 canvas_->scale(scale, scale); | 86 canvas_->scale(scale, scale); |
87 } | 87 } |
88 | 88 |
89 // static | 89 // static |
| 90 int Canvas::GetStringWidth(const base::string16& text, |
| 91 const gfx::FontList& font_list) { |
| 92 int width = 0, height = 0; |
| 93 Canvas::SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
| 94 return width; |
| 95 } |
| 96 |
| 97 // static |
90 int Canvas::GetStringWidth(const base::string16& text, const gfx::Font& font) { | 98 int Canvas::GetStringWidth(const base::string16& text, const gfx::Font& font) { |
91 int width = 0, height = 0; | 99 int width = 0, height = 0; |
92 Canvas::SizeStringInt(text, font, &width, &height, 0, NO_ELLIPSIS); | 100 Canvas::SizeStringInt(text, font, &width, &height, 0, NO_ELLIPSIS); |
93 return width; | 101 return width; |
94 } | 102 } |
95 | 103 |
96 // static | 104 // static |
97 int Canvas::DefaultCanvasTextAlignment() { | 105 int Canvas::DefaultCanvasTextAlignment() { |
98 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; | 106 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; |
99 } | 107 } |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( | 410 skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( |
403 image_rep, | 411 image_rep, |
404 SkShader::kRepeat_TileMode, | 412 SkShader::kRepeat_TileMode, |
405 matrix); | 413 matrix); |
406 | 414 |
407 SkPaint p(paint); | 415 SkPaint p(paint); |
408 p.setShader(shader.get()); | 416 p.setShader(shader.get()); |
409 canvas_->drawPath(path, p); | 417 canvas_->drawPath(path, p); |
410 } | 418 } |
411 | 419 |
| 420 void Canvas::DrawString(const base::string16& text, |
| 421 const gfx::FontList& font_list, |
| 422 SkColor color, |
| 423 const gfx::Rect& display_rect) { |
| 424 DrawStringWithAligned(text, font_list, color, display_rect, |
| 425 DefaultCanvasTextAlignment()); |
| 426 } |
| 427 |
| 428 void Canvas::DrawStringWithAligned(const base::string16& text, |
| 429 const gfx::FontList& font_list, |
| 430 SkColor color, |
| 431 const gfx::Rect& display_rect, |
| 432 int flags) { |
| 433 DrawStringWithShadows(text, |
| 434 font_list, |
| 435 color, |
| 436 display_rect, |
| 437 0, |
| 438 flags, |
| 439 ShadowValues()); |
| 440 } |
| 441 |
412 void Canvas::DrawStringInt(const base::string16& text, | 442 void Canvas::DrawStringInt(const base::string16& text, |
413 const gfx::Font& font, | 443 const gfx::Font& font, |
414 SkColor color, | 444 SkColor color, |
415 int x, int y, int w, int h) { | 445 int x, int y, int w, int h) { |
416 DrawStringInt(text, font, color, x, y, w, h, DefaultCanvasTextAlignment()); | 446 DrawStringInt(text, font, color, x, y, w, h, DefaultCanvasTextAlignment()); |
417 } | 447 } |
418 | 448 |
419 void Canvas::DrawStringInt(const base::string16& text, | 449 void Canvas::DrawStringInt(const base::string16& text, |
420 const gfx::Font& font, | 450 const gfx::Font& font, |
421 SkColor color, | 451 SkColor color, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 564 |
535 float bitmap_scale = image_rep.GetScale(); | 565 float bitmap_scale = image_rep.GetScale(); |
536 if (scale_x < bitmap_scale || scale_y < bitmap_scale) | 566 if (scale_x < bitmap_scale || scale_y < bitmap_scale) |
537 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); | 567 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); |
538 } | 568 } |
539 | 569 |
540 return image_rep; | 570 return image_rep; |
541 } | 571 } |
542 | 572 |
543 } // namespace gfx | 573 } // namespace gfx |
OLD | NEW |