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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/win/FontPlatformDataWin.cpp

Issue 1763803002: Pass Windows font rendering preferences from browser to blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 Apple Computer, Inc. 2 * Copyright (C) 2006, 2007 Apple Computer, Inc.
3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved. 3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved.
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 are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 || LayoutTestSupport::isRunningLayoutTest())) 78 || LayoutTestSupport::isRunningLayoutTest()))
79 flags |= SkPaint::kSubpixelText_Flag; 79 flags |= SkPaint::kSubpixelText_Flag;
80 80
81 SkASSERT(!(textFlags & ~textFlagsMask)); 81 SkASSERT(!(textFlags & ~textFlagsMask));
82 flags |= textFlags; 82 flags |= textFlags;
83 } 83 }
84 84
85 paint->setFlags(flags); 85 paint->setFlags(flags);
86 } 86 }
87 87
88 // Lookup the current system settings for font smoothing.
89 // We cache these values for performance, but if the browser has a way to be
90 // notified when these change, we could re-query them at that time.
91 static uint32_t getSystemTextFlags()
92 {
93 static bool gInited;
94 static uint32_t gFlags;
95 if (!gInited) {
96 BOOL enabled;
97 gFlags = 0;
98 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0)) {
99 if (enabled) {
100 gFlags |= SkPaint::kAntiAlias_Flag;
101
102 UINT smoothType;
103 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothTyp e, 0)) {
104 if (FE_FONTSMOOTHINGCLEARTYPE == smoothType)
105 gFlags |= SkPaint::kLCDRenderText_Flag;
106 }
107 }
108 } else {
109 // SystemParametersInfo will fail only under full sandbox lockdown o n Win8+.
110 // So, we default to settings we know are supported and look good.
111 // FIXME(eae): We should be querying the DirectWrite settings direct ly
112 // so we can respect the settings for users who turn off smoothing.
113 gFlags = SkPaint::kAntiAlias_Flag | SkPaint::kLCDRenderText_Flag;
114 }
115 gInited = true;
116 }
117 return gFlags;
118 }
119
120 static bool isWebFont(const String& familyName) 88 static bool isWebFont(const String& familyName)
121 { 89 {
122 // Web-fonts have artifical names constructed to always be: 90 // Web-fonts have artifical names constructed to always be:
123 // 1. 24 characters, followed by a '\0' 91 // 1. 24 characters, followed by a '\0'
124 // 2. the last two characters are '==' 92 // 2. the last two characters are '=='
125 return familyName.length() == 24 93 return familyName.length() == 24
126 && '=' == familyName[22] && '=' == familyName[23]; 94 && '=' == familyName[22] && '=' == familyName[23];
127 } 95 }
128 96
129 static int computePaintTextFlags(String fontFamilyName) 97 static int computePaintTextFlags(String fontFamilyName)
130 { 98 {
131 if (LayoutTestSupport::isRunningLayoutTest()) 99 if (LayoutTestSupport::isRunningLayoutTest())
132 return LayoutTestSupport::isFontAntialiasingEnabledForTest() ? SkPaint:: kAntiAlias_Flag : 0; 100 return LayoutTestSupport::isFontAntialiasingEnabledForTest() ? SkPaint:: kAntiAlias_Flag : 0;
133 101
134 int textFlags = getSystemTextFlags(); 102 int textFlags = 0;
103 if (FontCache::fontCache()->antialiasedTextEnabled()) {
104 int lcdFlag = FontCache::fontCache()->lcdTextEnabled()
105 ? SkPaint::kLCDRenderText_Flag
106 : 0;
107 textFlags = SkPaint::kAntiAlias_Flag | lcdFlag;
108 }
135 109
136 // Many web-fonts are so poorly hinted that they are terrible to read when d rawn in BW. 110 // Many web-fonts are so poorly hinted that they are terrible to read when d rawn in BW.
137 // In these cases, we have decided to FORCE these fonts to be drawn with at least grayscale AA, 111 // In these cases, we have decided to FORCE these fonts to be drawn with at least grayscale AA,
138 // even when the System (getSystemTextFlags) tells us to draw only in BW. 112 // even when the System (getSystemTextFlags) tells us to draw only in BW.
139 if (isWebFont(fontFamilyName)) 113 if (isWebFont(fontFamilyName))
140 textFlags |= SkPaint::kAntiAlias_Flag; 114 textFlags |= SkPaint::kAntiAlias_Flag;
141 115
142 return textFlags; 116 return textFlags;
143 } 117 }
144 118
145 119
146 void FontPlatformData::querySystemForRenderStyle(bool) 120 void FontPlatformData::querySystemForRenderStyle(bool)
147 { 121 {
148 m_paintTextFlags = computePaintTextFlags(fontFamilyName()); 122 m_paintTextFlags = computePaintTextFlags(fontFamilyName());
149 } 123 }
150 124
151 bool FontPlatformData::defaultUseSubpixelPositioning() 125 bool FontPlatformData::defaultUseSubpixelPositioning()
152 { 126 {
153 return FontCache::fontCache()->useSubpixelPositioning(); 127 return FontCache::fontCache()->useSubpixelPositioning();
154 } 128 }
155 129
156 } // namespace blink 130 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/FontCache.cpp ('k') | third_party/WebKit/Source/web/win/WebFontRendering.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698