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 3// found in the LICENSE file. 4 5#include "content/common/font_list.h" 6 7#import <Cocoa/Cocoa.h> 8 9#include <utility> 10 11#include "base/strings/sys_string_conversions.h" 12#include "base/values.h" 13 14namespace content { 15 16std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() { 17 @autoreleasepool { 18 std::unique_ptr<base::ListValue> font_list(new base::ListValue); 19 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; 20 NSMutableDictionary* fonts_dict = [NSMutableDictionary dictionary]; 21 NSArray* fonts = [fontManager availableFontFamilies]; 22 23 for (NSString* family_name in fonts) { 24 NSString* localized_family_name = 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]; 35 auto font_item = std::make_unique<base::ListValue>(); 36 font_item->AppendString(base::SysNSStringToUTF16(family_name)); 37 font_item->AppendString(base::SysNSStringToUTF16(localized_family_name)); 38 font_list->Append(std::move(font_item)); 39 } 40 41 return font_list; 42 } 43} 44 45} // namespace content 46