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 <cmath> |
7 #include <limits> | 8 #include <limits> |
8 | 9 |
9 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/effects/SkGradientShader.h" | 13 #include "third_party/skia/include/effects/SkGradientShader.h" |
13 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/font_list.h" | 15 #include "ui/gfx/font_list.h" |
15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
16 #include "ui/gfx/size_conversions.h" | 17 #include "ui/gfx/size_conversions.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), | 78 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), |
78 pixel_size.height(), | 79 pixel_size.height(), |
79 is_opaque)); | 80 is_opaque)); |
80 canvas_ = owned_canvas_.get(); | 81 canvas_ = owned_canvas_.get(); |
81 SkScalar scale_scalar = SkFloatToScalar(image_scale); | 82 SkScalar scale_scalar = SkFloatToScalar(image_scale); |
82 canvas_->scale(scale_scalar, scale_scalar); | 83 canvas_->scale(scale_scalar, scale_scalar); |
83 } | 84 } |
84 | 85 |
85 // static | 86 // static |
86 void Canvas::SizeStringInt(const base::string16& text, | 87 void Canvas::SizeStringInt(const base::string16& text, |
| 88 const FontList& font_list, |
| 89 int* width, |
| 90 int* height, |
| 91 int line_height, |
| 92 int flags) { |
| 93 float fractional_width = *width; |
| 94 float factional_height = *height; |
| 95 SizeStringFloat(text, font_list, &fractional_width, |
| 96 &factional_height, line_height, flags); |
| 97 *width = std::ceil(fractional_width); |
| 98 *height = std::ceil(factional_height); |
| 99 } |
| 100 |
| 101 // static |
| 102 void Canvas::SizeStringInt(const base::string16& text, |
87 const Font& font, | 103 const Font& font, |
88 int* width, | 104 int* width, |
89 int* height, | 105 int* height, |
90 int line_height, | 106 int line_height, |
91 int flags) { | 107 int flags) { |
92 SizeStringInt(text, FontList(font), width, height, line_height, flags); | 108 SizeStringInt(text, FontList(font), width, height, line_height, flags); |
93 } | 109 } |
94 | 110 |
95 // static | 111 // static |
96 int Canvas::GetStringWidth(const base::string16& text, | 112 int Canvas::GetStringWidth(const base::string16& text, |
97 const FontList& font_list) { | 113 const FontList& font_list) { |
98 int width = 0, height = 0; | 114 int width = 0, height = 0; |
99 SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); | 115 SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
100 return width; | 116 return width; |
101 } | 117 } |
102 | 118 |
103 // static | 119 // static |
| 120 float Canvas::GetStringWidthF(const base::string16& text, |
| 121 const FontList& font_list) { |
| 122 float width = 0, height = 0; |
| 123 SizeStringFloat(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
| 124 return width; |
| 125 } |
| 126 |
| 127 // static |
104 int Canvas::GetStringWidth(const base::string16& text, const Font& font) { | 128 int Canvas::GetStringWidth(const base::string16& text, const Font& font) { |
105 int width = 0, height = 0; | 129 int width = 0, height = 0; |
106 SizeStringInt(text, FontList(font), &width, &height, 0, NO_ELLIPSIS); | 130 SizeStringInt(text, FontList(font), &width, &height, 0, NO_ELLIPSIS); |
107 return width; | 131 return width; |
108 } | 132 } |
109 | 133 |
110 // static | 134 // static |
111 int Canvas::DefaultCanvasTextAlignment() { | 135 int Canvas::DefaultCanvasTextAlignment() { |
112 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; | 136 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; |
113 } | 137 } |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 634 |
611 float bitmap_scale = image_rep.scale(); | 635 float bitmap_scale = image_rep.scale(); |
612 if (scale_x < bitmap_scale || scale_y < bitmap_scale) | 636 if (scale_x < bitmap_scale || scale_y < bitmap_scale) |
613 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); | 637 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); |
614 } | 638 } |
615 | 639 |
616 return image_rep; | 640 return image_rep; |
617 } | 641 } |
618 | 642 |
619 } // namespace gfx | 643 } // namespace gfx |
OLD | NEW |