OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/gfx/canvas.h" | |
6 | |
7 #import <UIKit/UIKit.h> | |
8 | |
9 #include <algorithm> | |
10 #include <cmath> | |
11 | |
12 #include "base/logging.h" | |
13 #include "base/strings/sys_string_conversions.h" | |
14 #include "ui/gfx/font_list.h" | |
15 | |
16 namespace gfx { | |
17 | |
18 // static | |
19 void Canvas::SizeStringInt(const base::string16& text, | |
20 const gfx::FontList& font_list, | |
21 int* width, | |
22 int* height, | |
23 int line_height, | |
24 int flags) { | |
25 DLOG_IF(WARNING, line_height != 0) << "Line height not implemented."; | |
26 DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented."; | |
27 | |
28 NSString* ns_text = base::SysUTF16ToNSString(text); | |
29 CGSize size = [ns_text | |
30 sizeWithFont:font_list.GetPrimaryFont().GetNativeFont()]; | |
Alexei Svitkine (slow)
2013/08/19 14:17:28
Nit: Extract NativeFont into a local var so that t
msw
2013/08/19 19:05:43
Could this implementation be merged with canvas_ma
stuartmorgan
2013/08/19 22:08:11
This is the public documentation for the iOS equiv
Yuki
2013/08/20 15:05:47
Done.
| |
31 *width = std::ceil(size.width); | |
32 *height = std::max(static_cast<int>(std::ceil(size.height)), | |
33 font_list.GetHeight()); | |
34 } | |
35 | |
36 // static | |
37 int Canvas::GetStringWidth(const base::string16& text, | |
38 const gfx::FontList& font_list) { | |
39 int width = 0, height = 0; | |
40 SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); | |
41 return width; | |
42 } | |
43 | |
44 } // namespace gfx | |
OLD | NEW |