Chromium Code Reviews| 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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 font_size_ = font_size; | 103 font_size_ = font_size; |
| 104 style_ = style; | 104 style_ = style; |
| 105 CalculateMetrics(); | 105 CalculateMetrics(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void PlatformFontIOS::CalculateMetrics() { | 108 void PlatformFontIOS::CalculateMetrics() { |
| 109 UIFont* font = GetNativeFont(); | 109 UIFont* font = GetNativeFont(); |
| 110 height_ = font.lineHeight; | 110 height_ = font.lineHeight; |
| 111 ascent_ = font.ascender; | 111 ascent_ = font.ascender; |
| 112 cap_height_ = font.capHeight; | 112 cap_height_ = font.capHeight; |
| 113 average_width_ = [@"x" sizeWithFont:font].width; | 113 NSDictionary* attributes = @{ NSFontAttributeName : font }; |
| 114 average_width_ = ceilf([@"x" sizeWithAttributes:attributes].width); | |
|
sdefresne
2014/08/13 09:30:37
nit: why not use std::ceil from <cmath> and avoid
stuartmorgan
2014/08/13 14:07:35
Good call; done.
| |
| 114 } | 115 } |
| 115 | 116 |
| 116 //////////////////////////////////////////////////////////////////////////////// | 117 //////////////////////////////////////////////////////////////////////////////// |
| 117 // PlatformFont, public: | 118 // PlatformFont, public: |
| 118 | 119 |
| 119 // static | 120 // static |
| 120 PlatformFont* PlatformFont::CreateDefault() { | 121 PlatformFont* PlatformFont::CreateDefault() { |
| 121 return new PlatformFontIOS; | 122 return new PlatformFontIOS; |
| 122 } | 123 } |
| 123 | 124 |
| 124 // static | 125 // static |
| 125 PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) { | 126 PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) { |
| 126 return new PlatformFontIOS(native_font); | 127 return new PlatformFontIOS(native_font); |
| 127 } | 128 } |
| 128 | 129 |
| 129 // static | 130 // static |
| 130 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 131 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 131 int font_size) { | 132 int font_size) { |
| 132 return new PlatformFontIOS(font_name, font_size); | 133 return new PlatformFontIOS(font_name, font_size); |
| 133 } | 134 } |
| 134 | 135 |
| 135 } // namespace gfx | 136 } // namespace gfx |
| OLD | NEW |