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

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

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

Powered by Google App Engine
This is Rietveld 408576698