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

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

Issue 1292593003: Revert "Revert "Reland 2: mac: Use a placeholder string for the family name of the system font." Br… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « Source/platform/blink_platform.gypi ('k') | Source/platform/fonts/mac/FontFamilyMatcherMac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « Source/platform/blink_platform.gypi ('k') | Source/platform/fonts/mac/FontFamilyMatcherMac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698