OLD | NEW |
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 if (!font) | 183 if (!font) |
184 return nil; | 184 return nil; |
185 | 185 |
186 NSFontTraitMask actualTraits = 0; | 186 NSFontTraitMask actualTraits = 0; |
187 if (desiredTraits & NSFontItalicTrait) | 187 if (desiredTraits & NSFontItalicTrait) |
188 actualTraits = [fontManager traitsOfFont:font]; | 188 actualTraits = [fontManager traitsOfFont:font]; |
189 int actualWeight = [fontManager weightOfFont:font]; | 189 int actualWeight = [fontManager weightOfFont:font]; |
190 | 190 |
191 bool syntheticBold = desiredWeight >= 7 && actualWeight < 7; | 191 bool syntheticBold = desiredWeight >= 7 && actualWeight < 7; |
192 bool syntheticItalic = (desiredTraits & NSFontItalicTrait) && !(actualTraits
& NSFontItalicTrait); | 192 bool syntheticOblique = (desiredTraits & NSFontItalicTrait) && !(actualTrait
s & NSFontItalicTrait); |
193 | 193 |
194 // There are some malformed fonts that will be correctly returned by -fontWi
thFamily:traits:weight:size: as a match for a particular trait, | 194 // There are some malformed fonts that will be correctly returned by -fontWi
thFamily:traits:weight:size: as a match for a particular trait, |
195 // though -[NSFontManager traitsOfFont:] incorrectly claims the font does no
t have the specified trait. This could result in applying | 195 // though -[NSFontManager traitsOfFont:] incorrectly claims the font does no
t have the specified trait. This could result in applying |
196 // synthetic bold on top of an already-bold font, as reported in <http://bug
s.webkit.org/show_bug.cgi?id=6146>. To work around this | 196 // synthetic bold on top of an already-bold font, as reported in <http://bug
s.webkit.org/show_bug.cgi?id=6146>. To work around this |
197 // 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 | 197 // 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 |
198 // the same family without those traits (to apply the synthetic traits to la
ter). | 198 // the same family without those traits (to apply the synthetic traits to la
ter). |
199 NSFontTraitMask nonSyntheticTraits = desiredTraits; | 199 NSFontTraitMask nonSyntheticTraits = desiredTraits; |
200 | 200 |
201 if (syntheticBold) | 201 if (syntheticBold) |
202 nonSyntheticTraits &= ~NSBoldFontMask; | 202 nonSyntheticTraits &= ~NSBoldFontMask; |
203 | 203 |
204 if (syntheticItalic) | 204 if (syntheticOblique) |
205 nonSyntheticTraits &= ~NSItalicFontMask; | 205 nonSyntheticTraits &= ~NSItalicFontMask; |
206 | 206 |
207 if (nonSyntheticTraits != desiredTraits) { | 207 if (nonSyntheticTraits != desiredTraits) { |
208 NSFont *fontWithoutSyntheticTraits = [fontManager fontWithFamily:availab
leFamily traits:nonSyntheticTraits weight:chosenWeight size:size]; | 208 NSFont *fontWithoutSyntheticTraits = [fontManager fontWithFamily:availab
leFamily traits:nonSyntheticTraits weight:chosenWeight size:size]; |
209 if (fontWithoutSyntheticTraits) | 209 if (fontWithoutSyntheticTraits) |
210 font = fontWithoutSyntheticTraits; | 210 font = fontWithoutSyntheticTraits; |
211 } | 211 } |
212 | 212 |
213 return font; | 213 return font; |
214 } | 214 } |
(...skipping 11 matching lines...) Expand all Loading... |
226 return [self internalFontWithFamily:desiredFamily traits:desiredTraits weigh
t:desiredWeight size:size]; | 226 return [self internalFontWithFamily:desiredFamily traits:desiredTraits weigh
t:desiredWeight size:size]; |
227 } | 227 } |
228 | 228 |
229 + (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)des
iredTraits size:(float)size | 229 + (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)des
iredTraits size:(float)size |
230 { | 230 { |
231 int desiredWeight = (desiredTraits & NSBoldFontMask) ? 9 : 5; | 231 int desiredWeight = (desiredTraits & NSBoldFontMask) ? 9 : 5; |
232 return [self fontWithFamily:desiredFamily traits:desiredTraits weight:desire
dWeight size:size]; | 232 return [self fontWithFamily:desiredFamily traits:desiredTraits weight:desire
dWeight size:size]; |
233 } | 233 } |
234 | 234 |
235 @end | 235 @end |
OLD | NEW |