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 23 matching lines...) Expand all Loading... |
34 #include "platform/RuntimeEnabledFeatures.h" | 34 #include "platform/RuntimeEnabledFeatures.h" |
35 #include "platform/fonts/FontDescription.h" | 35 #include "platform/fonts/FontDescription.h" |
36 #include "platform/fonts/FontFaceCreationParams.h" | 36 #include "platform/fonts/FontFaceCreationParams.h" |
37 #include "platform/fonts/FontPlatformData.h" | 37 #include "platform/fonts/FontPlatformData.h" |
38 #include "platform/fonts/SimpleFontData.h" | 38 #include "platform/fonts/SimpleFontData.h" |
39 #include "platform/fonts/mac/FontFamilyMatcherMac.h" | 39 #include "platform/fonts/mac/FontFamilyMatcherMac.h" |
40 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
41 #include "public/platform/WebTaskRunner.h" | 41 #include "public/platform/WebTaskRunner.h" |
42 #include "public/platform/WebTraceLocation.h" | 42 #include "public/platform/WebTraceLocation.h" |
43 #include "wtf/Functional.h" | 43 #include "wtf/Functional.h" |
| 44 #include "wtf/PtrUtil.h" |
44 #include "wtf/StdLibExtras.h" | 45 #include "wtf/StdLibExtras.h" |
| 46 #include <memory> |
45 | 47 |
46 // Forward declare Mac SPIs. | 48 // Forward declare Mac SPIs. |
47 // Request for public API: rdar://13803570 | 49 // Request for public API: rdar://13803570 |
48 @interface NSFont (WebKitSPI) | 50 @interface NSFont (WebKitSPI) |
49 + (NSFont*)findFontLike:(NSFont*)font forString:(NSString*)string withRange:(NSR
ange)range inLanguage:(id)useNil; | 51 + (NSFont*)findFontLike:(NSFont*)font forString:(NSString*)string withRange:(NSR
ange)range inLanguage:(id)useNil; |
50 + (NSFont*)findFontLike:(NSFont*)font forCharacter:(UniChar)uc inLanguage:(id)us
eNil; | 52 + (NSFont*)findFontLike:(NSFont*)font forCharacter:(UniChar)uc inLanguage:(id)us
eNil; |
51 @end | 53 @end |
52 | 54 |
53 namespace blink { | 55 namespace blink { |
54 | 56 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return simpleFontData.release(); | 197 return simpleFontData.release(); |
196 | 198 |
197 // The Times fallback will almost always work, but in the highly unusual cas
e where | 199 // The Times fallback will almost always work, but in the highly unusual cas
e where |
198 // the user doesn't have it, we fall back on Lucida Grande because that's | 200 // the user doesn't have it, we fall back on Lucida Grande because that's |
199 // guaranteed to be there, according to Nathan Taylor. This is good enough | 201 // guaranteed to be there, according to Nathan Taylor. This is good enough |
200 // to avoid a crash at least. | 202 // to avoid a crash at least. |
201 DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande")); | 203 DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande")); |
202 return getFontData(fontDescription, lucidaGrandeStr, false, shouldRetain); | 204 return getFontData(fontDescription, lucidaGrandeStr, false, shouldRetain); |
203 } | 205 } |
204 | 206 |
205 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip
tion& fontDescription, | 207 std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
scription& fontDescription, |
206 const FontFaceCreationParams& creationParams, float fontSize) | 208 const FontFaceCreationParams& creationParams, float fontSize) |
207 { | 209 { |
208 NSFontTraitMask traits = fontDescription.style() ? NSFontItalicTrait : 0; | 210 NSFontTraitMask traits = fontDescription.style() ? NSFontItalicTrait : 0; |
209 float size = fontSize; | 211 float size = fontSize; |
210 | 212 |
211 NSFont* nsFont = MatchNSFontFamily(creationParams.family(), traits, fontDesc
ription.weight(), size); | 213 NSFont* nsFont = MatchNSFontFamily(creationParams.family(), traits, fontDesc
ription.weight(), size); |
212 if (!nsFont) | 214 if (!nsFont) |
213 return nullptr; | 215 return nullptr; |
214 | 216 |
215 NSFontManager *fontManager = [NSFontManager sharedFontManager]; | 217 NSFontManager *fontManager = [NSFontManager sharedFontManager]; |
216 NSFontTraitMask actualTraits = 0; | 218 NSFontTraitMask actualTraits = 0; |
217 if (fontDescription.style()) | 219 if (fontDescription.style()) |
218 actualTraits = [fontManager traitsOfFont:nsFont]; | 220 actualTraits = [fontManager traitsOfFont:nsFont]; |
219 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; | 221 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; |
220 | 222 |
221 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF
ont]; | 223 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF
ont]; |
222 NSInteger appKitWeight = toAppKitFontWeight(fontDescription.weight()); | 224 NSInteger appKitWeight = toAppKitFontWeight(fontDescription.weight()); |
223 | 225 |
224 // TODO(eae): Remove once skia supports bold emoji. See https://bugs.chromiu
m.org/p/skia/issues/detail?id=4904 | 226 // TODO(eae): Remove once skia supports bold emoji. See https://bugs.chromiu
m.org/p/skia/issues/detail?id=4904 |
225 // Bold emoji look the same as normal emoji, so syntheticBold isn't needed. | 227 // Bold emoji look the same as normal emoji, so syntheticBold isn't needed. |
226 bool syntheticBold = [platformFont.familyName isEqual:@"Apple Color Emoji"]
? false : | 228 bool syntheticBold = [platformFont.familyName isEqual:@"Apple Color Emoji"]
? false : |
227 (isAppKitFontWeightBold(appKitWeight) && !isAppKitFontWeightBold(actualW
eight)) || fontDescription.isSyntheticBold(); | 229 (isAppKitFontWeightBold(appKitWeight) && !isAppKitFontWeightBold(actualW
eight)) || fontDescription.isSyntheticBold(); |
228 | 230 |
229 bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSF
ontItalicTrait)) || fontDescription.isSyntheticItalic(); | 231 bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSF
ontItalicTrait)) || fontDescription.isSyntheticItalic(); |
230 | 232 |
231 // FontPlatformData::typeface() is null in the case of Chromium out-of-proce
ss font loading failing. | 233 // FontPlatformData::typeface() is null in the case of Chromium out-of-proce
ss font loading failing. |
232 // Out-of-process loading occurs for registered fonts stored in non-system l
ocations. | 234 // Out-of-process loading occurs for registered fonts stored in non-system l
ocations. |
233 // When loading fails, we do not want to use the returned FontPlatformData s
ince it will not have | 235 // When loading fails, we do not want to use the returned FontPlatformData s
ince it will not have |
234 // a valid SkTypeface. | 236 // a valid SkTypeface. |
235 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo
rmFont, size, syntheticBold, syntheticItalic, fontDescription.orientation())); | 237 std::unique_ptr<FontPlatformData> platformData = wrapUnique(new FontPlatform
Data(platformFont, size, syntheticBold, syntheticItalic, fontDescription.orienta
tion())); |
236 if (!platformData->typeface()) { | 238 if (!platformData->typeface()) { |
237 return nullptr; | 239 return nullptr; |
238 } | 240 } |
239 return platformData; | 241 return platformData; |
240 } | 242 } |
241 | 243 |
242 } // namespace blink | 244 } // namespace blink |
OLD | NEW |