| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale)); | 76 Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale)); |
| 77 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), | 77 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), |
| 78 pixel_size.height(), | 78 pixel_size.height(), |
| 79 is_opaque)); | 79 is_opaque)); |
| 80 canvas_ = owned_canvas_.get(); | 80 canvas_ = owned_canvas_.get(); |
| 81 SkScalar scale_scalar = SkFloatToScalar(image_scale); | 81 SkScalar scale_scalar = SkFloatToScalar(image_scale); |
| 82 canvas_->scale(scale_scalar, scale_scalar); | 82 canvas_->scale(scale_scalar, scale_scalar); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // static | 85 // static |
| 86 void Canvas::SizeStringInt(const base::string16& text, | 86 void Canvas::SizeStringToFit(const base::string16& text, |
| 87 const Font& font, | 87 const Font& font, |
| 88 int* width, | 88 float* width, |
| 89 int* height, | 89 float* height, |
| 90 int line_height, | 90 int line_height, |
| 91 int flags) { | 91 int flags) { |
| 92 SizeStringInt(text, FontList(font), width, height, line_height, flags); | 92 SizeStringToFit(text, FontList(font), width, height, line_height, flags); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // static | 95 // static |
| 96 int Canvas::GetStringWidth(const base::string16& text, | 96 float Canvas::GetStringWidth(const base::string16& text, |
| 97 const FontList& font_list) { | 97 const FontList& font_list) { |
| 98 int width = 0, height = 0; | 98 float width = 0, height = 0; |
| 99 SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); | 99 SizeStringToFit(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
| 100 return width; | 100 return width; |
| 101 } | 101 } |
| 102 | 102 |
| 103 // static | 103 // static |
| 104 int Canvas::GetStringWidth(const base::string16& text, const Font& font) { | 104 float Canvas::GetStringWidth(const base::string16& text, const Font& font) { |
| 105 int width = 0, height = 0; | 105 float width = 0, height = 0; |
| 106 SizeStringInt(text, FontList(font), &width, &height, 0, NO_ELLIPSIS); | 106 SizeStringToFit(text, FontList(font), &width, &height, 0, NO_ELLIPSIS); |
| 107 return width; | 107 return width; |
| 108 } | 108 } |
| 109 | 109 |
| 110 // static | 110 // static |
| 111 int Canvas::DefaultCanvasTextAlignment() { | 111 int Canvas::DefaultCanvasTextAlignment() { |
| 112 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; | 112 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void Canvas::DrawStringWithHalo(const base::string16& text, | 115 void Canvas::DrawStringWithHalo(const base::string16& text, |
| 116 const Font& font, | 116 const Font& font, |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 610 |
| 611 float bitmap_scale = image_rep.scale(); | 611 float bitmap_scale = image_rep.scale(); |
| 612 if (scale_x < bitmap_scale || scale_y < bitmap_scale) | 612 if (scale_x < bitmap_scale || scale_y < bitmap_scale) |
| 613 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); | 613 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 return image_rep; | 616 return image_rep; |
| 617 } | 617 } |
| 618 | 618 |
| 619 } // namespace gfx | 619 } // namespace gfx |
| OLD | NEW |