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/platform_font_ios.h" | 5 #include "ui/gfx/platform_font_ios.h" |
6 | 6 |
7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
8 | 8 |
| 9 #include <cmath> |
| 10 |
9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
10 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
12 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
13 | 15 |
14 namespace gfx { | 16 namespace gfx { |
15 | 17 |
16 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
17 // PlatformFontIOS, public: | 19 // PlatformFontIOS, public: |
18 | 20 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 55 |
54 int PlatformFontIOS::GetCapHeight() const { | 56 int PlatformFontIOS::GetCapHeight() const { |
55 return cap_height_; | 57 return cap_height_; |
56 } | 58 } |
57 | 59 |
58 int PlatformFontIOS::GetAverageCharacterWidth() const { | 60 int PlatformFontIOS::GetAverageCharacterWidth() const { |
59 return average_width_; | 61 return average_width_; |
60 } | 62 } |
61 | 63 |
62 int PlatformFontIOS::GetStringWidth(const base::string16& text) const { | 64 int PlatformFontIOS::GetStringWidth(const base::string16& text) const { |
| 65 return std::ceil(GetStringWidthF(text)); |
| 66 } |
| 67 |
| 68 float PlatformFontIOS::GetStringWidthF(const base::string16& text) const { |
63 NSString* ns_text = base::SysUTF16ToNSString(text); | 69 NSString* ns_text = base::SysUTF16ToNSString(text); |
64 return [ns_text sizeWithFont:GetNativeFont()].width; | 70 return [ns_text sizeWithFont:GetNativeFont()].width; |
65 } | 71 } |
66 | 72 |
67 int PlatformFontIOS::GetExpectedTextWidth(int length) const { | 73 int PlatformFontIOS::GetExpectedTextWidth(int length) const { |
68 return length * average_width_; | 74 return length * average_width_; |
69 } | 75 } |
70 | 76 |
71 int PlatformFontIOS::GetStyle() const { | 77 int PlatformFontIOS::GetStyle() const { |
72 return style_; | 78 return style_; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return new PlatformFontIOS(native_font); | 130 return new PlatformFontIOS(native_font); |
125 } | 131 } |
126 | 132 |
127 // static | 133 // static |
128 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 134 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
129 int font_size) { | 135 int font_size) { |
130 return new PlatformFontIOS(font_name, font_size); | 136 return new PlatformFontIOS(font_name, font_size); |
131 } | 137 } |
132 | 138 |
133 } // namespace gfx | 139 } // namespace gfx |
OLD | NEW |