| 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/font.h" | 5 #include "gfx/font.h" |
| 6 | 6 |
| 7 #include <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.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 "gfx/canvas.h" | 12 #include "gfx/canvas_skia.h" |
| 13 | 13 |
| 14 namespace gfx { | 14 namespace gfx { |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 Font Font::CreateFont(const std::wstring& font_name, int font_size) { | 17 Font Font::CreateFont(const std::wstring& font_name, int font_size) { |
| 18 return Font(font_name, font_size, NORMAL); | 18 return Font(font_name, font_size, NORMAL); |
| 19 } | 19 } |
| 20 | 20 |
| 21 Font::Font(const std::wstring& font_name, int font_size, int style) | 21 Font::Font(const std::wstring& font_name, int font_size, int style) |
| 22 : font_name_(font_name), | 22 : font_name_(font_name), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 int Font::baseline() const { | 53 int Font::baseline() const { |
| 54 return ascent_; | 54 return ascent_; |
| 55 } | 55 } |
| 56 | 56 |
| 57 int Font::ave_char_width() const { | 57 int Font::ave_char_width() const { |
| 58 return avg_width_; | 58 return avg_width_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 int Font::GetStringWidth(const std::wstring& text) const { | 61 int Font::GetStringWidth(const std::wstring& text) const { |
| 62 int width = 0, height = 0; | 62 int width = 0, height = 0; |
| 63 Canvas::SizeStringInt(text, *this, &width, &height, gfx::Canvas::NO_ELLIPSIS); | 63 CanvasSkia::SizeStringInt(text, *this, &width, &height, |
| 64 gfx::Canvas::NO_ELLIPSIS); |
| 64 return width; | 65 return width; |
| 65 } | 66 } |
| 66 | 67 |
| 67 int Font::GetExpectedTextWidth(int length) const { | 68 int Font::GetExpectedTextWidth(int length) const { |
| 68 return length * avg_width_; | 69 return length * avg_width_; |
| 69 } | 70 } |
| 70 | 71 |
| 71 int Font::style() const { | 72 int Font::style() const { |
| 72 return style_; | 73 return style_; |
| 73 } | 74 } |
| 74 | 75 |
| 75 const std::wstring& Font::FontName() const { | 76 const std::wstring& Font::FontName() const { |
| 76 return font_name_; | 77 return font_name_; |
| 77 } | 78 } |
| 78 | 79 |
| 79 int Font::FontSize() { | 80 int Font::FontSize() { |
| 80 return font_size_; | 81 return font_size_; |
| 81 } | 82 } |
| 82 | 83 |
| 83 NativeFont Font::nativeFont() const { | 84 NativeFont Font::nativeFont() const { |
| 84 // TODO(pinkerton): apply |style_| to font. http://crbug.com/34667 | 85 // TODO(pinkerton): apply |style_| to font. http://crbug.com/34667 |
| 85 // We could cache this, but then we'd have to conditionally change the | 86 // We could cache this, but then we'd have to conditionally change the |
| 86 // dtor just for MacOS. Not sure if we want to/need to do that. | 87 // dtor just for MacOS. Not sure if we want to/need to do that. |
| 87 return [NSFont fontWithName:base::SysWideToNSString(font_name_) | 88 return [NSFont fontWithName:base::SysWideToNSString(font_name_) |
| 88 size:font_size_]; | 89 size:font_size_]; |
| 89 } | 90 } |
| 90 | 91 |
| 91 } // namespace gfx | 92 } // namespace gfx |
| OLD | NEW |