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

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

Issue 1299653004: Revert "Reland 2: mac: Use a placeholder string for the family name of the system font." (branch 248 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@2485
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
85 static inline bool isAppKitFontWeightBold(NSInteger appKitFontWeight) 101 static inline bool isAppKitFontWeightBold(NSInteger appKitFontWeight)
86 { 102 {
87 return appKitFontWeight >= 7; 103 return appKitFontWeight >= 7;
88 } 104 }
89 105
90 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 character, const SimpleFontData* fontDataToSubsti tute) 106 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 character, const SimpleFontData* fontDataToSubsti tute)
91 { 107 {
92 // FIXME: We should fix getFallbackFamily to take a UChar32 108 // FIXME: We should fix getFallbackFamily to take a UChar32
93 // and remove this split-to-UChar16 code. 109 // and remove this split-to-UChar16 code.
94 UChar codeUnits[2]; 110 UChar codeUnits[2];
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // the user doesn't have it, we fall back on Lucida Grande because that's 196 // the user doesn't have it, we fall back on Lucida Grande because that's
181 // guaranteed to be there, according to Nathan Taylor. This is good enough 197 // guaranteed to be there, according to Nathan Taylor. This is good enough
182 // to avoid a crash at least. 198 // to avoid a crash at least.
183 DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande", AtomicS tring::ConstructFromLiteral)); 199 DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande", AtomicS tring::ConstructFromLiteral));
184 return getFontData(fontDescription, lucidaGrandeStr, false, shouldRetain); 200 return getFontData(fontDescription, lucidaGrandeStr, false, shouldRetain);
185 } 201 }
186 202
187 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize) 203 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize)
188 { 204 {
189 NSFontTraitMask traits = fontDescription.style() ? NSFontItalicTrait : 0; 205 NSFontTraitMask traits = fontDescription.style() ? NSFontItalicTrait : 0;
206 NSInteger weight = toAppKitFontWeight(fontDescription.weight());
190 float size = fontSize; 207 float size = fontSize;
191 208
192 NSFont* nsFont = MatchNSFontFamily(creationParams.family(), traits, fontDesc ription.weight(), size); 209 NSFont *nsFont = MatchNSFontFamily(creationParams.family(),traits, weight, s ize);
193 if (!nsFont) 210 if (!nsFont)
194 return 0; 211 return 0;
195 212
196 NSFontManager *fontManager = [NSFontManager sharedFontManager]; 213 NSFontManager *fontManager = [NSFontManager sharedFontManager];
197 NSFontTraitMask actualTraits = 0; 214 NSFontTraitMask actualTraits = 0;
198 if (fontDescription.style()) 215 if (fontDescription.style())
199 actualTraits = [fontManager traitsOfFont:nsFont]; 216 actualTraits = [fontManager traitsOfFont:nsFont];
200 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; 217 NSInteger actualWeight = [fontManager weightOfFont:nsFont];
201 218
202 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF ont]; 219 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF ont];
203 NSInteger appKitWeight = toAppKitFontWeight(fontDescription.weight()); 220 bool syntheticBold = (isAppKitFontWeightBold(weight) && !isAppKitFontWeightB old(actualWeight)) || fontDescription.isSyntheticBold();
204 bool syntheticBold = (isAppKitFontWeightBold(appKitWeight) && !isAppKitFontW eightBold(actualWeight)) || fontDescription.isSyntheticBold();
205 bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSF ontItalicTrait)) || fontDescription.isSyntheticItalic(); 221 bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSF ontItalicTrait)) || fontDescription.isSyntheticItalic();
206 222
207 // FontPlatformData::typeface() is null in the case of Chromium out-of-proce ss font loading failing. 223 // FontPlatformData::typeface() is null in the case of Chromium out-of-proce ss font loading failing.
208 // Out-of-process loading occurs for registered fonts stored in non-system l ocations. 224 // Out-of-process loading occurs for registered fonts stored in non-system l ocations.
209 // When loading fails, we do not want to use the returned FontPlatformData s ince it will not have 225 // When loading fails, we do not want to use the returned FontPlatformData s ince it will not have
210 // a valid SkTypeface. 226 // a valid SkTypeface.
211 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo rmFont, size, syntheticBold, syntheticItalic, fontDescription.orientation())); 227 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo rmFont, size, syntheticBold, syntheticItalic, fontDescription.orientation()));
212 if (!platformData->typeface()) { 228 if (!platformData->typeface()) {
213 return nullptr; 229 return nullptr;
214 } 230 }
215 return platformData.leakPtr(); 231 return platformData.leakPtr();
216 } 232 }
217 233
218 } // namespace blink 234 } // 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