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 08018cf3478108b6dae458b14d439139daee77b8..0aec9c353a556e2c4345620149211bdc1e3557dc 100644 |
| --- a/content/common/font_list_mac.mm |
| +++ b/content/common/font_list_mac.mm |
| @@ -12,20 +12,54 @@ |
| namespace content { |
| +static void AppendNewFontItemToList(NSString* font_value, |
| + NSString* font_label, ListValue* font_list) { |
| + ListValue* font_item = new ListValue(); |
| + string16 value_string = base::SysNSStringToUTF16(font_value); |
| + font_item->Append(Value::CreateStringValue(value_string)); |
| + string16 label_string = base::SysNSStringToUTF16(font_label); |
| + font_item->Append(Value::CreateStringValue(label_string)); |
| + font_list->Append(font_item); |
| +} |
| + |
| ListValue* GetFontList_SlowBlocking() { |
| base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| ListValue* font_list = new ListValue; |
| - NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; |
| - NSArray* fonts = [fontManager availableFontFamilies]; |
| - for (NSString* family_name in fonts) { |
| - NSString* localized_family_name = |
| - [fontManager localizedNameForFamily:family_name face:nil]; |
| - ListValue* font_item = new ListValue(); |
| - string16 family = base::SysNSStringToUTF16(family_name); |
| - font_item->Append(Value::CreateStringValue(family)); |
| - string16 loc_family = base::SysNSStringToUTF16(localized_family_name); |
| - font_item->Append(Value::CreateStringValue(loc_family)); |
| - font_list->Append(font_item); |
| + NSFontManager* font_manager = [[[NSFontManager alloc] init] autorelease]; |
| + NSArray* family_names = [font_manager availableFontFamilies]; |
| + NSMutableArray* font_families = [NSMutableArray array]; |
| + for (NSString* family_name in family_names) { |
| + NSString* localized_family_name = [font_manager |
| + localizedNameForFamily:family_name face:nil]; |
| + [font_families addObject:[NSDictionary dictionaryWithObjectsAndKeys: |
| + family_name, @"name", localized_family_name, @"localizedName", nil]]; |
| + } |
| + NSSortDescriptor* sort_descriptor = [[NSSortDescriptor alloc] |
| + initWithKey:@"localizedName" ascending:YES]; |
| + [font_families sortUsingDescriptors: |
| + [NSArray arrayWithObject:sort_descriptor]]; |
| + [sort_descriptor release]; |
| + for (NSDictionary* family in font_families) { |
| + NSString* family_name = [family objectForKey:@"name"]; |
| + AppendNewFontItemToList(family_name, [family objectForKey:@"localizedName"], |
| + font_list); |
| + // Osaka-Mono is the only monospace Japanese font on the Mac, |
| + // but since it is included as a member of the Osaka family, it cannot |
| + // be selected. The code below exceptionally picks out monospace members in |
| + // a proportionaly spaced family (or vice versa) to included. |
| + BOOL is_family_fixed_point = [font_manager fontNamed:family_name |
| + hasTraits:NSFixedPitchFontMask]; |
| + NSArray* familyMembers = [font_manager availableMembersOfFontFamily: |
|
csilv
2011/07/06 19:42:51
Nit: change variable name to family_members
|
| + [family objectForKey:@"name"]]; |
| + for (NSArray* member in familyMembers) { |
| + NSString* font_name = [member objectAtIndex:0]; |
| + if (is_family_fixed_point != [font_manager fontNamed:font_name |
| + hasTraits:NSFixedPitchFontMask]) { |
| + NSFont* font = [NSFont fontWithName:font_name size:0.0]; |
| + NSString* localized_font_name = [font displayName]; |
| + AppendNewFontItemToList(font_name, localized_font_name, font_list); |
| + } |
| + } |
| } |
| return font_list; |
| } |