Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: content/common/font_list_mac.mm

Issue 2472283002: In chrome://settings/fonts, fonts are not alphabetically ordered. (Closed)
Patch Set: Change sort Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/common/font_list.h" 5 #include "content/common/font_list.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/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() { 15 std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() {
16 base::mac::ScopedNSAutoreleasePool autorelease_pool; 16 base::mac::ScopedNSAutoreleasePool autorelease_pool;
17 std::unique_ptr<base::ListValue> font_list(new base::ListValue); 17 std::unique_ptr<base::ListValue> font_list(new base::ListValue);
18 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; 18 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
19 NSMutableDictionary* fonts_dict =
20 [[[NSMutableDictionary alloc] init] autorelease];
Avi (use Gerrit) 2016/11/04 19:59:55 Nit: you can use the convenience constructor: NSM
19 NSArray* fonts = [fontManager availableFontFamilies]; 21 NSArray* fonts = [fontManager availableFontFamilies];
22
20 for (NSString* family_name in fonts) { 23 for (NSString* family_name in fonts) {
21 NSString* localized_family_name = 24 NSString* localized_family_name =
22 [fontManager localizedNameForFamily:family_name face:nil]; 25 [fontManager localizedNameForFamily:family_name face:nil];
26 fonts_dict[family_name] = localized_family_name;
27 }
28
29 // Sort family names based on localized names.
30 NSArray* sortedFonts = [fonts_dict
31 keysSortedByValueUsingSelector:@selector(localizedStandardCompare:)];
32
33 for (NSString* family_name in sortedFonts) {
34 NSString* localized_family_name = fonts_dict[family_name];
23 base::ListValue* font_item = new base::ListValue(); 35 base::ListValue* font_item = new base::ListValue();
24 base::string16 family = base::SysNSStringToUTF16(family_name); 36 base::string16 family = base::SysNSStringToUTF16(family_name);
37 base::string16 loc_family = base::SysNSStringToUTF16(localized_family_name);
25 font_item->Append(new base::StringValue(family)); 38 font_item->Append(new base::StringValue(family));
26 base::string16 loc_family = base::SysNSStringToUTF16(localized_family_name);
27 font_item->Append(new base::StringValue(loc_family)); 39 font_item->Append(new base::StringValue(loc_family));
28 font_list->Append(font_item); 40 font_list->Append(font_item);
29 } 41 }
42
30 return font_list; 43 return font_list;
31 } 44 }
32 45
33 } // namespace content 46 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698