Chromium Code Reviews| Index: content/common/font_list_mac.mm |
| diff --git a/content/common/font_list_mac.mm b/content/common/font_list_mac.mm |
| index 8c7d889b853a9674ecd536dabeb2ac0a672260db..a1b46212a718ecd29fa595c6a349c3eb02fc52f0 100644 |
| --- a/content/common/font_list_mac.mm |
| +++ b/content/common/font_list_mac.mm |
| @@ -16,17 +16,30 @@ |
| base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| std::unique_ptr<base::ListValue> font_list(new base::ListValue); |
| NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; |
| + NSMutableDictionary* fonts_dict = |
| + [[[NSMutableDictionary alloc] init] autorelease]; |
|
Avi (use Gerrit)
2016/11/04 19:59:55
Nit: you can use the convenience constructor:
NSM
|
| NSArray* fonts = [fontManager availableFontFamilies]; |
| + |
| for (NSString* family_name in fonts) { |
| NSString* localized_family_name = |
| [fontManager localizedNameForFamily:family_name face:nil]; |
| + fonts_dict[family_name] = localized_family_name; |
| + } |
| + |
| + // Sort family names based on localized names. |
| + NSArray* sortedFonts = [fonts_dict |
| + keysSortedByValueUsingSelector:@selector(localizedStandardCompare:)]; |
| + |
| + for (NSString* family_name in sortedFonts) { |
| + NSString* localized_family_name = fonts_dict[family_name]; |
| base::ListValue* font_item = new base::ListValue(); |
| base::string16 family = base::SysNSStringToUTF16(family_name); |
| - font_item->Append(new base::StringValue(family)); |
| base::string16 loc_family = base::SysNSStringToUTF16(localized_family_name); |
| + font_item->Append(new base::StringValue(family)); |
| font_item->Append(new base::StringValue(loc_family)); |
| font_list->Append(font_item); |
| } |
| + |
| return font_list; |
| } |