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

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

Issue 304723002: Gate subpixel scaling by RuntimeEnabledFeatures::subpixelFontScalingEnabled() on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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 13 matching lines...) Expand all
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30 #import "config.h" 30 #import "config.h"
31 #import "platform/fonts/FontCache.h" 31 #import "platform/fonts/FontCache.h"
32 32
33 #import <AppKit/AppKit.h> 33 #import <AppKit/AppKit.h>
34 #import "RuntimeEnabledFeatures.h"
34 #import "platform/LayoutTestSupport.h" 35 #import "platform/LayoutTestSupport.h"
35 #import "platform/fonts/FontDescription.h" 36 #import "platform/fonts/FontDescription.h"
36 #import "platform/fonts/FontPlatformData.h" 37 #import "platform/fonts/FontPlatformData.h"
37 #import "platform/fonts/SimpleFontData.h" 38 #import "platform/fonts/SimpleFontData.h"
38 #import "platform/mac/WebFontCache.h" 39 #import "platform/mac/WebFontCache.h"
39 #import <wtf/MainThread.h> 40 #import <wtf/MainThread.h>
40 #import <wtf/StdLibExtras.h> 41 #import <wtf/StdLibExtras.h>
41 42
42 // Forward declare Mac SPIs. 43 // Forward declare Mac SPIs.
43 // Request for public API: rdar://13803570 44 // Request for public API: rdar://13803570
(...skipping 14 matching lines...) Expand all
58 FontCache::fontCache()->invalidate(); 59 FontCache::fontCache()->invalidate();
59 } 60 }
60 61
61 static void fontCacheRegisteredFontsChangedNotificationCallback(CFNotificationCe nterRef, void* observer, CFStringRef name, const void *, CFDictionaryRef) 62 static void fontCacheRegisteredFontsChangedNotificationCallback(CFNotificationCe nterRef, void* observer, CFStringRef name, const void *, CFDictionaryRef)
62 { 63 {
63 ASSERT_UNUSED(observer, observer == FontCache::fontCache()); 64 ASSERT_UNUSED(observer, observer == FontCache::fontCache());
64 ASSERT_UNUSED(name, CFEqual(name, kCTFontManagerRegisteredFontsChangedNotifi cation)); 65 ASSERT_UNUSED(name, CFEqual(name, kCTFontManagerRegisteredFontsChangedNotifi cation));
65 invalidateFontCache(0); 66 invalidateFontCache(0);
66 } 67 }
67 68
69 static bool useHinting()
70 {
71 // Enable hinting when subpixel font scaling is disabled or
72 // when running the set of standard non-subpixel layout tests,
73 // otherwise use subpixel glyph positioning.
74 return (isRunningLayoutTest() && !isFontAntialiasingEnabledForTest()) || !Ru ntimeEnabledFeatures::subpixelFontScalingEnabled();
75 }
76
68 void FontCache::platformInit() 77 void FontCache::platformInit()
69 { 78 {
70 CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, fontCacheRegisteredFontsChangedNotificationCallback, kCTFontManagerRegisteredFon tsChangedNotification, 0, CFNotificationSuspensionBehaviorDeliverImmediately); 79 CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, fontCacheRegisteredFontsChangedNotificationCallback, kCTFontManagerRegisteredFon tsChangedNotification, 0, CFNotificationSuspensionBehaviorDeliverImmediately);
71 } 80 }
72 81
73 static int toAppKitFontWeight(FontWeight fontWeight) 82 static int toAppKitFontWeight(FontWeight fontWeight)
74 { 83 {
75 static int appKitFontWeights[] = { 84 static int appKitFontWeights[] = {
76 2, // FontWeight100 85 2, // FontWeight100
77 3, // FontWeight200 86 3, // FontWeight200
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 NSInteger substituteFontWeight = [fontManager weightOfFont:substituteFont]; 163 NSInteger substituteFontWeight = [fontManager weightOfFont:substituteFont];
155 164
156 if (traits != substituteFontTraits || weight != substituteFontWeight || !nsF ont) { 165 if (traits != substituteFontTraits || weight != substituteFontWeight || !nsF ont) {
157 if (NSFont *bestVariation = [fontManager fontWithFamily:[substituteFont familyName] traits:traits weight:weight size:size]) { 166 if (NSFont *bestVariation = [fontManager fontWithFamily:[substituteFont familyName] traits:traits weight:weight size:size]) {
158 if (!nsFont || (([fontManager traitsOfFont:bestVariation] != substit uteFontTraits || [fontManager weightOfFont:bestVariation] != substituteFontWeigh t) 167 if (!nsFont || (([fontManager traitsOfFont:bestVariation] != substit uteFontTraits || [fontManager weightOfFont:bestVariation] != substituteFontWeigh t)
159 && [[bestVariation coveredCharacterSet] longCharacterIsMember:ch aracter])) 168 && [[bestVariation coveredCharacterSet] longCharacterIsMember:ch aracter]))
160 substituteFont = bestVariation; 169 substituteFont = bestVariation;
161 } 170 }
162 } 171 }
163 172
164 // Enable hinting, which is equivalent to using the screen font, 173 substituteFont = useHinting() ? [substituteFont screenFont] : [substituteFon t printerFont];
165 // only when running the set of standard non-subpixel layout tests,
166 // otherwise use subpixel glyph positioning.
167 substituteFont = !isRunningLayoutTest() || isFontAntialiasingEnabledForTest( ) ? [substituteFont printerFont] : [substituteFont screenFont];
168 174
169 substituteFontTraits = [fontManager traitsOfFont:substituteFont]; 175 substituteFontTraits = [fontManager traitsOfFont:substituteFont];
170 substituteFontWeight = [fontManager weightOfFont:substituteFont]; 176 substituteFontWeight = [fontManager weightOfFont:substituteFont];
171 177
172 FontPlatformData alternateFont(substituteFont, platformData.size(), 178 FontPlatformData alternateFont(substituteFont, platformData.size(),
173 isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFont Weight), 179 isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFont Weight),
174 (traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTra it), 180 (traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTra it),
175 platformData.m_orientation); 181 platformData.m_orientation);
176 182
177 return fontDataFromFontPlatformData(&alternateFont, DoNotRetain); 183 return fontDataFromFontPlatformData(&alternateFont, DoNotRetain);
(...skipping 26 matching lines...) Expand all
204 NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:we ight size:size]; 210 NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:we ight size:size];
205 if (!nsFont) 211 if (!nsFont)
206 return 0; 212 return 0;
207 213
208 NSFontManager *fontManager = [NSFontManager sharedFontManager]; 214 NSFontManager *fontManager = [NSFontManager sharedFontManager];
209 NSFontTraitMask actualTraits = 0; 215 NSFontTraitMask actualTraits = 0;
210 if (fontDescription.style()) 216 if (fontDescription.style())
211 actualTraits = [fontManager traitsOfFont:nsFont]; 217 actualTraits = [fontManager traitsOfFont:nsFont];
212 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; 218 NSInteger actualWeight = [fontManager weightOfFont:nsFont];
213 219
214 // Enable hinting, which is equivalent to using the screen font, 220 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF ont];
215 // only when running the set of standard non-subpixel layout tests,
216 // otherwise use subpixel glyph positioning.
217 NSFont *platformFont = !isRunningLayoutTest() || isFontAntialiasingEnabledFo rTest() ? [nsFont printerFont] : [nsFont screenFont];
218 bool syntheticBold = (isAppKitFontWeightBold(weight) && !isAppKitFontWeightB old(actualWeight)) || fontDescription.isSyntheticBold(); 221 bool syntheticBold = (isAppKitFontWeightBold(weight) && !isAppKitFontWeightB old(actualWeight)) || fontDescription.isSyntheticBold();
219 bool syntheticOblique = ((traits & NSFontItalicTrait) && !(actualTraits & NS FontItalicTrait)) || fontDescription.isSyntheticItalic(); 222 bool syntheticOblique = ((traits & NSFontItalicTrait) && !(actualTraits & NS FontItalicTrait)) || fontDescription.isSyntheticItalic();
220 223
221 // FontPlatformData::font() can be null for the case of Chromium out-of-proc ess font loading. 224 // FontPlatformData::font() can be null for the case of Chromium out-of-proc ess font loading.
222 // In that case, we don't want to use the platformData. 225 // In that case, we don't want to use the platformData.
223 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo rmFont, size, syntheticBold, syntheticOblique, fontDescription.orientation(), fo ntDescription.widthVariant())); 226 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo rmFont, size, syntheticBold, syntheticOblique, fontDescription.orientation(), fo ntDescription.widthVariant()));
224 if (!platformData->font()) 227 if (!platformData->font())
225 return 0; 228 return 0;
226 return platformData.leakPtr(); 229 return platformData.leakPtr();
227 } 230 }
228 231
229 } // namespace WebCore 232 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/platform/fonts/mac/SimpleFontDataMac.mm » ('j') | Source/platform/fonts/mac/SimpleFontDataMac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698