| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "gfx/platform_font_mac.h" | 5 #include "gfx/platform_font_mac.h" |
| 6 | 6 |
| 7 #include <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/scoped_nsobject.h" | 10 #include "base/scoped_nsobject.h" |
| 11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "gfx/canvas_skia.h" | 13 #include "gfx/canvas_skia.h" |
| 14 #include "gfx/font.h" | 14 #include "gfx/font.h" |
| 15 | 15 |
| 16 namespace gfx { | 16 namespace gfx { |
| 17 | 17 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 19 // PlatformFontMac, public: | 19 // PlatformFontMac, public: |
| 20 | 20 |
| 21 PlatformFontMac::PlatformFontMac() { | 21 PlatformFontMac::PlatformFontMac() { |
| 22 font_size_ = [NSFont systemFontSize]; | 22 font_size_ = [NSFont systemFontSize]; |
| 23 style_ = gfx::Font::NORMAL; | 23 style_ = gfx::Font::NORMAL; |
| 24 NSFont* system_font = [NSFont systemFontOfSize:font_size_]; | 24 NSFont* system_font = [NSFont systemFontOfSize:font_size_]; |
| 25 font_name_ = base::SysNSStringToWide([system_font fontName]); | 25 font_name_ = base::SysNSStringToUTF16([system_font fontName]); |
| 26 CalculateMetrics(); | 26 CalculateMetrics(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 PlatformFontMac::PlatformFontMac(const Font& other) { | 29 PlatformFontMac::PlatformFontMac(const Font& other) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 PlatformFontMac::PlatformFontMac(NativeFont native_font) { | 32 PlatformFontMac::PlatformFontMac(NativeFont native_font) { |
| 33 } | 33 } |
| 34 | 34 |
| 35 PlatformFontMac::PlatformFontMac(const std::wstring& font_name, | 35 PlatformFontMac::PlatformFontMac(const string16& font_name, |
| 36 int font_size) { | 36 int font_size) { |
| 37 InitWithNameSizeAndStyle(font_name, font_size, gfx::Font::NORMAL); | 37 InitWithNameSizeAndStyle(font_name, font_size, gfx::Font::NORMAL); |
| 38 } | 38 } |
| 39 | 39 |
| 40 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
| 41 // PlatformFontMac, PlatformFont implementation: | 41 // PlatformFontMac, PlatformFont implementation: |
| 42 | 42 |
| 43 Font PlatformFontMac::DeriveFont(int size_delta, int style) const { | 43 Font PlatformFontMac::DeriveFont(int size_delta, int style) const { |
| 44 return Font(new PlatformFontMac(font_name_, font_size_ + size_delta, style)); | 44 return Font(new PlatformFontMac(font_name_, font_size_ + size_delta, style)); |
| 45 } | 45 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 int PlatformFontMac::GetExpectedTextWidth(int length) const { | 66 int PlatformFontMac::GetExpectedTextWidth(int length) const { |
| 67 return length * average_width_; | 67 return length * average_width_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 int PlatformFontMac::GetStyle() const { | 70 int PlatformFontMac::GetStyle() const { |
| 71 return style_; | 71 return style_; |
| 72 } | 72 } |
| 73 | 73 |
| 74 const std::wstring& PlatformFontMac::GetFontName() const { | 74 string16 PlatformFontMac::GetFontName() const { |
| 75 return font_name_; | 75 return font_name_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 int PlatformFontMac::GetFontSize() const { | 78 int PlatformFontMac::GetFontSize() const { |
| 79 return font_size_; | 79 return font_size_; |
| 80 } | 80 } |
| 81 | 81 |
| 82 NativeFont PlatformFontMac::GetNativeFont() const { | 82 NativeFont PlatformFontMac::GetNativeFont() const { |
| 83 // TODO(pinkerton): apply |style_| to font. http://crbug.com/34667 | 83 // TODO(pinkerton): apply |style_| to font. http://crbug.com/34667 |
| 84 // We could cache this, but then we'd have to conditionally change the | 84 // We could cache this, but then we'd have to conditionally change the |
| 85 // dtor just for MacOS. Not sure if we want to/need to do that. | 85 // dtor just for MacOS. Not sure if we want to/need to do that. |
| 86 return [NSFont fontWithName:base::SysWideToNSString(font_name_) | 86 return [NSFont fontWithName:base::SysUTF16ToNSString(font_name_) |
| 87 size:font_size_]; | 87 size:font_size_]; |
| 88 } | 88 } |
| 89 | 89 |
| 90 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
| 91 // PlatformFontMac, private: | 91 // PlatformFontMac, private: |
| 92 | 92 |
| 93 PlatformFontMac::PlatformFontMac(const std::wstring& font_name, | 93 PlatformFontMac::PlatformFontMac(const string16& font_name, |
| 94 int font_size, | 94 int font_size, |
| 95 int style) { | 95 int style) { |
| 96 InitWithNameSizeAndStyle(font_name, font_size, style); | 96 InitWithNameSizeAndStyle(font_name, font_size, style); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void PlatformFontMac::InitWithNameSizeAndStyle(const std::wstring& font_name, | 99 void PlatformFontMac::InitWithNameSizeAndStyle(const string16& font_name, |
| 100 int font_size, | 100 int font_size, |
| 101 int style) { | 101 int style) { |
| 102 font_name_ = font_name; | 102 font_name_ = font_name; |
| 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 PlatformFontMac::CalculateMetrics() { | 108 void PlatformFontMac::CalculateMetrics() { |
| 109 NSFont* font = GetNativeFont(); | 109 NSFont* font = GetNativeFont(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 127 PlatformFont* PlatformFont::CreateFromFont(const Font& other) { | 127 PlatformFont* PlatformFont::CreateFromFont(const Font& other) { |
| 128 return new PlatformFontMac(other); | 128 return new PlatformFontMac(other); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // static | 131 // static |
| 132 PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) { | 132 PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) { |
| 133 return new PlatformFontMac(native_font); | 133 return new PlatformFontMac(native_font); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // static | 136 // static |
| 137 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::wstring& font_name, | 137 PlatformFont* PlatformFont::CreateFromNameAndSize(const string16& font_name, |
| 138 int font_size) { | 138 int font_size) { |
| 139 return new PlatformFontMac(font_name, font_size); | 139 return new PlatformFontMac(font_name, font_size); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace gfx | 142 } // namespace gfx |
| 143 | 143 |
| OLD | NEW |