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

Unified 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 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 4ffb3de1804cb39bb6fe3b21989a258fc809d8ee..7dc70f33410a91f93ae149e188639e576d5ad4cf 100644
--- a/content/common/font_list_mac.mm
+++ b/content/common/font_list_mac.mm
@@ -12,20 +12,58 @@
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);
+}
+
scoped_ptr<base::ListValue> GetFontList_SlowBlocking() {
base::mac::ScopedNSAutoreleasePool autorelease_pool;
scoped_ptr<base::ListValue> font_list(new base::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];
- base::ListValue* font_item = new base::ListValue();
- string16 family = base::SysNSStringToUTF16(family_name);
- font_item->Append(new base::StringValue(family));
- string16 loc_family = base::SysNSStringToUTF16(localized_family_name);
- font_item->Append(new base::StringValue(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.get());
+ // 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* family_members = [font_manager availableMembersOfFontFamily:
+ [family objectForKey:@"name"]];
+ for (NSArray* member in family_members) {
+ 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.get());
+ }
+ }
}
return font_list.Pass();
}
« 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