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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/mac/FontFamilyMatcherMac.mm

Issue 2386333002: reflow comments in platform/fonts (Closed)
Patch Set: comments Created 4 years, 2 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
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 BOOL candidateHasUnwantedTrait = desired != ((candidateTraits & mask) != 0); 105 BOOL candidateHasUnwantedTrait = desired != ((candidateTraits & mask) != 0);
106 if (!candidateHasUnwantedTrait && chosenHasUnwantedTrait) 106 if (!candidateHasUnwantedTrait && chosenHasUnwantedTrait)
107 return YES; 107 return YES;
108 if (!chosenHasUnwantedTrait && candidateHasUnwantedTrait) 108 if (!chosenHasUnwantedTrait && candidateHasUnwantedTrait)
109 return NO; 109 return NO;
110 } 110 }
111 111
112 int chosenWeightDeltaMagnitude = abs(chosenWeight - desiredWeight); 112 int chosenWeightDeltaMagnitude = abs(chosenWeight - desiredWeight);
113 int candidateWeightDeltaMagnitude = abs(candidateWeight - desiredWeight); 113 int candidateWeightDeltaMagnitude = abs(candidateWeight - desiredWeight);
114 114
115 // If both are the same distance from the desired weight, prefer the candidate if it is further from medium. 115 // If both are the same distance from the desired weight, prefer the candidate
116 // if it is further from medium.
116 if (chosenWeightDeltaMagnitude == candidateWeightDeltaMagnitude) 117 if (chosenWeightDeltaMagnitude == candidateWeightDeltaMagnitude)
117 return abs(candidateWeight - 6) > abs(chosenWeight - 6); 118 return abs(candidateWeight - 6) > abs(chosenWeight - 6);
118 119
119 // Otherwise, prefer the one closer to the desired weight. 120 // Otherwise, prefer the one closer to the desired weight.
120 return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude; 121 return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude;
121 } 122 }
122 123
123 // Family name is somewhat of a misnomer here. We first attempt to find an exac t match 124 // Family name is somewhat of a misnomer here. We first attempt to find an
124 // comparing the desiredFamily to the PostScript name of the installed fonts. I f that fails 125 // exact match comparing the desiredFamily to the PostScript name of the
125 // we then do a search based on the family names of the installed fonts. 126 // installed fonts. If that fails we then do a search based on the family
127 // names of the installed fonts.
126 NSFont* MatchNSFontFamily(NSString* desiredFamily, 128 NSFont* MatchNSFontFamily(NSString* desiredFamily,
127 NSFontTraitMask desiredTraits, 129 NSFontTraitMask desiredTraits,
128 FontWeight desiredWeight, 130 FontWeight desiredWeight,
129 float size) { 131 float size) {
130 if ([desiredFamily isEqualToString:@"BlinkMacSystemFont"]) { 132 if ([desiredFamily isEqualToString:@"BlinkMacSystemFont"]) {
131 // On OSX 10.9, the default system font depends on the SDK version. When 133 // On OSX 10.9, the default system font depends on the SDK version. When
132 // compiled against the OSX 10.10 SDK, the font is .LucidaGrandeUI. When 134 // compiled against the OSX 10.10 SDK, the font is .LucidaGrandeUI. When
133 // compiled against the OSX 10.6 SDK, the font is Lucida Grande. Layout 135 // compiled against the OSX 10.6 SDK, the font is Lucida Grande. Layout
134 // tests don't support different expectations based on the SDK version, 136 // tests don't support different expectations based on the SDK version,
135 // so force layout tests to use "Lucida Grande". Once the 10.10 SDK 137 // so force layout tests to use "Lucida Grande". Once the 10.10 SDK
(...skipping 22 matching lines...) Expand all
158 if (desiredTraits & IMPORTANT_FONT_TRAITS) 160 if (desiredTraits & IMPORTANT_FONT_TRAITS)
159 font = [[NSFontManager sharedFontManager] convertFont:font 161 font = [[NSFontManager sharedFontManager] convertFont:font
160 toHaveTrait:desiredTraits]; 162 toHaveTrait:desiredTraits];
161 return font; 163 return font;
162 } 164 }
163 165
164 NSFontManager* fontManager = [NSFontManager sharedFontManager]; 166 NSFontManager* fontManager = [NSFontManager sharedFontManager];
165 167
166 // Do a simple case insensitive search for a matching font family. 168 // Do a simple case insensitive search for a matching font family.
167 // NSFontManager requires exact name matches. 169 // NSFontManager requires exact name matches.
168 // This addresses the problem of matching arial to Arial, etc., but perhaps no t all the issues. 170 // This addresses the problem of matching arial to Arial, etc., but perhaps
171 // not all the issues.
169 NSEnumerator* e = [[fontManager availableFontFamilies] objectEnumerator]; 172 NSEnumerator* e = [[fontManager availableFontFamilies] objectEnumerator];
170 NSString* availableFamily; 173 NSString* availableFamily;
171 while ((availableFamily = [e nextObject])) { 174 while ((availableFamily = [e nextObject])) {
172 if ([desiredFamily caseInsensitiveCompare:availableFamily] == NSOrderedSame) 175 if ([desiredFamily caseInsensitiveCompare:availableFamily] == NSOrderedSame)
173 break; 176 break;
174 } 177 }
175 178
176 int appKitFontWeight = toAppKitFontWeight(desiredWeight); 179 int appKitFontWeight = toAppKitFontWeight(desiredWeight);
177 if (!availableFamily) { 180 if (!availableFamily) {
178 // Match by PostScript name. 181 // Match by PostScript name.
179 NSEnumerator* availableFonts = 182 NSEnumerator* availableFonts =
180 [[fontManager availableFonts] objectEnumerator]; 183 [[fontManager availableFonts] objectEnumerator];
181 NSString* availableFont; 184 NSString* availableFont;
182 NSFont* nameMatchedFont = nil; 185 NSFont* nameMatchedFont = nil;
183 NSFontTraitMask desiredTraitsForNameMatch = 186 NSFontTraitMask desiredTraitsForNameMatch =
184 desiredTraits | (appKitFontWeight >= 7 ? NSBoldFontMask : 0); 187 desiredTraits | (appKitFontWeight >= 7 ? NSBoldFontMask : 0);
185 while ((availableFont = [availableFonts nextObject])) { 188 while ((availableFont = [availableFonts nextObject])) {
186 if ([desiredFamily caseInsensitiveCompare:availableFont] == 189 if ([desiredFamily caseInsensitiveCompare:availableFont] ==
187 NSOrderedSame) { 190 NSOrderedSame) {
188 nameMatchedFont = [NSFont fontWithName:availableFont size:size]; 191 nameMatchedFont = [NSFont fontWithName:availableFont size:size];
189 192
190 // Special case Osaka-Mono. According to <rdar://problem/3999467>, we n eed to 193 // Special case Osaka-Mono. According to <rdar://problem/3999467>, we
191 // treat Osaka-Mono as fixed pitch. 194 // need to treat Osaka-Mono as fixed pitch.
192 if ([desiredFamily caseInsensitiveCompare:@"Osaka-Mono"] == 195 if ([desiredFamily caseInsensitiveCompare:@"Osaka-Mono"] ==
193 NSOrderedSame && 196 NSOrderedSame &&
194 desiredTraitsForNameMatch == 0) 197 desiredTraitsForNameMatch == 0)
195 return nameMatchedFont; 198 return nameMatchedFont;
196 199
197 NSFontTraitMask traits = [fontManager traitsOfFont:nameMatchedFont]; 200 NSFontTraitMask traits = [fontManager traitsOfFont:nameMatchedFont];
198 if ((traits & desiredTraitsForNameMatch) == desiredTraitsForNameMatch) 201 if ((traits & desiredTraitsForNameMatch) == desiredTraitsForNameMatch)
199 return [fontManager convertFont:nameMatchedFont 202 return [fontManager convertFont:nameMatchedFont
200 toHaveTrait:desiredTraitsForNameMatch]; 203 toHaveTrait:desiredTraitsForNameMatch];
201 204
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 256
254 NSFontTraitMask actualTraits = 0; 257 NSFontTraitMask actualTraits = 0;
255 if (desiredTraits & NSFontItalicTrait) 258 if (desiredTraits & NSFontItalicTrait)
256 actualTraits = [fontManager traitsOfFont:font]; 259 actualTraits = [fontManager traitsOfFont:font];
257 int actualWeight = [fontManager weightOfFont:font]; 260 int actualWeight = [fontManager weightOfFont:font];
258 261
259 bool syntheticBold = appKitFontWeight >= 7 && actualWeight < 7; 262 bool syntheticBold = appKitFontWeight >= 7 && actualWeight < 7;
260 bool syntheticItalic = (desiredTraits & NSFontItalicTrait) && 263 bool syntheticItalic = (desiredTraits & NSFontItalicTrait) &&
261 !(actualTraits & NSFontItalicTrait); 264 !(actualTraits & NSFontItalicTrait);
262 265
263 // There are some malformed fonts that will be correctly returned by -fontWith Family:traits:weight:size: as a match for a particular trait, 266 // There are some malformed fonts that will be correctly returned by
264 // though -[NSFontManager traitsOfFont:] incorrectly claims the font does not have the specified trait. This could result in applying 267 // -fontWithFamily:traits:weight:size: as a match for a particular trait,
265 // synthetic bold on top of an already-bold font, as reported in <http://bugs. webkit.org/show_bug.cgi?id=6146>. To work around this 268 // though -[NSFontManager traitsOfFont:] incorrectly claims the font does not
266 // problem, if we got an apparent exact match, but the requested traits aren't present in the matched font, we'll try to get a font from 269 // have the specified trait. This could result in applying
267 // the same family without those traits (to apply the synthetic traits to late r). 270 // synthetic bold on top of an already-bold font, as reported in
271 // <http://bugs.webkit.org/show_bug.cgi?id=6146>. To work around this
272 // problem, if we got an apparent exact match, but the requested traits
273 // aren't present in the matched font, we'll try to get a font from the same
274 // family without those traits (to apply the synthetic traits to later).
268 NSFontTraitMask nonSyntheticTraits = desiredTraits; 275 NSFontTraitMask nonSyntheticTraits = desiredTraits;
269 276
270 if (syntheticBold) 277 if (syntheticBold)
271 nonSyntheticTraits &= ~NSBoldFontMask; 278 nonSyntheticTraits &= ~NSBoldFontMask;
272 279
273 if (syntheticItalic) 280 if (syntheticItalic)
274 nonSyntheticTraits &= ~NSItalicFontMask; 281 nonSyntheticTraits &= ~NSItalicFontMask;
275 282
276 if (nonSyntheticTraits != desiredTraits) { 283 if (nonSyntheticTraits != desiredTraits) {
277 NSFont* fontWithoutSyntheticTraits = 284 NSFont* fontWithoutSyntheticTraits =
(...skipping 17 matching lines...) Expand all
295 6, // FontWeight500 302 6, // FontWeight500
296 8, // FontWeight600 303 8, // FontWeight600
297 9, // FontWeight700 304 9, // FontWeight700
298 10, // FontWeight800 305 10, // FontWeight800
299 12, // FontWeight900 306 12, // FontWeight900
300 }; 307 };
301 return appKitFontWeights[fontWeight]; 308 return appKitFontWeights[fontWeight];
302 } 309 }
303 310
304 } // namespace blink 311 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698