| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_mac.h" | 5 #include "ui/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/memory/scoped_nsobject.h" | 10 #include "base/memory/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 "ui/gfx/canvas_skia.h" | |
| 14 #include "ui/gfx/font.h" | 13 #include "ui/gfx/font.h" |
| 15 | 14 |
| 16 namespace gfx { | 15 namespace gfx { |
| 17 | 16 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 17 //////////////////////////////////////////////////////////////////////////////// |
| 19 // PlatformFontMac, public: | 18 // PlatformFontMac, public: |
| 20 | 19 |
| 21 PlatformFontMac::PlatformFontMac() { | 20 PlatformFontMac::PlatformFontMac() { |
| 22 font_size_ = [NSFont systemFontSize]; | 21 font_size_ = [NSFont systemFontSize]; |
| 23 style_ = gfx::Font::NORMAL; | 22 style_ = gfx::Font::NORMAL; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 49 } | 48 } |
| 50 | 49 |
| 51 int PlatformFontMac::GetBaseline() const { | 50 int PlatformFontMac::GetBaseline() const { |
| 52 return ascent_; | 51 return ascent_; |
| 53 } | 52 } |
| 54 | 53 |
| 55 int PlatformFontMac::GetAverageCharacterWidth() const { | 54 int PlatformFontMac::GetAverageCharacterWidth() const { |
| 56 return average_width_; | 55 return average_width_; |
| 57 } | 56 } |
| 58 | 57 |
| 59 int PlatformFontMac::GetStringWidth(const string16& text) const { | |
| 60 int width = 0, height = 0; | |
| 61 CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontMac*>(this)), | |
| 62 &width, &height, gfx::Canvas::NO_ELLIPSIS); | |
| 63 return width; | |
| 64 } | |
| 65 | |
| 66 int PlatformFontMac::GetExpectedTextWidth(int length) const { | 58 int PlatformFontMac::GetExpectedTextWidth(int length) const { |
| 67 return length * average_width_; | 59 return length * average_width_; |
| 68 } | 60 } |
| 69 | 61 |
| 70 int PlatformFontMac::GetStyle() const { | 62 int PlatformFontMac::GetStyle() const { |
| 71 return style_; | 63 return style_; |
| 72 } | 64 } |
| 73 | 65 |
| 74 std::string PlatformFontMac::GetFontName() const { | 66 std::string PlatformFontMac::GetFontName() const { |
| 75 return font_name_; | 67 return font_name_; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 126 } |
| 135 | 127 |
| 136 // static | 128 // static |
| 137 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 129 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 138 int font_size) { | 130 int font_size) { |
| 139 return new PlatformFontMac(font_name, font_size); | 131 return new PlatformFontMac(font_name, font_size); |
| 140 } | 132 } |
| 141 | 133 |
| 142 } // namespace gfx | 134 } // namespace gfx |
| 143 | 135 |
| OLD | NEW |