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

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

Issue 139203009: Re-land "Don't check lfQuality in LOGFONT as it has no effect on rendering"" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/fonts/win/FontPlatformDataWin.h ('k') | no next file » | 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 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 SkASSERT(!(textFlags & ~textFlagsMask)); 78 SkASSERT(!(textFlags & ~textFlagsMask));
79 uint32_t flags = paint->getFlags(); 79 uint32_t flags = paint->getFlags();
80 flags &= ~textFlagsMask; 80 flags &= ~textFlagsMask;
81 flags |= textFlags; 81 flags |= textFlags;
82 paint->setFlags(flags); 82 paint->setFlags(flags);
83 } 83 }
84 84
85 // Lookup the current system settings for font smoothing. 85 // Lookup the current system settings for font smoothing.
86 // We cache these values for performance, but if the browser has a way to be 86 // We cache these values for performance, but if the browser has a way to be
87 // notified when these change, we could re-query them at that time. 87 // notified when these change, we could re-query them at that time.
88 static uint32_t getDefaultGDITextFlags() 88 static uint32_t getSystemTextFlags()
89 { 89 {
90 static bool gInited; 90 static bool gInited;
91 static uint32_t gFlags; 91 static uint32_t gFlags;
92 if (!gInited) { 92 if (!gInited) {
93 BOOL enabled; 93 BOOL enabled;
94 gFlags = 0; 94 gFlags = 0;
95 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enable d) { 95 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enable d) {
96 gFlags |= SkPaint::kAntiAlias_Flag; 96 gFlags |= SkPaint::kAntiAlias_Flag;
97 97
98 UINT smoothType; 98 UINT smoothType;
99 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothType, 0 )) { 99 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothType, 0 )) {
100 if (FE_FONTSMOOTHINGCLEARTYPE == smoothType) 100 if (FE_FONTSMOOTHINGCLEARTYPE == smoothType)
101 gFlags |= SkPaint::kLCDRenderText_Flag; 101 gFlags |= SkPaint::kLCDRenderText_Flag;
102 } 102 }
103 } 103 }
104 gInited = true; 104 gInited = true;
105 } 105 }
106 return gFlags; 106 return gFlags;
107 } 107 }
108 108
109 static bool isWebFont(const LOGFONT& lf) 109 static bool isWebFont(const String& familyName)
110 { 110 {
111 // web-fonts have artifical names constructed to always be 111 // Web-fonts have artifical names constructed to always be:
112 // 1. 24 characters, followed by a '\0' 112 // 1. 24 characters, followed by a '\0'
113 // 2. the last two characters are '==' 113 // 2. the last two characters are '=='
114 return '=' == lf.lfFaceName[22] && '=' == lf.lfFaceName[23] && '\0' == lf.lf FaceName[24]; 114 return familyName.length() == 24
115 && '=' == familyName[22] && '=' == familyName[23];
115 } 116 }
116 117
117 static int computePaintTextFlags(const LOGFONT& lf) 118 static int computePaintTextFlags()
bungeman-skia 2014/02/11 15:42:56 computePaintTextFlags(bool isWebFont) this is sta
118 { 119 {
119 int textFlags = 0; 120 int textFlags = getSystemTextFlags();
120 switch (lf.lfQuality) {
121 case NONANTIALIASED_QUALITY:
122 textFlags = 0;
123 break;
124 case ANTIALIASED_QUALITY:
125 textFlags = SkPaint::kAntiAlias_Flag;
126 break;
127 case CLEARTYPE_QUALITY:
128 textFlags = (SkPaint::kAntiAlias_Flag | SkPaint::kLCDRenderText_Flag);
129 break;
130 default:
131 textFlags = getDefaultGDITextFlags();
132 break;
133 }
134 121
135 // only allow features that SystemParametersInfo allows 122 // Many web-fonts are so poorly hinted that they are terrible to read when d rawn in BW.
136 textFlags &= getDefaultGDITextFlags(); 123 // In these cases, we have decided to FORCE these fonts to be drawn with at least grayscale AA,
137 124 // even when the System (getSystemTextFlags) tells us to draw only in BW.
138 /* 125 if (isWebFont(fontFamilyName()) && !isRunningLayoutTest())
139 * FontPlatformData(...) will read our logfont, and try to honor the the lf Quality
140 * setting (computing the corresponding SkPaint flags for AA and LCD). Howe ver, it
141 * will limit the quality based on its query of SPI_GETFONTSMOOTHING. This could mean
142 * we end up drawing the text in BW, even though our lfQuality requested an tialiasing.
143 *
144 * Many web-fonts are so poorly hinted that they are terrible to read when drawn in BW.
145 * In these cases, we have decided to FORCE these fonts to be drawn with at least grayscale AA,
146 * even when the System (getDefaultGDITextFlags) tells us to draw only in B W.
147 */
148 if (isWebFont(lf) && !isRunningLayoutTest())
149 textFlags |= SkPaint::kAntiAlias_Flag; 126 textFlags |= SkPaint::kAntiAlias_Flag;
150 return textFlags; 127 return textFlags;
151 } 128 }
152 129
153 #if !USE(HARFBUZZ) 130 #if !USE(HARFBUZZ)
154 PassRefPtr<SkTypeface> CreateTypefaceFromHFont(HFONT hfont, int* size, int* pain tTextFlags) 131 PassRefPtr<SkTypeface> CreateTypefaceFromHFont(HFONT hfont, int* size)
155 { 132 {
156 LOGFONT info; 133 LOGFONT info;
157 GetObject(hfont, sizeof(info), &info); 134 GetObject(hfont, sizeof(info), &info);
158 if (size) { 135 if (size) {
159 int height = info.lfHeight; 136 int height = info.lfHeight;
160 if (height < 0) 137 if (height < 0)
161 height = -height; 138 height = -height;
162 *size = height; 139 *size = height;
163 } 140 }
164 if (paintTextFlags)
165 *paintTextFlags = computePaintTextFlags(info);
166 return adoptRef(SkCreateTypefaceFromLOGFONT(info)); 141 return adoptRef(SkCreateTypefaceFromLOGFONT(info));
167 } 142 }
168 #endif 143 #endif
169 144
170 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) 145 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
171 : m_textSize(-1) 146 : m_textSize(-1)
172 , m_syntheticBold(false) 147 , m_syntheticBold(false)
173 , m_syntheticItalic(false) 148 , m_syntheticItalic(false)
174 , m_orientation(Horizontal) 149 , m_orientation(Horizontal)
175 , m_typeface(adoptRef(SkTypeface::RefDefault())) 150 , m_typeface(adoptRef(SkTypeface::RefDefault()))
(...skipping 24 matching lines...) Expand all
200 } 175 }
201 176
202 #if ENABLE(GDI_FONTS_ON_WINDOWS) && !USE(HARFBUZZ) 177 #if ENABLE(GDI_FONTS_ON_WINDOWS) && !USE(HARFBUZZ)
203 FontPlatformData::FontPlatformData(HFONT font, float size, FontOrientation orien tation) 178 FontPlatformData::FontPlatformData(HFONT font, float size, FontOrientation orien tation)
204 : m_font(RefCountedHFONT::create(font)) 179 : m_font(RefCountedHFONT::create(font))
205 , m_textSize(size) 180 , m_textSize(size)
206 , m_syntheticBold(false) 181 , m_syntheticBold(false)
207 , m_syntheticItalic(false) 182 , m_syntheticItalic(false)
208 , m_orientation(orientation) 183 , m_orientation(orientation)
209 , m_scriptCache(0) 184 , m_scriptCache(0)
210 , m_typeface(CreateTypefaceFromHFont(font, 0, &m_paintTextFlags)) 185 , m_typeface(CreateTypefaceFromHFont(font, 0))
211 , m_isHashTableDeletedValue(false) 186 , m_isHashTableDeletedValue(false)
212 , m_useSubpixelPositioning(false) 187 , m_useSubpixelPositioning(false)
213 { 188 {
189 m_paintTextFlags = computePaintTextFlags();
214 } 190 }
215 #endif 191 #endif
216 192
217 // FIXME: this constructor is needed for SVG fonts but doesn't seem to do much 193 // FIXME: this constructor is needed for SVG fonts but doesn't seem to do much
218 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) 194 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique)
219 : m_textSize(size) 195 : m_textSize(size)
220 , m_syntheticBold(false) 196 , m_syntheticBold(false)
221 , m_syntheticItalic(false) 197 , m_syntheticItalic(false)
222 , m_orientation(Horizontal) 198 , m_orientation(Horizontal)
223 , m_typeface(adoptRef(SkTypeface::RefDefault())) 199 , m_typeface(adoptRef(SkTypeface::RefDefault()))
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 , m_orientation(orientation) 248 , m_orientation(orientation)
273 , m_typeface(tf) 249 , m_typeface(tf)
274 , m_isHashTableDeletedValue(false) 250 , m_isHashTableDeletedValue(false)
275 , m_useSubpixelPositioning(useSubpixelPositioning) 251 , m_useSubpixelPositioning(useSubpixelPositioning)
276 { 252 {
277 // FIXME: This can be removed together with m_font once the last few 253 // FIXME: This can be removed together with m_font once the last few
278 // uses of hfont() has been eliminated. 254 // uses of hfont() has been eliminated.
279 LOGFONT logFont; 255 LOGFONT logFont;
280 SkLOGFONTFromTypeface(m_typeface.get(), &logFont); 256 SkLOGFONTFromTypeface(m_typeface.get(), &logFont);
281 logFont.lfHeight = -textSize; 257 logFont.lfHeight = -textSize;
282 m_paintTextFlags = computePaintTextFlags(logFont); 258 m_paintTextFlags = computePaintTextFlags(logFont);
bungeman-skia 2014/02/11 15:42:56 computeTextFlags doesn't take a param anymore?
283 259
284 #if !USE(HARFBUZZ) 260 #if !USE(HARFBUZZ)
285 HFONT hFont = CreateFontIndirect(&logFont); 261 HFONT hFont = CreateFontIndirect(&logFont);
286 m_font = hFont ? RefCountedHFONT::create(hFont) : 0; 262 m_font = hFont ? RefCountedHFONT::create(hFont) : 0;
287 m_scriptCache = 0; 263 m_scriptCache = 0;
288 #endif 264 #endif
289 } 265 }
290 266
291 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data) 267 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data)
292 { 268 {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 415 }
440 416
441 #ifndef NDEBUG 417 #ifndef NDEBUG
442 String FontPlatformData::description() const 418 String FontPlatformData::description() const
443 { 419 {
444 return String(); 420 return String();
445 } 421 }
446 #endif 422 #endif
447 423
448 } // namespace WebCore 424 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/fonts/win/FontPlatformDataWin.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698