OLD | NEW |
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 Loading... |
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(String fontFamilyName) |
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 Loading... |
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(fontFamilyName()); |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation or
ientation, | 243 float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation or
ientation, |
268 bool useSubpixelPositioning) | 244 bool useSubpixelPositioning) |
269 : m_textSize(textSize) | 245 : m_textSize(textSize) |
270 , m_syntheticBold(syntheticBold) | 246 , m_syntheticBold(syntheticBold) |
271 , m_syntheticItalic(syntheticItalic) | 247 , m_syntheticItalic(syntheticItalic) |
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 { |
| 253 m_paintTextFlags = computePaintTextFlags(fontFamilyName()); |
| 254 #if !USE(HARFBUZZ) |
277 // FIXME: This can be removed together with m_font once the last few | 255 // FIXME: This can be removed together with m_font once the last few |
278 // uses of hfont() has been eliminated. | 256 // uses of hfont() has been eliminated. |
279 LOGFONT logFont; | 257 LOGFONT logFont; |
280 SkLOGFONTFromTypeface(m_typeface.get(), &logFont); | 258 SkLOGFONTFromTypeface(m_typeface.get(), &logFont); |
281 logFont.lfHeight = -textSize; | 259 logFont.lfHeight = -textSize; |
282 m_paintTextFlags = computePaintTextFlags(logFont); | |
283 | |
284 #if !USE(HARFBUZZ) | |
285 HFONT hFont = CreateFontIndirect(&logFont); | 260 HFONT hFont = CreateFontIndirect(&logFont); |
286 m_font = hFont ? RefCountedHFONT::create(hFont) : 0; | 261 m_font = hFont ? RefCountedHFONT::create(hFont) : 0; |
287 m_scriptCache = 0; | 262 m_scriptCache = 0; |
288 #endif | 263 #endif |
289 } | 264 } |
290 | 265 |
291 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data) | 266 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data) |
292 { | 267 { |
293 if (this != &data) { | 268 if (this != &data) { |
294 m_textSize = data.m_textSize; | 269 m_textSize = data.m_textSize; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 414 } |
440 | 415 |
441 #ifndef NDEBUG | 416 #ifndef NDEBUG |
442 String FontPlatformData::description() const | 417 String FontPlatformData::description() const |
443 { | 418 { |
444 return String(); | 419 return String(); |
445 } | 420 } |
446 #endif | 421 #endif |
447 | 422 |
448 } // namespace WebCore | 423 } // namespace WebCore |
OLD | NEW |