Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/sys_string_conversions.h" | 10 #include "base/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 ListValue* GetFontList_SlowBlocking() { | 15 ListValue* GetFontList_SlowBlocking() { |
| 16 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 16 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 17 ListValue* font_list = new ListValue; | 17 ListValue* font_list = new ListValue; |
| 18 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; | 18 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; |
| 19 NSArray* fonts = [fontManager availableFontFamilies]; | 19 NSArray* familyNames = [fontManager availableFontFamilies]; |
| 20 for (NSString* family_name in fonts) { | 20 NSMutableArray* fontFamilies = [NSMutableArray array]; |
| 21 NSString* localized_family_name = | 21 for (NSString* familyName in familyNames) { |
| 22 [fontManager localizedNameForFamily:family_name face:nil]; | 22 NSString* localizedFamilyName = [fontManager |
| 23 localizedNameForFamily:familyName face:nil]; | |
| 24 [fontFamilies addObject:[NSDictionary dictionaryWithObjectsAndKeys: | |
| 25 familyName, @"name", localizedFamilyName, @"localizedName", nil]]; | |
| 26 } | |
| 27 NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc] | |
| 28 initWithKey:@"localizedName" ascending:YES]; | |
|
csilv
2011/06/24 20:51:30
indent line continuations 4 space, here and below.
| |
| 29 [fontFamilies sortUsingDescriptors: | |
| 30 [NSArray arrayWithObject: sortDescriptor]]; | |
|
csilv
2011/06/24 20:51:30
eliminate space after colon
| |
| 31 [sortDescriptor release]; | |
| 32 for (NSDictionary* family in fontFamilies) { | |
| 33 NSString* familyName = [family objectForKey:@"name"]; | |
| 23 ListValue* font_item = new ListValue(); | 34 ListValue* font_item = new ListValue(); |
| 24 string16 family = base::SysNSStringToUTF16(family_name); | 35 string16 font_value = base::SysNSStringToUTF16(familyName); |
| 25 font_item->Append(Value::CreateStringValue(family)); | 36 font_item->Append(Value::CreateStringValue(font_value)); |
| 26 string16 loc_family = base::SysNSStringToUTF16(localized_family_name); | 37 string16 font_label = base::SysNSStringToUTF16( |
| 27 font_item->Append(Value::CreateStringValue(loc_family)); | 38 [family objectForKey:@"localizedName"]); |
| 39 font_item->Append(Value::CreateStringValue(font_label)); | |
| 28 font_list->Append(font_item); | 40 font_list->Append(font_item); |
| 41 // Osaka-Mono is the only monospace Japanese font on the Mac, | |
| 42 // but since it is included as a member of the Osaka family, it cannot | |
| 43 // be selected. The code below exceptionally picks out monospace members in | |
| 44 // a proportionaly spaced family (or vice versa) to included. | |
| 45 BOOL isFamilyFixedPoint = [fontManager fontNamed:familyName | |
| 46 hasTraits:NSFixedPitchFontMask]; | |
| 47 NSArray* familyMembers = [fontManager availableMembersOfFontFamily: | |
| 48 [family objectForKey:@"name"]]; | |
| 49 for (NSArray* member in familyMembers) { | |
| 50 NSString* fontName = [member objectAtIndex:0]; | |
| 51 if (isFamilyFixedPoint != [fontManager fontNamed:fontName | |
|
brettw
2011/06/24 20:56:26
Is there some way this function can be made more c
| |
| 52 hasTraits:NSFixedPitchFontMask]) { | |
| 53 NSFont* font = [NSFont fontWithName:fontName size:0.0]; | |
| 54 NSString* localizedFontName = [font displayName]; | |
| 55 ListValue* font_item = new ListValue(); | |
| 56 string16 font_value = base::SysNSStringToUTF16(fontName); | |
| 57 font_item->Append(Value::CreateStringValue(font_value)); | |
| 58 string16 font_label = base::SysNSStringToUTF16(localizedFontName); | |
| 59 font_item->Append(Value::CreateStringValue(font_label)); | |
| 60 font_list->Append(font_item); | |
| 61 } | |
| 62 } | |
| 29 } | 63 } |
| 30 return font_list; | 64 return font_list; |
| 31 } | 65 } |
| 32 | 66 |
| 33 } // namespace content | 67 } // namespace content |
| OLD | NEW |