OLD | NEW |
---|---|
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 <utility> | |
10 | |
9 #include "base/mac/scoped_nsautorelease_pool.h" | 11 #include "base/mac/scoped_nsautorelease_pool.h" |
12 #include "base/memory/ptr_util.h" | |
10 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
11 #include "base/values.h" | 14 #include "base/values.h" |
12 | 15 |
13 namespace content { | 16 namespace content { |
14 | 17 |
15 std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() { | 18 std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() { |
16 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 19 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
17 std::unique_ptr<base::ListValue> font_list(new base::ListValue); | 20 std::unique_ptr<base::ListValue> font_list(new base::ListValue); |
18 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; | 21 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; |
19 NSMutableDictionary* fonts_dict = [NSMutableDictionary dictionary]; | 22 NSMutableDictionary* fonts_dict = [NSMutableDictionary dictionary]; |
20 NSArray* fonts = [fontManager availableFontFamilies]; | 23 NSArray* fonts = [fontManager availableFontFamilies]; |
21 | 24 |
22 for (NSString* family_name in fonts) { | 25 for (NSString* family_name in fonts) { |
23 NSString* localized_family_name = | 26 NSString* localized_family_name = |
24 [fontManager localizedNameForFamily:family_name face:nil]; | 27 [fontManager localizedNameForFamily:family_name face:nil]; |
25 fonts_dict[family_name] = localized_family_name; | 28 fonts_dict[family_name] = localized_family_name; |
26 } | 29 } |
27 | 30 |
28 // Sort family names based on localized names. | 31 // Sort family names based on localized names. |
29 NSArray* sortedFonts = [fonts_dict | 32 NSArray* sortedFonts = [fonts_dict |
30 keysSortedByValueUsingSelector:@selector(localizedStandardCompare:)]; | 33 keysSortedByValueUsingSelector:@selector(localizedStandardCompare:)]; |
31 | 34 |
32 for (NSString* family_name in sortedFonts) { | 35 for (NSString* family_name in sortedFonts) { |
33 NSString* localized_family_name = fonts_dict[family_name]; | 36 NSString* localized_family_name = fonts_dict[family_name]; |
34 base::ListValue* font_item = new base::ListValue(); | 37 auto font_item = base::MakeUnique<base::ListValue>(); |
35 base::string16 family = base::SysNSStringToUTF16(family_name); | 38 base::string16 family = base::SysNSStringToUTF16(family_name); |
36 base::string16 loc_family = base::SysNSStringToUTF16(localized_family_name); | 39 base::string16 loc_family = base::SysNSStringToUTF16(localized_family_name); |
37 font_item->Append(new base::Value(family)); | 40 font_item->Append(base::MakeUnique<base::Value>(family)); |
38 font_item->Append(new base::Value(loc_family)); | 41 font_item->Append(base::MakeUnique<base::Value>(loc_family)); |
jdoerrie
2017/04/12 12:37:46
Consider the more compact AppendString, ie:
font_
vabr (Chromium)
2017/04/12 12:55:04
Good point, I completely missed the existence of t
| |
39 font_list->Append(font_item); | 42 font_list->Append(std::move(font_item)); |
40 } | 43 } |
41 | 44 |
42 return font_list; | 45 return font_list; |
43 } | 46 } |
44 | 47 |
45 } // namespace content | 48 } // namespace content |
OLD | NEW |