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

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

Issue 7248065: Changed fontlist to list Osaka-Mono Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 7 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/options/font_settings_utils_mac.mm ('k') | 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 static void AppendNewFontItemToList(NSString* font_value,
16 NSString* font_label,
17 ListValue* font_list) {
18 ListValue* font_item = new ListValue();
19 string16 value_string = base::SysNSStringToUTF16(font_value);
20 font_item->Append(Value::CreateStringValue(value_string));
21 string16 label_string = base::SysNSStringToUTF16(font_label);
22 font_item->Append(Value::CreateStringValue(label_string));
23 font_list->Append(font_item);
24 }
25
15 scoped_ptr<base::ListValue> GetFontList_SlowBlocking() { 26 scoped_ptr<base::ListValue> GetFontList_SlowBlocking() {
16 base::mac::ScopedNSAutoreleasePool autorelease_pool; 27 base::mac::ScopedNSAutoreleasePool autorelease_pool;
17 scoped_ptr<base::ListValue> font_list(new base::ListValue); 28 scoped_ptr<base::ListValue> font_list(new base::ListValue);
18 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; 29 NSFontManager* font_manager = [[[NSFontManager alloc] init] autorelease];
19 NSArray* fonts = [fontManager availableFontFamilies]; 30 NSArray* family_names = [font_manager availableFontFamilies];
20 for (NSString* family_name in fonts) { 31 NSMutableArray* font_families = [NSMutableArray array];
21 NSString* localized_family_name = 32 for (NSString* family_name in family_names) {
22 [fontManager localizedNameForFamily:family_name face:nil]; 33 NSString* localized_family_name = [font_manager
23 base::ListValue* font_item = new base::ListValue(); 34 localizedNameForFamily:family_name face:nil];
24 string16 family = base::SysNSStringToUTF16(family_name); 35 [font_families addObject:[NSDictionary dictionaryWithObjectsAndKeys:
25 font_item->Append(new base::StringValue(family)); 36 family_name, @"name", localized_family_name, @"localizedName", nil]];
26 string16 loc_family = base::SysNSStringToUTF16(localized_family_name); 37 }
27 font_item->Append(new base::StringValue(loc_family)); 38 NSSortDescriptor* sort_descriptor = [[NSSortDescriptor alloc]
28 font_list->Append(font_item); 39 initWithKey:@"localizedName" ascending:YES];
40 [font_families sortUsingDescriptors:
41 [NSArray arrayWithObject:sort_descriptor]];
42 [sort_descriptor release];
43 for (NSDictionary* family in font_families) {
44 NSString* family_name = [family objectForKey:@"name"];
45 AppendNewFontItemToList(family_name,
46 [family objectForKey:@"localizedName"],
47 font_list.get());
48 // Osaka-Mono is the only monospace Japanese font on the Mac,
49 // but since it is included as a member of the Osaka family, it cannot
50 // be selected. The code below exceptionally picks out monospace members in
51 // a proportionaly spaced family (or vice versa) to included.
52 BOOL is_family_fixed_point = [font_manager fontNamed:family_name
53 hasTraits:NSFixedPitchFontMask];
54 NSArray* family_members = [font_manager availableMembersOfFontFamily:
55 [family objectForKey:@"name"]];
56 for (NSArray* member in family_members) {
57 NSString* font_name = [member objectAtIndex:0];
58 if (is_family_fixed_point != [font_manager fontNamed:font_name
59 hasTraits:NSFixedPitchFontMask]) {
60 NSFont* font = [NSFont fontWithName:font_name size:0.0];
61 NSString* localized_font_name = [font displayName];
62 AppendNewFontItemToList(font_name,
63 localized_font_name,
64 font_list.get());
65 }
66 }
29 } 67 }
30 return font_list.Pass(); 68 return font_list.Pass();
31 } 69 }
32 70
33 } // namespace content 71 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/font_settings_utils_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698