| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 inLanguage:nil]; | 139 inLanguage:nil]; |
| 140 [string release]; | 140 [string release]; |
| 141 | 141 |
| 142 // FIXME: Remove this SPI usage: http://crbug.com/255122 | 142 // FIXME: Remove this SPI usage: http://crbug.com/255122 |
| 143 if (!substituteFont && codeUnitsLength == 1) | 143 if (!substituteFont && codeUnitsLength == 1) |
| 144 substituteFont = | 144 substituteFont = |
| 145 [NSFont findFontLike:nsFont forCharacter:codeUnits[0] inLanguage:nil]; | 145 [NSFont findFontLike:nsFont forCharacter:codeUnits[0] inLanguage:nil]; |
| 146 if (!substituteFont) | 146 if (!substituteFont) |
| 147 return nullptr; | 147 return nullptr; |
| 148 | 148 |
| 149 // Use the family name from the AppKit-supplied substitute font, requesting th
e | 149 // Use the family name from the AppKit-supplied substitute font, requesting |
| 150 // traits, weight, and size we want. One way this does better than the origina
l | 150 // the traits, weight, and size we want. One way this does better than the |
| 151 // AppKit request is that it takes synthetic bold and oblique into account. | 151 // original AppKit request is that it takes synthetic bold and oblique into |
| 152 // But it does create the possibility that we could end up with a font that | 152 // account. But it does create the possibility that we could end up with a |
| 153 // doesn't actually cover the characters we need. | 153 // font that doesn't actually cover the characters we need. |
| 154 | 154 |
| 155 NSFontManager* fontManager = [NSFontManager sharedFontManager]; | 155 NSFontManager* fontManager = [NSFontManager sharedFontManager]; |
| 156 | 156 |
| 157 NSFontTraitMask traits; | 157 NSFontTraitMask traits; |
| 158 NSInteger weight; | 158 NSInteger weight; |
| 159 CGFloat size; | 159 CGFloat size; |
| 160 | 160 |
| 161 if (nsFont) { | 161 if (nsFont) { |
| 162 traits = [fontManager traitsOfFont:nsFont]; | 162 traits = [fontManager traitsOfFont:nsFont]; |
| 163 if (platformData.m_syntheticBold) | 163 if (platformData.m_syntheticBold) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 191 substituteFont = bestVariation; | 191 substituteFont = bestVariation; |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 substituteFont = | 195 substituteFont = |
| 196 useHinting() ? [substituteFont screenFont] : [substituteFont printerFont]; | 196 useHinting() ? [substituteFont screenFont] : [substituteFont printerFont]; |
| 197 | 197 |
| 198 substituteFontTraits = [fontManager traitsOfFont:substituteFont]; | 198 substituteFontTraits = [fontManager traitsOfFont:substituteFont]; |
| 199 substituteFontWeight = [fontManager weightOfFont:substituteFont]; | 199 substituteFontWeight = [fontManager weightOfFont:substituteFont]; |
| 200 | 200 |
| 201 // TODO(eae): Remove once skia supports bold emoji. See https://bugs.chromium.
org/p/skia/issues/detail?id=4904 | 201 // TODO(eae): Remove once skia supports bold emoji. See |
| 202 // https://bugs.chromium.org/p/skia/issues/detail?id=4904 |
| 202 // Bold emoji look the same as normal emoji, so syntheticBold isn't needed. | 203 // Bold emoji look the same as normal emoji, so syntheticBold isn't needed. |
| 203 bool syntheticBold = | 204 bool syntheticBold = |
| 204 isAppKitFontWeightBold(weight) && | 205 isAppKitFontWeightBold(weight) && |
| 205 !isAppKitFontWeightBold(substituteFontWeight) && | 206 !isAppKitFontWeightBold(substituteFontWeight) && |
| 206 ![substituteFont.familyName isEqual:@"Apple Color Emoji"]; | 207 ![substituteFont.familyName isEqual:@"Apple Color Emoji"]; |
| 207 | 208 |
| 208 FontPlatformData alternateFont( | 209 FontPlatformData alternateFont( |
| 209 substituteFont, platformData.size(), syntheticBold, | 210 substituteFont, platformData.size(), syntheticBold, |
| 210 (traits & NSFontItalicTrait) && | 211 (traits & NSFontItalicTrait) && |
| 211 !(substituteFontTraits & NSFontItalicTrait), | 212 !(substituteFontTraits & NSFontItalicTrait), |
| 212 platformData.orientation()); | 213 platformData.orientation()); |
| 213 | 214 |
| 214 return fontDataFromFontPlatformData(&alternateFont, DoNotRetain); | 215 return fontDataFromFontPlatformData(&alternateFont, DoNotRetain); |
| 215 } | 216 } |
| 216 | 217 |
| 217 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont( | 218 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont( |
| 218 const FontDescription& fontDescription, | 219 const FontDescription& fontDescription, |
| 219 ShouldRetain shouldRetain) { | 220 ShouldRetain shouldRetain) { |
| 220 DEFINE_STATIC_LOCAL(AtomicString, timesStr, ("Times")); | 221 DEFINE_STATIC_LOCAL(AtomicString, timesStr, ("Times")); |
| 221 | 222 |
| 222 // FIXME: Would be even better to somehow get the user's default font here. F
or now we'll pick | 223 // FIXME: Would be even better to somehow get the user's default font here. |
| 223 // the default that the user would get without changing any prefs. | 224 // For now we'll pick the default that the user would get without changing |
| 225 // any prefs. |
| 224 RefPtr<SimpleFontData> simpleFontData = | 226 RefPtr<SimpleFontData> simpleFontData = |
| 225 getFontData(fontDescription, timesStr, false, shouldRetain); | 227 getFontData(fontDescription, timesStr, false, shouldRetain); |
| 226 if (simpleFontData) | 228 if (simpleFontData) |
| 227 return simpleFontData.release(); | 229 return simpleFontData.release(); |
| 228 | 230 |
| 229 // The Times fallback will almost always work, but in the highly unusual case
where | 231 // The Times fallback will almost always work, but in the highly unusual case |
| 230 // the user doesn't have it, we fall back on Lucida Grande because that's | 232 // where the user doesn't have it, we fall back on Lucida Grande because |
| 231 // guaranteed to be there, according to Nathan Taylor. This is good enough | 233 // that's guaranteed to be there, according to Nathan Taylor. This is good |
| 232 // to avoid a crash at least. | 234 // enough to avoid a crash at least. |
| 233 DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande")); | 235 DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande")); |
| 234 return getFontData(fontDescription, lucidaGrandeStr, false, shouldRetain); | 236 return getFontData(fontDescription, lucidaGrandeStr, false, shouldRetain); |
| 235 } | 237 } |
| 236 | 238 |
| 237 std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData( | 239 std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData( |
| 238 const FontDescription& fontDescription, | 240 const FontDescription& fontDescription, |
| 239 const FontFaceCreationParams& creationParams, | 241 const FontFaceCreationParams& creationParams, |
| 240 float fontSize) { | 242 float fontSize) { |
| 241 NSFontTraitMask traits = fontDescription.style() ? NSFontItalicTrait : 0; | 243 NSFontTraitMask traits = fontDescription.style() ? NSFontItalicTrait : 0; |
| 242 float size = fontSize; | 244 float size = fontSize; |
| 243 | 245 |
| 244 NSFont* nsFont = MatchNSFontFamily(creationParams.family(), traits, | 246 NSFont* nsFont = MatchNSFontFamily(creationParams.family(), traits, |
| 245 fontDescription.weight(), size); | 247 fontDescription.weight(), size); |
| 246 if (!nsFont) | 248 if (!nsFont) |
| 247 return nullptr; | 249 return nullptr; |
| 248 | 250 |
| 249 NSFontManager* fontManager = [NSFontManager sharedFontManager]; | 251 NSFontManager* fontManager = [NSFontManager sharedFontManager]; |
| 250 NSFontTraitMask actualTraits = 0; | 252 NSFontTraitMask actualTraits = 0; |
| 251 if (fontDescription.style()) | 253 if (fontDescription.style()) |
| 252 actualTraits = [fontManager traitsOfFont:nsFont]; | 254 actualTraits = [fontManager traitsOfFont:nsFont]; |
| 253 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; | 255 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; |
| 254 | 256 |
| 255 NSFont* platformFont = | 257 NSFont* platformFont = |
| 256 useHinting() ? [nsFont screenFont] : [nsFont printerFont]; | 258 useHinting() ? [nsFont screenFont] : [nsFont printerFont]; |
| 257 NSInteger appKitWeight = toAppKitFontWeight(fontDescription.weight()); | 259 NSInteger appKitWeight = toAppKitFontWeight(fontDescription.weight()); |
| 258 | 260 |
| 259 // TODO(eae): Remove once skia supports bold emoji. See https://bugs.chromium.
org/p/skia/issues/detail?id=4904 | 261 // TODO(eae): Remove once skia supports bold emoji. See |
| 262 // https://bugs.chromium.org/p/skia/issues/detail?id=4904 |
| 260 // Bold emoji look the same as normal emoji, so syntheticBold isn't needed. | 263 // Bold emoji look the same as normal emoji, so syntheticBold isn't needed. |
| 261 bool syntheticBold = [platformFont.familyName isEqual:@"Apple Color Emoji"] | 264 bool syntheticBold = [platformFont.familyName isEqual:@"Apple Color Emoji"] |
| 262 ? false | 265 ? false |
| 263 : (isAppKitFontWeightBold(appKitWeight) && | 266 : (isAppKitFontWeightBold(appKitWeight) && |
| 264 !isAppKitFontWeightBold(actualWeight)) || | 267 !isAppKitFontWeightBold(actualWeight)) || |
| 265 fontDescription.isSyntheticBold(); | 268 fontDescription.isSyntheticBold(); |
| 266 | 269 |
| 267 bool syntheticItalic = | 270 bool syntheticItalic = |
| 268 ((traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait)) || | 271 ((traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait)) || |
| 269 fontDescription.isSyntheticItalic(); | 272 fontDescription.isSyntheticItalic(); |
| 270 | 273 |
| 271 // FontPlatformData::typeface() is null in the case of Chromium out-of-process
font loading failing. | 274 // FontPlatformData::typeface() is null in the case of Chromium out-of-process |
| 272 // Out-of-process loading occurs for registered fonts stored in non-system loc
ations. | 275 // font loading failing. Out-of-process loading occurs for registered fonts |
| 273 // When loading fails, we do not want to use the returned FontPlatformData sin
ce it will not have | 276 // stored in non-system locations. When loading fails, we do not want to use |
| 274 // a valid SkTypeface. | 277 // the returned FontPlatformData since it will not have a valid SkTypeface. |
| 275 std::unique_ptr<FontPlatformData> platformData = wrapUnique( | 278 std::unique_ptr<FontPlatformData> platformData = wrapUnique( |
| 276 new FontPlatformData(platformFont, size, syntheticBold, syntheticItalic, | 279 new FontPlatformData(platformFont, size, syntheticBold, syntheticItalic, |
| 277 fontDescription.orientation())); | 280 fontDescription.orientation())); |
| 278 if (!platformData->typeface()) { | 281 if (!platformData->typeface()) { |
| 279 return nullptr; | 282 return nullptr; |
| 280 } | 283 } |
| 281 return platformData; | 284 return platformData; |
| 282 } | 285 } |
| 283 | 286 |
| 284 } // namespace blink | 287 } // namespace blink |
| OLD | NEW |