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

Unified Diff: content/common/font_list_mac.mm

Issue 7204026: Changed fontlist to list all avalilable fonts. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fixed patch Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/options/font_settings_utils_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
+ [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;
}
« 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