Chromium Code Reviews| 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() |
|
bungeman-chromium
2013/12/09 15:29:58
I have no real issue with this renaming, but note
| |
| 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 int FontPlatformData::paintTextFlags() const |
| 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()) |
|
bungeman-chromium
2014/02/10 20:59:57
Hopefully getting the family name here doesn't tak
bungeman-skia
2014/02/10 23:16:15
Yep, this is it. Doing the work of actually diggin
| |
| 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_fakeBold(false) | 147 , m_fakeBold(false) |
| 173 , m_fakeItalic(false) | 148 , m_fakeItalic(false) |
| 174 , m_orientation(Horizontal) | 149 , m_orientation(Horizontal) |
| 175 , m_typeface(adoptRef(SkTypeface::RefDefault())) | 150 , m_typeface(adoptRef(SkTypeface::RefDefault())) |
| 176 , m_paintTextFlags(0) | |
| 177 , m_isHashTableDeletedValue(true) | 151 , m_isHashTableDeletedValue(true) |
| 178 , m_useSubpixelPositioning(false) | 152 , m_useSubpixelPositioning(false) |
| 179 { | 153 { |
| 180 #if !USE(HARFBUZZ) | 154 #if !USE(HARFBUZZ) |
| 181 m_font = 0; | 155 m_font = 0; |
| 182 m_scriptCache = 0; | 156 m_scriptCache = 0; |
| 183 #endif | 157 #endif |
| 184 } | 158 } |
| 185 | 159 |
| 186 FontPlatformData::FontPlatformData() | 160 FontPlatformData::FontPlatformData() |
| 187 : m_textSize(0) | 161 : m_textSize(0) |
| 188 , m_fakeBold(false) | 162 , m_fakeBold(false) |
| 189 , m_fakeItalic(false) | 163 , m_fakeItalic(false) |
| 190 , m_orientation(Horizontal) | 164 , m_orientation(Horizontal) |
| 191 , m_typeface(adoptRef(SkTypeface::RefDefault())) | 165 , m_typeface(adoptRef(SkTypeface::RefDefault())) |
| 192 , m_paintTextFlags(0) | |
|
bungeman-chromium
2014/02/10 20:59:57
It seems like the paintTextFlags were often 0 (mon
| |
| 193 , m_isHashTableDeletedValue(false) | 166 , m_isHashTableDeletedValue(false) |
| 194 , m_useSubpixelPositioning(false) | 167 , m_useSubpixelPositioning(false) |
| 195 { | 168 { |
| 196 #if !USE(HARFBUZZ) | 169 #if !USE(HARFBUZZ) |
| 197 m_font = 0; | 170 m_font = 0; |
| 198 m_scriptCache = 0; | 171 m_scriptCache = 0; |
| 199 #endif | 172 #endif |
| 200 } | 173 } |
| 201 | 174 |
| 202 #if ENABLE(GDI_FONTS_ON_WINDOWS) && !USE(HARFBUZZ) | 175 #if ENABLE(GDI_FONTS_ON_WINDOWS) && !USE(HARFBUZZ) |
| 203 FontPlatformData::FontPlatformData(HFONT font, float size, FontOrientation orien tation) | 176 FontPlatformData::FontPlatformData(HFONT font, float size, FontOrientation orien tation) |
| 204 : m_font(RefCountedHFONT::create(font)) | 177 : m_font(RefCountedHFONT::create(font)) |
| 205 , m_textSize(size) | 178 , m_textSize(size) |
| 206 , m_fakeBold(false) | 179 , m_fakeBold(false) |
| 207 , m_fakeItalic(false) | 180 , m_fakeItalic(false) |
| 208 , m_orientation(orientation) | 181 , m_orientation(orientation) |
| 209 , m_scriptCache(0) | 182 , m_scriptCache(0) |
| 210 , m_typeface(CreateTypefaceFromHFont(font, 0, &m_paintTextFlags)) | 183 , m_typeface(CreateTypefaceFromHFont(font, 0)) |
| 211 , m_isHashTableDeletedValue(false) | 184 , m_isHashTableDeletedValue(false) |
| 212 , m_useSubpixelPositioning(false) | 185 , m_useSubpixelPositioning(false) |
| 213 { | 186 { |
| 214 } | 187 } |
| 215 #endif | 188 #endif |
| 216 | 189 |
| 217 // FIXME: this constructor is needed for SVG fonts but doesn't seem to do much | 190 // FIXME: this constructor is needed for SVG fonts but doesn't seem to do much |
| 218 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) | 191 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) |
| 219 : m_textSize(size) | 192 : m_textSize(size) |
| 220 , m_fakeBold(false) | 193 , m_fakeBold(false) |
| 221 , m_fakeItalic(false) | 194 , m_fakeItalic(false) |
| 222 , m_orientation(Horizontal) | 195 , m_orientation(Horizontal) |
| 223 , m_typeface(adoptRef(SkTypeface::RefDefault())) | 196 , m_typeface(adoptRef(SkTypeface::RefDefault())) |
| 224 , m_paintTextFlags(0) | |
| 225 , m_isHashTableDeletedValue(false) | 197 , m_isHashTableDeletedValue(false) |
| 226 , m_useSubpixelPositioning(false) | 198 , m_useSubpixelPositioning(false) |
| 227 { | 199 { |
| 228 #if !USE(HARFBUZZ) | 200 #if !USE(HARFBUZZ) |
| 229 m_font = 0; | 201 m_font = 0; |
| 230 m_scriptCache = 0; | 202 m_scriptCache = 0; |
| 231 #endif | 203 #endif |
| 232 } | 204 } |
| 233 | 205 |
| 234 FontPlatformData::FontPlatformData(const FontPlatformData& data) | 206 FontPlatformData::FontPlatformData(const FontPlatformData& data) |
| 235 : m_textSize(data.m_textSize) | 207 : m_textSize(data.m_textSize) |
| 236 , m_fakeBold(data.m_fakeBold) | 208 , m_fakeBold(data.m_fakeBold) |
| 237 , m_fakeItalic(data.m_fakeItalic) | 209 , m_fakeItalic(data.m_fakeItalic) |
| 238 , m_orientation(data.m_orientation) | 210 , m_orientation(data.m_orientation) |
| 239 , m_typeface(data.m_typeface) | 211 , m_typeface(data.m_typeface) |
| 240 , m_paintTextFlags(data.m_paintTextFlags) | |
| 241 , m_isHashTableDeletedValue(false) | 212 , m_isHashTableDeletedValue(false) |
| 242 , m_useSubpixelPositioning(data.m_useSubpixelPositioning) | 213 , m_useSubpixelPositioning(data.m_useSubpixelPositioning) |
| 243 { | 214 { |
| 244 #if !USE(HARFBUZZ) | 215 #if !USE(HARFBUZZ) |
| 245 m_font = data.m_font; | 216 m_font = data.m_font; |
| 246 m_scriptCache = 0; | 217 m_scriptCache = 0; |
| 247 #endif | 218 #endif |
| 248 } | 219 } |
| 249 | 220 |
| 250 FontPlatformData::FontPlatformData(const FontPlatformData& data, float textSize) | 221 FontPlatformData::FontPlatformData(const FontPlatformData& data, float textSize) |
| 251 : m_textSize(textSize) | 222 : m_textSize(textSize) |
| 252 , m_fakeBold(data.m_fakeBold) | 223 , m_fakeBold(data.m_fakeBold) |
| 253 , m_fakeItalic(data.m_fakeItalic) | 224 , m_fakeItalic(data.m_fakeItalic) |
| 254 , m_orientation(data.m_orientation) | 225 , m_orientation(data.m_orientation) |
| 255 , m_typeface(data.m_typeface) | 226 , m_typeface(data.m_typeface) |
| 256 , m_paintTextFlags(data.m_paintTextFlags) | |
| 257 , m_isHashTableDeletedValue(false) | 227 , m_isHashTableDeletedValue(false) |
| 258 , m_useSubpixelPositioning(data.m_useSubpixelPositioning) | 228 , m_useSubpixelPositioning(data.m_useSubpixelPositioning) |
| 259 { | 229 { |
| 260 #if !USE(HARFBUZZ) | 230 #if !USE(HARFBUZZ) |
| 261 m_font = data.m_font; | 231 m_font = data.m_font; |
| 262 m_scriptCache = 0; | 232 m_scriptCache = 0; |
| 263 #endif | 233 #endif |
| 264 } | 234 } |
| 265 | 235 |
| 266 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family , | 236 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family , |
| 267 float textSize, bool fakeBold, bool fakeItalic, FontOrientation orientation, | 237 float textSize, bool fakeBold, bool fakeItalic, FontOrientation orientation, |
| 268 bool useSubpixelPositioning) | 238 bool useSubpixelPositioning) |
| 269 : m_textSize(textSize) | 239 : m_textSize(textSize) |
| 270 , m_fakeBold(fakeBold) | 240 , m_fakeBold(fakeBold) |
| 271 , m_fakeItalic(fakeItalic) | 241 , m_fakeItalic(fakeItalic) |
| 272 , m_orientation(orientation) | 242 , m_orientation(orientation) |
| 273 , m_typeface(tf) | 243 , m_typeface(tf) |
| 274 , m_isHashTableDeletedValue(false) | 244 , m_isHashTableDeletedValue(false) |
| 275 , m_useSubpixelPositioning(useSubpixelPositioning) | 245 , m_useSubpixelPositioning(useSubpixelPositioning) |
| 276 { | 246 { |
| 277 // FIXME: This can be removed together with m_font once the last few | 247 // FIXME: This can be removed together with m_font once the last few |
| 278 // uses of hfont() has been eliminated. | 248 // uses of hfont() has been eliminated. |
| 279 LOGFONT logFont; | 249 LOGFONT logFont; |
| 280 SkLOGFONTFromTypeface(m_typeface.get(), &logFont); | 250 SkLOGFONTFromTypeface(m_typeface.get(), &logFont); |
| 281 logFont.lfHeight = -textSize; | 251 logFont.lfHeight = -textSize; |
| 282 m_paintTextFlags = computePaintTextFlags(logFont); | |
|
bungeman-chromium
2014/02/10 20:59:57
Note that here 'logFont' would always be CLEARTYPE
| |
| 283 | 252 |
| 284 #if !USE(HARFBUZZ) | 253 #if !USE(HARFBUZZ) |
| 285 HFONT hFont = CreateFontIndirect(&logFont); | 254 HFONT hFont = CreateFontIndirect(&logFont); |
| 286 m_font = hFont ? RefCountedHFONT::create(hFont) : 0; | 255 m_font = hFont ? RefCountedHFONT::create(hFont) : 0; |
| 287 m_scriptCache = 0; | 256 m_scriptCache = 0; |
| 288 #endif | 257 #endif |
| 289 } | 258 } |
| 290 | 259 |
| 291 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data) | 260 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& data) |
| 292 { | 261 { |
| 293 if (this != &data) { | 262 if (this != &data) { |
| 294 m_textSize = data.m_textSize; | 263 m_textSize = data.m_textSize; |
| 295 m_fakeBold = data.m_fakeBold; | 264 m_fakeBold = data.m_fakeBold; |
| 296 m_fakeItalic = data.m_fakeItalic; | 265 m_fakeItalic = data.m_fakeItalic; |
| 297 m_orientation = data.m_orientation; | 266 m_orientation = data.m_orientation; |
| 298 m_typeface = data.m_typeface; | 267 m_typeface = data.m_typeface; |
| 299 m_paintTextFlags = data.m_paintTextFlags; | |
| 300 | 268 |
| 301 #if !USE(HARFBUZZ) | 269 #if !USE(HARFBUZZ) |
| 302 m_font = data.m_font; | 270 m_font = data.m_font; |
| 303 // The following fields will get re-computed if necessary. | 271 // The following fields will get re-computed if necessary. |
| 304 ScriptFreeCache(&m_scriptCache); | 272 ScriptFreeCache(&m_scriptCache); |
| 305 m_scriptCache = 0; | 273 m_scriptCache = 0; |
| 306 m_scriptFontProperties.clear(); | 274 m_scriptFontProperties.clear(); |
| 307 #endif | 275 #endif |
| 308 } | 276 } |
| 309 return *this; | 277 return *this; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 322 #if ENABLE(GDI_FONTS_ON_WINDOWS) | 290 #if ENABLE(GDI_FONTS_ON_WINDOWS) |
| 323 HWndDC dc(0); | 291 HWndDC dc(0); |
| 324 HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(dc, hfont())); | 292 HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(dc, hfont())); |
| 325 WCHAR name[LF_FACESIZE]; | 293 WCHAR name[LF_FACESIZE]; |
| 326 unsigned resultLength = GetTextFace(dc, LF_FACESIZE, name); | 294 unsigned resultLength = GetTextFace(dc, LF_FACESIZE, name); |
| 327 if (resultLength > 0) | 295 if (resultLength > 0) |
| 328 resultLength--; // ignore the null terminator | 296 resultLength--; // ignore the null terminator |
| 329 SelectObject(dc, oldFont); | 297 SelectObject(dc, oldFont); |
| 330 return String(name, resultLength); | 298 return String(name, resultLength); |
| 331 #else | 299 #else |
| 332 // FIXME: This returns the requested name, perhaps a better solution would b e to | 300 // FIXME: This returns the requested name, perhaps a better solution would b e to |
|
bungeman-chromium
2014/02/10 20:59:57
Actually, this FIXME isn't true anymore on GDI. Un
| |
| 333 // return the list of names provided by SkTypeface::createFamilyNameIterator . | 301 // return the list of names provided by SkTypeface::createFamilyNameIterator . |
| 334 ASSERT(typeface()); | 302 ASSERT(typeface()); |
| 335 SkString familyName; | 303 SkString familyName; |
| 336 typeface()->getFamilyName(&familyName); | 304 typeface()->getFamilyName(&familyName); |
| 337 return String::fromUTF8(familyName.c_str()); | 305 return String::fromUTF8(familyName.c_str()); |
| 338 #endif | 306 #endif |
| 339 } | 307 } |
| 340 | 308 |
| 341 bool FontPlatformData::isFixedPitch() const | 309 bool FontPlatformData::isFixedPitch() const |
| 342 { | 310 { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 #endif | 398 #endif |
| 431 | 399 |
| 432 #ifndef NDEBUG | 400 #ifndef NDEBUG |
| 433 String FontPlatformData::description() const | 401 String FontPlatformData::description() const |
| 434 { | 402 { |
| 435 return String(); | 403 return String(); |
| 436 } | 404 } |
| 437 #endif | 405 #endif |
| 438 | 406 |
| 439 } | 407 } |
| OLD | NEW |