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_mac.h" | 5 #include "ui/gfx/platform_font_mac.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include <Cocoa/Cocoa.h> | 9 #include <Cocoa/Cocoa.h> |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 //////////////////////////////////////////////////////////////////////////////// | 59 //////////////////////////////////////////////////////////////////////////////// |
| 60 // PlatformFontMac, public: | 60 // PlatformFontMac, public: |
| 61 | 61 |
| 62 PlatformFontMac::PlatformFontMac() | 62 PlatformFontMac::PlatformFontMac() |
| 63 : PlatformFontMac([NSFont systemFontOfSize:[NSFont systemFontSize]]) { | 63 : PlatformFontMac([NSFont systemFontOfSize:[NSFont systemFontSize]]) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 PlatformFontMac::PlatformFontMac(NativeFont native_font) | 66 PlatformFontMac::PlatformFontMac(NativeFont native_font, bool underline) |
| 67 : native_font_([native_font retain]), | 67 : native_font_([native_font retain]), |
| 68 font_name_(base::SysNSStringToUTF8([native_font_ familyName])), | 68 font_name_(base::SysNSStringToUTF8([native_font_ familyName])), |
| 69 font_size_([native_font_ pointSize]), | 69 font_size_([native_font_ pointSize]), |
| 70 font_style_(Font::NORMAL), | 70 font_style_(Font::NORMAL), |
| 71 font_weight_(Font::Weight::NORMAL) { | 71 font_weight_(Font::Weight::NORMAL) { |
| 72 NSFontSymbolicTraits traits = [[native_font fontDescriptor] symbolicTraits]; | 72 NSFontSymbolicTraits traits = [[native_font fontDescriptor] symbolicTraits]; |
| 73 if (traits & NSFontItalicTrait) | 73 if (traits & NSFontItalicTrait) |
| 74 font_style_ |= Font::ITALIC; | 74 font_style_ |= Font::ITALIC; |
| 75 if (underline) | |
| 76 font_style_ |= Font::UNDERLINE; | |
| 75 if (traits & NSFontBoldTrait) | 77 if (traits & NSFontBoldTrait) |
| 76 font_weight_ = Font::Weight::BOLD; | 78 font_weight_ = Font::Weight::BOLD; |
| 77 | 79 |
| 78 CalculateMetricsAndInitRenderParams(); | 80 CalculateMetricsAndInitRenderParams(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 PlatformFontMac::PlatformFontMac(const std::string& font_name, int font_size) | 83 PlatformFontMac::PlatformFontMac(const std::string& font_name, int font_size) |
| 82 : native_font_([NSFontWithSpec(font_name, | 84 : PlatformFontMac(font_name, |
|
karandeepb
2016/08/05 11:03:07
Just a small cleanup.
Avi (use Gerrit)
2016/08/05 14:54:59
Acknowledged.
| |
| 83 font_size, | 85 font_size, |
| 84 Font::NORMAL, | 86 Font::NORMAL, |
| 85 Font::Weight::NORMAL) retain]), | 87 Font::Weight::NORMAL) {} |
| 86 font_name_(font_name), | |
| 87 font_size_(font_size), | |
| 88 font_style_(Font::NORMAL), | |
| 89 font_weight_(Font::Weight::NORMAL) { | |
| 90 CalculateMetricsAndInitRenderParams(); | |
| 91 } | |
| 92 | 88 |
| 93 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
| 94 // PlatformFontMac, PlatformFont implementation: | 90 // PlatformFontMac, PlatformFont implementation: |
| 95 | 91 |
| 96 Font PlatformFontMac::DeriveFont(int size_delta, | 92 Font PlatformFontMac::DeriveFont(int size_delta, |
| 97 int style, | 93 int style, |
| 98 Font::Weight weight) const { | 94 Font::Weight weight) const { |
| 99 if (native_font_ && style == font_style_ && weight == font_weight_) { | 95 if (native_font_ && style == font_style_ && weight == font_weight_) { |
| 100 // System fonts have special attributes starting with 10.11. They should be | 96 // System fonts have special attributes starting with 10.11. They should be |
| 101 // requested using the same descriptor to preserve these attributes. | 97 // requested using the same descriptor to preserve these attributes. Since |
| 102 return Font(new PlatformFontMac([NSFont | 98 // NSFont does not support underline as a descriptor, pass it explicitly. |
| 103 fontWithDescriptor:[native_font_ fontDescriptor] | 99 return Font(new PlatformFontMac( |
| 104 size:font_size_ + size_delta])); | 100 [NSFont fontWithDescriptor:[native_font_ fontDescriptor] |
| 101 size:font_size_ + size_delta], | |
| 102 style & Font::UNDERLINE)); | |
| 105 } | 103 } |
| 106 | 104 |
| 107 return Font( | 105 return Font( |
| 108 new PlatformFontMac(font_name_, font_size_ + size_delta, style, weight)); | 106 new PlatformFontMac(font_name_, font_size_ + size_delta, style, weight)); |
| 109 } | 107 } |
| 110 | 108 |
| 111 int PlatformFontMac::GetHeight() { | 109 int PlatformFontMac::GetHeight() { |
| 112 return height_; | 110 return height_; |
| 113 } | 111 } |
| 114 | 112 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 return new PlatformFontMac(native_font); | 218 return new PlatformFontMac(native_font); |
| 221 } | 219 } |
| 222 | 220 |
| 223 // static | 221 // static |
| 224 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, | 222 PlatformFont* PlatformFont::CreateFromNameAndSize(const std::string& font_name, |
| 225 int font_size) { | 223 int font_size) { |
| 226 return new PlatformFontMac(font_name, font_size); | 224 return new PlatformFontMac(font_name, font_size); |
| 227 } | 225 } |
| 228 | 226 |
| 229 } // namespace gfx | 227 } // namespace gfx |
| OLD | NEW |