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 <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 canvas_->scale(scale_scalar, scale_scalar); | 85 canvas_->scale(scale_scalar, scale_scalar); |
86 } | 86 } |
87 | 87 |
88 // static | 88 // static |
89 void Canvas::SizeStringInt(const base::string16& text, | 89 void Canvas::SizeStringInt(const base::string16& text, |
90 const FontList& font_list, | 90 const FontList& font_list, |
91 int* width, | 91 int* width, |
92 int* height, | 92 int* height, |
93 int line_height, | 93 int line_height, |
94 int flags) { | 94 int flags) { |
95 float fractional_width = *width; | 95 float fractional_width = static_cast<float>(*width); |
96 float factional_height = *height; | 96 float factional_height = static_cast<float>(*height); |
97 SizeStringFloat(text, font_list, &fractional_width, | 97 SizeStringFloat(text, font_list, &fractional_width, |
98 &factional_height, line_height, flags); | 98 &factional_height, line_height, flags); |
99 *width = std::ceil(fractional_width); | 99 *width = static_cast<int>(std::ceil(fractional_width)); |
msw
2014/10/17 22:13:23
nit q: DCHECK when the int type can't support the
Peter Kasting
2014/10/21 01:20:45
Changed to ToCeiledInt() for these, which saturate
| |
100 *height = std::ceil(factional_height); | 100 *height = static_cast<int>(std::ceil(factional_height)); |
101 } | 101 } |
102 | 102 |
103 // static | 103 // static |
104 int Canvas::GetStringWidth(const base::string16& text, | 104 int Canvas::GetStringWidth(const base::string16& text, |
105 const FontList& font_list) { | 105 const FontList& font_list) { |
106 int width = 0, height = 0; | 106 int width = 0, height = 0; |
107 SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); | 107 SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
108 return width; | 108 return width; |
109 } | 109 } |
110 | 110 |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 SkPaint p(paint); | 634 SkPaint p(paint); |
635 p.setFilterLevel(filter ? SkPaint::kLow_FilterLevel | 635 p.setFilterLevel(filter ? SkPaint::kLow_FilterLevel |
636 : SkPaint::kNone_FilterLevel); | 636 : SkPaint::kNone_FilterLevel); |
637 p.setShader(shader.get()); | 637 p.setShader(shader.get()); |
638 | 638 |
639 // The rect will be filled by the bitmap. | 639 // The rect will be filled by the bitmap. |
640 canvas_->drawRect(dest_rect, p); | 640 canvas_->drawRect(dest_rect, p); |
641 } | 641 } |
642 | 642 |
643 } // namespace gfx | 643 } // namespace gfx |
OLD | NEW |