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..3ed70b1d730a155662f9eaa105e6e045a400f742 100644 |
| --- a/content/common/font_list_mac.mm |
| +++ b/content/common/font_list_mac.mm |
| @@ -16,16 +16,50 @@ 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]; |
| + NSArray* familyNames = [fontManager availableFontFamilies]; |
| + NSMutableArray* fontFamilies = [NSMutableArray array]; |
| + for (NSString* familyName in familyNames) { |
| + NSString* localizedFamilyName = [fontManager |
| + localizedNameForFamily:familyName face:nil]; |
| + [fontFamilies addObject:[NSDictionary dictionaryWithObjectsAndKeys: |
| + familyName, @"name", localizedFamilyName, @"localizedName", nil]]; |
| + } |
| + NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc] |
| + initWithKey:@"localizedName" ascending:YES]; |
|
csilv
2011/06/24 20:51:30
indent line continuations 4 space, here and below.
|
| + [fontFamilies sortUsingDescriptors: |
| + [NSArray arrayWithObject: sortDescriptor]]; |
|
csilv
2011/06/24 20:51:30
eliminate space after colon
|
| + [sortDescriptor release]; |
| + for (NSDictionary* family in fontFamilies) { |
| + NSString* familyName = [family objectForKey:@"name"]; |
| 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)); |
| + string16 font_value = base::SysNSStringToUTF16(familyName); |
| + font_item->Append(Value::CreateStringValue(font_value)); |
| + string16 font_label = base::SysNSStringToUTF16( |
| + [family objectForKey:@"localizedName"]); |
| + font_item->Append(Value::CreateStringValue(font_label)); |
| font_list->Append(font_item); |
| + // 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 isFamilyFixedPoint = [fontManager fontNamed:familyName |
| + hasTraits:NSFixedPitchFontMask]; |
| + NSArray* familyMembers = [fontManager availableMembersOfFontFamily: |
| + [family objectForKey:@"name"]]; |
| + for (NSArray* member in familyMembers) { |
| + NSString* fontName = [member objectAtIndex:0]; |
| + if (isFamilyFixedPoint != [fontManager fontNamed:fontName |
|
brettw
2011/06/24 20:56:26
Is there some way this function can be made more c
|
| + hasTraits:NSFixedPitchFontMask]) { |
| + NSFont* font = [NSFont fontWithName:fontName size:0.0]; |
| + NSString* localizedFontName = [font displayName]; |
| + ListValue* font_item = new ListValue(); |
| + string16 font_value = base::SysNSStringToUTF16(fontName); |
| + font_item->Append(Value::CreateStringValue(font_value)); |
| + string16 font_label = base::SysNSStringToUTF16(localizedFontName); |
| + font_item->Append(Value::CreateStringValue(font_label)); |
| + font_list->Append(font_item); |
| + } |
| + } |
| } |
| return font_list; |
| } |