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, factional_height = *height; | |
Alexei Svitkine (slow)
2013/10/07 23:33:28
Nit: Separate lines.
jianli
2013/10/08 00:01:18
Done.
| |
94 SizeStringFloat(text, font_list, &fractional_width, | |
95 &factional_height, line_height, flags); | |
96 *width = std::ceil(fractional_width); | |
97 *height = std::ceil(factional_height); | |
98 } | |
99 | |
100 // static | |
101 void Canvas::SizeStringInt(const base::string16& text, | |
87 const Font& font, | 102 const Font& font, |
88 int* width, | 103 int* width, |
89 int* height, | 104 int* height, |
90 int line_height, | 105 int line_height, |
91 int flags) { | 106 int flags) { |
92 SizeStringInt(text, FontList(font), width, height, line_height, flags); | 107 SizeStringInt(text, FontList(font), width, height, line_height, flags); |
93 } | 108 } |
94 | 109 |
95 // static | 110 // static |
96 int Canvas::GetStringWidth(const base::string16& text, | 111 int Canvas::GetStringWidth(const base::string16& text, |
97 const FontList& font_list) { | 112 const FontList& font_list) { |
98 int width = 0, height = 0; | 113 int width = 0, height = 0; |
99 SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); | 114 SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
100 return width; | 115 return width; |
101 } | 116 } |
102 | 117 |
103 // static | 118 // static |
119 float Canvas::GetStringWidthF(const base::string16& text, | |
120 const FontList& font_list) { | |
121 float width = 0, height = 0; | |
122 SizeStringFloat(text, font_list, &width, &height, 0, NO_ELLIPSIS); | |
123 return width; | |
124 } | |
125 | |
126 // static | |
104 int Canvas::GetStringWidth(const base::string16& text, const Font& font) { | 127 int Canvas::GetStringWidth(const base::string16& text, const Font& font) { |
105 int width = 0, height = 0; | 128 int width = 0, height = 0; |
106 SizeStringInt(text, FontList(font), &width, &height, 0, NO_ELLIPSIS); | 129 SizeStringInt(text, FontList(font), &width, &height, 0, NO_ELLIPSIS); |
107 return width; | 130 return width; |
108 } | 131 } |
109 | 132 |
110 // static | 133 // static |
111 int Canvas::DefaultCanvasTextAlignment() { | 134 int Canvas::DefaultCanvasTextAlignment() { |
112 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; | 135 return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; |
113 } | 136 } |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 | 633 |
611 float bitmap_scale = image_rep.scale(); | 634 float bitmap_scale = image_rep.scale(); |
612 if (scale_x < bitmap_scale || scale_y < bitmap_scale) | 635 if (scale_x < bitmap_scale || scale_y < bitmap_scale) |
613 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); | 636 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); |
614 } | 637 } |
615 | 638 |
616 return image_rep; | 639 return image_rep; |
617 } | 640 } |
618 | 641 |
619 } // namespace gfx | 642 } // namespace gfx |
OLD | NEW |