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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // when running the set of standard non-subpixel layout tests, | 75 // when running the set of standard non-subpixel layout tests, |
76 // otherwise use subpixel glyph positioning. | 76 // otherwise use subpixel glyph positioning. |
77 return (LayoutTestSupport::isRunningLayoutTest() && !LayoutTestSupport::isFo
ntAntialiasingEnabledForTest()); | 77 return (LayoutTestSupport::isRunningLayoutTest() && !LayoutTestSupport::isFo
ntAntialiasingEnabledForTest()); |
78 } | 78 } |
79 | 79 |
80 void FontCache::platformInit() | 80 void FontCache::platformInit() |
81 { | 81 { |
82 CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this,
fontCacheRegisteredFontsChangedNotificationCallback, kCTFontManagerRegisteredFon
tsChangedNotification, 0, CFNotificationSuspensionBehaviorDeliverImmediately); | 82 CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this,
fontCacheRegisteredFontsChangedNotificationCallback, kCTFontManagerRegisteredFon
tsChangedNotification, 0, CFNotificationSuspensionBehaviorDeliverImmediately); |
83 } | 83 } |
84 | 84 |
85 static int toAppKitFontWeight(FontWeight fontWeight) | |
86 { | |
87 static int appKitFontWeights[] = { | |
88 2, // FontWeight100 | |
89 3, // FontWeight200 | |
90 4, // FontWeight300 | |
91 5, // FontWeight400 | |
92 6, // FontWeight500 | |
93 8, // FontWeight600 | |
94 9, // FontWeight700 | |
95 10, // FontWeight800 | |
96 12, // FontWeight900 | |
97 }; | |
98 return appKitFontWeights[fontWeight]; | |
99 } | |
100 | |
101 static inline bool isAppKitFontWeightBold(NSInteger appKitFontWeight) | 85 static inline bool isAppKitFontWeightBold(NSInteger appKitFontWeight) |
102 { | 86 { |
103 return appKitFontWeight >= 7; | 87 return appKitFontWeight >= 7; |
104 } | 88 } |
105 | 89 |
106 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip
tion& fontDescription, UChar32 character, const SimpleFontData* fontDataToSubsti
tute) | 90 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip
tion& fontDescription, UChar32 character, const SimpleFontData* fontDataToSubsti
tute) |
107 { | 91 { |
108 // FIXME: We should fix getFallbackFamily to take a UChar32 | 92 // FIXME: We should fix getFallbackFamily to take a UChar32 |
109 // and remove this split-to-UChar16 code. | 93 // and remove this split-to-UChar16 code. |
110 UChar codeUnits[2]; | 94 UChar codeUnits[2]; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 traits = [fontManager traitsOfFont:nsFont]; | 131 traits = [fontManager traitsOfFont:nsFont]; |
148 if (platformData.m_syntheticBold) | 132 if (platformData.m_syntheticBold) |
149 traits |= NSBoldFontMask; | 133 traits |= NSBoldFontMask; |
150 if (platformData.m_syntheticItalic) | 134 if (platformData.m_syntheticItalic) |
151 traits |= NSFontItalicTrait; | 135 traits |= NSFontItalicTrait; |
152 weight = [fontManager weightOfFont:nsFont]; | 136 weight = [fontManager weightOfFont:nsFont]; |
153 size = [nsFont pointSize]; | 137 size = [nsFont pointSize]; |
154 } else { | 138 } else { |
155 // For custom fonts nsFont is nil. | 139 // For custom fonts nsFont is nil. |
156 traits = fontDescription.style() ? NSFontItalicTrait : 0; | 140 traits = fontDescription.style() ? NSFontItalicTrait : 0; |
157 weight = toAppKitFontWeight(fontDescription.weight()); | 141 weight = ToAppKitFontWeight(fontDescription.weight()); |
158 size = fontDescription.computedPixelSize(); | 142 size = fontDescription.computedPixelSize(); |
159 } | 143 } |
160 | 144 |
161 NSFontTraitMask substituteFontTraits = [fontManager traitsOfFont:substituteF
ont]; | 145 NSFontTraitMask substituteFontTraits = [fontManager traitsOfFont:substituteF
ont]; |
162 NSInteger substituteFontWeight = [fontManager weightOfFont:substituteFont]; | 146 NSInteger substituteFontWeight = [fontManager weightOfFont:substituteFont]; |
163 | 147 |
164 if (traits != substituteFontTraits || weight != substituteFontWeight || !nsF
ont) { | 148 if (traits != substituteFontTraits || weight != substituteFontWeight || !nsF
ont) { |
165 if (NSFont *bestVariation = [fontManager fontWithFamily:[substituteFont
familyName] traits:traits weight:weight size:size]) { | 149 if (NSFont *bestVariation = [fontManager fontWithFamily:[substituteFont
familyName] traits:traits weight:weight size:size]) { |
166 if ((!nsFont || [fontManager traitsOfFont:bestVariation] != substitu
teFontTraits || [fontManager weightOfFont:bestVariation] != substituteFontWeight
) | 150 if ((!nsFont || [fontManager traitsOfFont:bestVariation] != substitu
teFontTraits || [fontManager weightOfFont:bestVariation] != substituteFontWeight
) |
167 && [[bestVariation coveredCharacterSet] longCharacterIsMember:ch
aracter]) | 151 && [[bestVariation coveredCharacterSet] longCharacterIsMember:ch
aracter]) |
(...skipping 28 matching lines...) Expand all Loading... |
196 // the user doesn't have it, we fall back on Lucida Grande because that's | 180 // the user doesn't have it, we fall back on Lucida Grande because that's |
197 // guaranteed to be there, according to Nathan Taylor. This is good enough | 181 // guaranteed to be there, according to Nathan Taylor. This is good enough |
198 // to avoid a crash at least. | 182 // to avoid a crash at least. |
199 DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande", AtomicS
tring::ConstructFromLiteral)); | 183 DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande", AtomicS
tring::ConstructFromLiteral)); |
200 return getFontData(fontDescription, lucidaGrandeStr, false, shouldRetain); | 184 return getFontData(fontDescription, lucidaGrandeStr, false, shouldRetain); |
201 } | 185 } |
202 | 186 |
203 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const FontFaceCreationParams& creationParams, float fontSize) | 187 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const FontFaceCreationParams& creationParams, float fontSize) |
204 { | 188 { |
205 NSFontTraitMask traits = fontDescription.style() ? NSFontItalicTrait : 0; | 189 NSFontTraitMask traits = fontDescription.style() ? NSFontItalicTrait : 0; |
206 NSInteger weight = toAppKitFontWeight(fontDescription.weight()); | |
207 float size = fontSize; | 190 float size = fontSize; |
208 | 191 |
209 NSFont *nsFont = MatchNSFontFamily(creationParams.family(),traits, weight, s
ize); | 192 NSFont* nsFont = MatchNSFontFamily(creationParams.family(), traits, fontDesc
ription.weight(), size); |
210 if (!nsFont) | 193 if (!nsFont) |
211 return 0; | 194 return 0; |
212 | 195 |
213 NSFontManager *fontManager = [NSFontManager sharedFontManager]; | 196 NSFontManager *fontManager = [NSFontManager sharedFontManager]; |
214 NSFontTraitMask actualTraits = 0; | 197 NSFontTraitMask actualTraits = 0; |
215 if (fontDescription.style()) | 198 if (fontDescription.style()) |
216 actualTraits = [fontManager traitsOfFont:nsFont]; | 199 actualTraits = [fontManager traitsOfFont:nsFont]; |
217 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; | 200 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; |
218 | 201 |
219 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF
ont]; | 202 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF
ont]; |
220 bool syntheticBold = (isAppKitFontWeightBold(weight) && !isAppKitFontWeightB
old(actualWeight)) || fontDescription.isSyntheticBold(); | 203 NSInteger appKitWeight = ToAppKitFontWeight(fontDescription.weight()); |
| 204 bool syntheticBold = (isAppKitFontWeightBold(appKitWeight) && !isAppKitFontW
eightBold(actualWeight)) || fontDescription.isSyntheticBold(); |
221 bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSF
ontItalicTrait)) || fontDescription.isSyntheticItalic(); | 205 bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSF
ontItalicTrait)) || fontDescription.isSyntheticItalic(); |
222 | 206 |
223 // FontPlatformData::typeface() is null in the case of Chromium out-of-proce
ss font loading failing. | 207 // FontPlatformData::typeface() is null in the case of Chromium out-of-proce
ss font loading failing. |
224 // Out-of-process loading occurs for registered fonts stored in non-system l
ocations. | 208 // Out-of-process loading occurs for registered fonts stored in non-system l
ocations. |
225 // When loading fails, we do not want to use the returned FontPlatformData s
ince it will not have | 209 // When loading fails, we do not want to use the returned FontPlatformData s
ince it will not have |
226 // a valid SkTypeface. | 210 // a valid SkTypeface. |
227 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo
rmFont, size, syntheticBold, syntheticItalic, fontDescription.orientation())); | 211 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo
rmFont, size, syntheticBold, syntheticItalic, fontDescription.orientation())); |
228 if (!platformData->typeface()) { | 212 if (!platformData->typeface()) { |
229 return nullptr; | 213 return nullptr; |
230 } | 214 } |
231 return platformData.leakPtr(); | 215 return platformData.leakPtr(); |
232 } | 216 } |
233 | 217 |
234 } // namespace blink | 218 } // namespace blink |
OLD | NEW |