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" |
(...skipping 69 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 string16& text, const gfx::Font& font) { | 90 int Canvas::GetStringWidth(const base::string16& text, const gfx::Font& font) { |
91 int width = 0, height = 0; | 91 int width = 0, height = 0; |
92 Canvas::SizeStringInt(text, font, &width, &height, 0, NO_ELLIPSIS); | 92 Canvas::SizeStringInt(text, font, &width, &height, 0, NO_ELLIPSIS); |
93 return width; | 93 return width; |
94 } | 94 } |
95 | 95 |
96 // static | 96 // static |
97 int Canvas::DefaultCanvasTextAlignment() { | 97 int Canvas::DefaultCanvasTextAlignment() { |
98 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; | 98 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; |
99 } | 99 } |
100 | 100 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( | 402 skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( |
403 image_rep, | 403 image_rep, |
404 SkShader::kRepeat_TileMode, | 404 SkShader::kRepeat_TileMode, |
405 matrix); | 405 matrix); |
406 | 406 |
407 SkPaint p(paint); | 407 SkPaint p(paint); |
408 p.setShader(shader.get()); | 408 p.setShader(shader.get()); |
409 canvas_->drawPath(path, p); | 409 canvas_->drawPath(path, p); |
410 } | 410 } |
411 | 411 |
412 void Canvas::DrawStringInt(const string16& text, | 412 void Canvas::DrawStringInt(const base::string16& text, |
413 const gfx::Font& font, | 413 const gfx::Font& font, |
414 SkColor color, | 414 SkColor color, |
415 int x, int y, int w, int h) { | 415 int x, int y, int w, int h) { |
416 DrawStringInt(text, font, color, x, y, w, h, DefaultCanvasTextAlignment()); | 416 DrawStringInt(text, font, color, x, y, w, h, DefaultCanvasTextAlignment()); |
417 } | 417 } |
418 | 418 |
419 void Canvas::DrawStringInt(const string16& text, | 419 void Canvas::DrawStringInt(const base::string16& text, |
420 const gfx::Font& font, | 420 const gfx::Font& font, |
421 SkColor color, | 421 SkColor color, |
422 const gfx::Rect& display_rect) { | 422 const gfx::Rect& display_rect) { |
423 DrawStringInt(text, font, color, display_rect.x(), display_rect.y(), | 423 DrawStringInt(text, font, color, display_rect.x(), display_rect.y(), |
424 display_rect.width(), display_rect.height()); | 424 display_rect.width(), display_rect.height()); |
425 } | 425 } |
426 | 426 |
427 void Canvas::DrawStringInt(const string16& text, | 427 void Canvas::DrawStringInt(const base::string16& text, |
428 const gfx::Font& font, | 428 const gfx::Font& font, |
429 SkColor color, | 429 SkColor color, |
430 int x, int y, int w, int h, | 430 int x, int y, int w, int h, |
431 int flags) { | 431 int flags) { |
432 DrawStringWithShadows(text, | 432 DrawStringWithShadows(text, |
433 font, | 433 font, |
434 color, | 434 color, |
435 gfx::Rect(x, y, w, h), | 435 gfx::Rect(x, y, w, h), |
436 0, | 436 0, |
437 flags, | 437 flags, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 534 |
535 float bitmap_scale = image_rep.GetScale(); | 535 float bitmap_scale = image_rep.GetScale(); |
536 if (scale_x < bitmap_scale || scale_y < bitmap_scale) | 536 if (scale_x < bitmap_scale || scale_y < bitmap_scale) |
537 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); | 537 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); |
538 } | 538 } |
539 | 539 |
540 return image_rep; | 540 return image_rep; |
541 } | 541 } |
542 | 542 |
543 } // namespace gfx | 543 } // namespace gfx |
OLD | NEW |