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 "chrome/browser/ui/webui/options/font_settings_utils.h" | 5 #include "chrome/browser/ui/webui/options/font_settings_utils.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/mac/scoped_nsautorelease_pool.h" | 9 #include "base/mac/scoped_nsautorelease_pool.h" |
| 10 #include "base/mac/scoped_nsobject.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 | 15 |
15 namespace options { | 16 namespace options { |
16 | 17 |
17 static void ValidateFontFamily(PrefService* prefs, | 18 static void ValidateFontFamily(PrefService* prefs, |
18 const char* family_pref_name) { | 19 const char* family_pref_name) { |
19 // The native font settings dialog saved fonts by the font name, rather | 20 // The native font settings dialog saved fonts by the font name, rather |
20 // than the family name. This worked for the old dialog since | 21 // than the family name. This worked for the old dialog since |
21 // -[NSFont fontWithName:size] accepted a font or family name, but the | 22 // -[NSFont fontWithName:size] accepted a font or family name, but the |
22 // behavior was technically wrong. Since we really need the family name for | 23 // behavior was technically wrong. Since we really need the family name for |
23 // the dom-ui options window, we will fix the saved preference if necessary. | 24 // the dom-ui options window, we will fix the saved preference if necessary. |
24 NSString *family_name = | 25 NSString *pref_value = |
25 base::SysUTF8ToNSString(prefs->GetString(family_pref_name)); | 26 base::SysUTF8ToNSString(prefs->GetString(family_pref_name)); |
26 NSFont *font = [NSFont fontWithName:family_name | 27 NSFont *font = [NSFont fontWithName:pref_value |
27 size:[NSFont systemFontSize]]; | 28 size:[NSFont systemFontSize]]; |
| 29 NSString* family_name = [font familyName]; |
| 30 base::scoped_nsobject<NSFontManager> font_manager( |
| 31 [[NSFontManager alloc] init]); |
| 32 // The fixed pitch check is for Osaka-Mono which exceptionally stores font |
| 33 // name instead of font family name. See GetFontList_SlowBlocking |
| 34 // in font_list_mac.mm for more info. |
28 if (font && | 35 if (font && |
29 [[font familyName] caseInsensitiveCompare:family_name] != NSOrderedSame) { | 36 [family_name caseInsensitiveCompare:pref_value] != NSOrderedSame && |
30 std::string new_family_name = base::SysNSStringToUTF8([font familyName]); | 37 [font_manager fontNamed:family_name hasTraits:NSFixedPitchFontMask] == |
31 prefs->SetString(family_pref_name, new_family_name); | 38 [font_manager fontNamed:pref_value hasTraits:NSFixedPitchFontMask]) { |
| 39 std::string new_pref_value = base::SysNSStringToUTF8(family_name); |
| 40 prefs->SetString(family_pref_name, new_pref_value); |
32 } | 41 } |
33 } | 42 } |
34 | 43 |
35 // static | 44 // static |
36 void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { | 45 void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { |
37 ValidateFontFamily(prefs, prefs::kWebKitSerifFontFamily); | 46 ValidateFontFamily(prefs, prefs::kWebKitSerifFontFamily); |
38 ValidateFontFamily(prefs, prefs::kWebKitSansSerifFontFamily); | 47 ValidateFontFamily(prefs, prefs::kWebKitSansSerifFontFamily); |
39 ValidateFontFamily(prefs, prefs::kWebKitFixedFontFamily); | 48 ValidateFontFamily(prefs, prefs::kWebKitFixedFontFamily); |
40 } | 49 } |
41 | 50 |
42 } // namespace options | 51 } // namespace options |
OLD | NEW |