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

Side by Side Diff: Source/WebCore/platform/mac/WebFontCache.mm

Issue 13905007: Remove the last remaining PLATFORM() bits from WebCore. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int candidateWeightDeltaMagnitude = abs(candidateWeight - desiredWeight); 94 int candidateWeightDeltaMagnitude = abs(candidateWeight - desiredWeight);
95 95
96 // If both are the same distance from the desired weight, prefer the candida te if it is further from medium. 96 // If both are the same distance from the desired weight, prefer the candida te if it is further from medium.
97 if (chosenWeightDeltaMagnitude == candidateWeightDeltaMagnitude) 97 if (chosenWeightDeltaMagnitude == candidateWeightDeltaMagnitude)
98 return abs(candidateWeight - 6) > abs(chosenWeight - 6); 98 return abs(candidateWeight - 6) > abs(chosenWeight - 6);
99 99
100 // Otherwise, prefer the one closer to the desired weight. 100 // Otherwise, prefer the one closer to the desired weight.
101 return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude; 101 return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude;
102 } 102 }
103 103
104 // Workaround for <rdar://problem/5781372>.
105 static inline void fixUpWeight(NSInteger& weight, NSString *fontName)
106 {
107 #if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
108 UNUSED_PARAM(weight);
109 UNUSED_PARAM(fontName);
110 #else
111 if (weight == 3 && [fontName rangeOfString:@"ultralight" options:NSCaseInsen sitiveSearch | NSBackwardsSearch | NSLiteralSearch].location != NSNotFound)
112 weight = 2;
113 #endif
114 }
115
116 static inline FontTraitsMask toTraitsMask(NSFontTraitMask appKitTraits, NSIntege r appKitWeight) 104 static inline FontTraitsMask toTraitsMask(NSFontTraitMask appKitTraits, NSIntege r appKitWeight)
117 { 105 {
118 return static_cast<FontTraitsMask>(((appKitTraits & NSFontItalicTrait) ? Fon tStyleItalicMask : FontStyleNormalMask) 106 return static_cast<FontTraitsMask>(((appKitTraits & NSFontItalicTrait) ? Fon tStyleItalicMask : FontStyleNormalMask)
119 | FontVariantNormalMask 107 | FontVariantNormalMask
120 | (appKitWeight == 1 ? FontWeight100Mask : 108 | (appKitWeight == 1 ? FontWeight100Mask :
121 appKitWeight == 2 ? FontWeight200Mask : 109 appKitWeight == 2 ? FontWeight200Mask :
122 appKitWeight <= 4 ? FontWeight300Mask : 110 appKitWeight <= 4 ? FontWeight300Mask :
123 appKitWeight == 5 ? FontWeight400Mask : 111 appKitWeight == 5 ? FontWeight400Mask :
124 appKitWeight == 6 ? FontWeight500Mask : 112 appKitWeight == 6 ? FontWeight500Mask :
125 appKitWeight <= 8 ? FontWeight600Mask : 113 appKitWeight <= 8 ? FontWeight600Mask :
(...skipping 16 matching lines...) Expand all
142 } 130 }
143 131
144 if (!availableFamily) { 132 if (!availableFamily) {
145 // Match by PostScript name. 133 // Match by PostScript name.
146 NSEnumerator *availableFonts = [[fontManager availableFonts] objectEnume rator]; 134 NSEnumerator *availableFonts = [[fontManager availableFonts] objectEnume rator];
147 NSString *availableFont; 135 NSString *availableFont;
148 while ((availableFont = [availableFonts nextObject])) { 136 while ((availableFont = [availableFonts nextObject])) {
149 if ([desiredFamily caseInsensitiveCompare:availableFont] == NSOrdere dSame) { 137 if ([desiredFamily caseInsensitiveCompare:availableFont] == NSOrdere dSame) {
150 NSFont *font = [NSFont fontWithName:availableFont size:10]; 138 NSFont *font = [NSFont fontWithName:availableFont size:10];
151 NSInteger weight = [fontManager weightOfFont:font]; 139 NSInteger weight = [fontManager weightOfFont:font];
152 fixUpWeight(weight, desiredFamily);
153 traitsMasks.append(toTraitsMask([fontManager traitsOfFont:font], weight)); 140 traitsMasks.append(toTraitsMask([fontManager traitsOfFont:font], weight));
154 break; 141 break;
155 } 142 }
156 } 143 }
157 return; 144 return;
158 } 145 }
159 146
160 NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily]; 147 NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];
161 unsigned n = [fonts count]; 148 unsigned n = [fonts count];
162 unsigned i; 149 unsigned i;
163 for (i = 0; i < n; i++) { 150 for (i = 0; i < n; i++) {
164 NSArray *fontInfo = [fonts objectAtIndex:i]; 151 NSArray *fontInfo = [fonts objectAtIndex:i];
165 // Array indices must be hard coded because of lame AppKit API. 152 // Array indices must be hard coded because of lame AppKit API.
166 NSString *fontFullName = [fontInfo objectAtIndex:0]; 153 NSString *fontFullName = [fontInfo objectAtIndex:0];
167 NSInteger fontWeight = [[fontInfo objectAtIndex:2] intValue]; 154 NSInteger fontWeight = [[fontInfo objectAtIndex:2] intValue];
168 fixUpWeight(fontWeight, fontFullName);
169 155
170 NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValu e]; 156 NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValu e];
171 traitsMasks.append(toTraitsMask(fontTraits, fontWeight)); 157 traitsMasks.append(toTraitsMask(fontTraits, fontWeight));
172 } 158 }
173 } 159 }
174 160
175 // Family name is somewhat of a misnomer here. We first attempt to find an exac t match 161 // Family name is somewhat of a misnomer here. We first attempt to find an exac t match
176 // comparing the desiredFamily to the PostScript name of the installed fonts. I f that fails 162 // comparing the desiredFamily to the PostScript name of the installed fonts. I f that fails
177 // we then do a search based on the family names of the installed fonts. 163 // we then do a search based on the family names of the installed fonts.
178 + (NSFont *)internalFontWithFamily:(NSString *)desiredFamily traits:(NSFontTrait Mask)desiredTraits weight:(int)desiredWeight size:(float)size 164 + (NSFont *)internalFontWithFamily:(NSString *)desiredFamily traits:(NSFontTrait Mask)desiredTraits weight:(int)desiredWeight size:(float)size
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 208
223 NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily]; 209 NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];
224 unsigned n = [fonts count]; 210 unsigned n = [fonts count];
225 unsigned i; 211 unsigned i;
226 for (i = 0; i < n; i++) { 212 for (i = 0; i < n; i++) {
227 NSArray *fontInfo = [fonts objectAtIndex:i]; 213 NSArray *fontInfo = [fonts objectAtIndex:i];
228 214
229 // Array indices must be hard coded because of lame AppKit API. 215 // Array indices must be hard coded because of lame AppKit API.
230 NSString *fontFullName = [fontInfo objectAtIndex:0]; 216 NSString *fontFullName = [fontInfo objectAtIndex:0];
231 NSInteger fontWeight = [[fontInfo objectAtIndex:2] intValue]; 217 NSInteger fontWeight = [[fontInfo objectAtIndex:2] intValue];
232 fixUpWeight(fontWeight, fontFullName);
233 218
234 NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValu e]; 219 NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValu e];
235 220
236 BOOL newWinner; 221 BOOL newWinner;
237 if (!choseFont) 222 if (!choseFont)
238 newWinner = acceptableChoice(desiredTraits, fontTraits); 223 newWinner = acceptableChoice(desiredTraits, fontTraits);
239 else 224 else
240 newWinner = betterChoice(desiredTraits, desiredWeight, chosenTraits, chosenWeight, fontTraits, fontWeight); 225 newWinner = betterChoice(desiredTraits, desiredWeight, chosenTraits, chosenWeight, fontTraits, fontWeight);
241 226
242 if (newWinner) { 227 if (newWinner) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 return [self internalFontWithFamily:desiredFamily traits:desiredTraits weigh t:desiredWeight size:size]; 286 return [self internalFontWithFamily:desiredFamily traits:desiredTraits weigh t:desiredWeight size:size];
302 } 287 }
303 288
304 + (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)des iredTraits size:(float)size 289 + (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)des iredTraits size:(float)size
305 { 290 {
306 int desiredWeight = (desiredTraits & NSBoldFontMask) ? 9 : 5; 291 int desiredWeight = (desiredTraits & NSBoldFontMask) ? 9 : 5;
307 return [self fontWithFamily:desiredFamily traits:desiredTraits weight:desire dWeight size:size]; 292 return [self fontWithFamily:desiredFamily traits:desiredTraits weight:desire dWeight size:size];
308 } 293 }
309 294
310 @end 295 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698