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

Side by Side Diff: Source/core/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp

Issue 23454039: detect web-fonts, and force gray-antialiasing for them, regardless of the system's FONTSMOOTHING se… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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 | « no previous file | 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 17 matching lines...) Expand all
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #include "config.h" 32 #include "config.h"
33 #include "core/platform/graphics/FontPlatformData.h" 33 #include "core/platform/graphics/FontPlatformData.h"
34 34
35 #include <windows.h> 35 #include <windows.h>
36 #include <mlang.h> 36 #include <mlang.h>
37 #include <objidl.h> 37 #include <objidl.h>
38 #include "core/platform/LayoutTestSupport.h"
38 #include "core/platform/SharedBuffer.h" 39 #include "core/platform/SharedBuffer.h"
39 #include "core/platform/graphics/FontCache.h" 40 #include "core/platform/graphics/FontCache.h"
40 #include "core/platform/graphics/skia/SkiaFontWin.h" 41 #include "core/platform/graphics/skia/SkiaFontWin.h"
41 #include "core/platform/win/HWndDC.h" 42 #include "core/platform/win/HWndDC.h"
42 #include "public/platform/Platform.h" 43 #include "public/platform/Platform.h"
43 #include "public/platform/win/WebSandboxSupport.h" 44 #include "public/platform/win/WebSandboxSupport.h"
44 #include "third_party/skia/include/core/SkPaint.h" 45 #include "third_party/skia/include/core/SkPaint.h"
45 #include "third_party/skia/include/core/SkTypeface.h" 46 #include "third_party/skia/include/core/SkTypeface.h"
46 #include "third_party/skia/include/ports/SkTypeface_win.h" 47 #include "third_party/skia/include/ports/SkTypeface_win.h"
47 #include "wtf/PassOwnPtr.h" 48 #include "wtf/PassOwnPtr.h"
(...skipping 27 matching lines...) Expand all
75 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothType, 0 )) { 76 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothType, 0 )) {
76 if (FE_FONTSMOOTHINGCLEARTYPE == smoothType) 77 if (FE_FONTSMOOTHINGCLEARTYPE == smoothType)
77 gFlags |= SkPaint::kLCDRenderText_Flag; 78 gFlags |= SkPaint::kLCDRenderText_Flag;
78 } 79 }
79 } 80 }
80 gInited = true; 81 gInited = true;
81 } 82 }
82 return gFlags; 83 return gFlags;
83 } 84 }
84 85
86 static bool isWebFont(const LOGFONT& lf)
87 {
88 // web-fonts have artifical names constructed to always be
89 // 1. 24 characters, followed by a '\0'
90 // 2. the last two characters are '=='
f(malita) 2013/09/13 15:28:02 Don't know much about LOGFONT, but I assume lfFace
91 return '=' == lf.lfFaceName[22] && '=' == lf.lfFaceName[23] && '\0' == lf.lf FaceName[24];
92 }
93
85 static int computePaintTextFlags(const LOGFONT& lf) 94 static int computePaintTextFlags(const LOGFONT& lf)
86 { 95 {
87 int textFlags = 0; 96 int textFlags = 0;
88 switch (lf.lfQuality) { 97 switch (lf.lfQuality) {
89 case NONANTIALIASED_QUALITY: 98 case NONANTIALIASED_QUALITY:
90 textFlags = 0; 99 textFlags = 0;
91 break; 100 break;
92 case ANTIALIASED_QUALITY: 101 case ANTIALIASED_QUALITY:
93 textFlags = SkPaint::kAntiAlias_Flag; 102 textFlags = SkPaint::kAntiAlias_Flag;
94 break; 103 break;
95 case CLEARTYPE_QUALITY: 104 case CLEARTYPE_QUALITY:
96 textFlags = (SkPaint::kAntiAlias_Flag | SkPaint::kLCDRenderText_Flag); 105 textFlags = (SkPaint::kAntiAlias_Flag | SkPaint::kLCDRenderText_Flag);
97 break; 106 break;
98 default: 107 default:
99 textFlags = getDefaultGDITextFlags(); 108 textFlags = getDefaultGDITextFlags();
100 break; 109 break;
101 } 110 }
102 111
103 // only allow features that SystemParametersInfo allows 112 // only allow features that SystemParametersInfo allows
104 return textFlags & getDefaultGDITextFlags(); 113 textFlags &= getDefaultGDITextFlags();
114
115 /*
116 * FontPlatformData(...) will read our logfont, and try to honor the the lf Quality
117 * setting (computing the corresponding SkPaint flags for AA and LCD). Howe ver, it
118 * will limit the quality based on its query of SPI_GETFONTSMOOTHING. This could mean
119 * we end up drawing the text in BW, even though our lfQuality requested an tialiasing.
120 *
121 * Many web-fonts are so poorly hinted that they are terrible to read when drawn in BW.
122 * In these cases, we have decided to FORCE these fonts to be drawn with at least grayscale AA,
123 * even when the System (getDefaultGDITextFlags) tells us to draw only in B W.
124 */
125 if (isWebFont(lf) && !isRunningLayoutTest())
126 textFlags |= SkPaint::kAntiAlias_Flag;
127 return textFlags;
105 } 128 }
106 129
107 PassRefPtr<SkTypeface> CreateTypefaceFromHFont(HFONT hfont, int* size, int* pain tTextFlags) 130 PassRefPtr<SkTypeface> CreateTypefaceFromHFont(HFONT hfont, int* size, int* pain tTextFlags)
108 { 131 {
109 LOGFONT info; 132 LOGFONT info;
110 GetObject(hfont, sizeof(info), &info); 133 GetObject(hfont, sizeof(info), &info);
111 if (size) { 134 if (size) {
112 int height = info.lfHeight; 135 int height = info.lfHeight;
113 if (height < 0) 136 if (height < 0)
114 height = -height; 137 height = -height;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 333
311 bool FontPlatformData::ensureFontLoaded(HFONT font) 334 bool FontPlatformData::ensureFontLoaded(HFONT font)
312 { 335 {
313 WebKit::WebSandboxSupport* sandboxSupport = WebKit::Platform::current()->san dboxSupport(); 336 WebKit::WebSandboxSupport* sandboxSupport = WebKit::Platform::current()->san dboxSupport();
314 // if there is no sandbox, then we can assume the font 337 // if there is no sandbox, then we can assume the font
315 // was able to be loaded successfully already 338 // was able to be loaded successfully already
316 return sandboxSupport ? sandboxSupport->ensureFontLoaded(font) : true; 339 return sandboxSupport ? sandboxSupport->ensureFontLoaded(font) : true;
317 } 340 }
318 341
319 } 342 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698