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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 , m_paintTextFlags(0) | 167 , m_paintTextFlags(0) |
168 , m_isHashTableDeletedValue(false) | 168 , m_isHashTableDeletedValue(false) |
169 , m_useSubpixelPositioning(false) | 169 , m_useSubpixelPositioning(false) |
170 { | 170 { |
171 #if !USE(HARFBUZZ) | 171 #if !USE(HARFBUZZ) |
172 m_font = 0; | 172 m_font = 0; |
173 m_scriptCache = 0; | 173 m_scriptCache = 0; |
174 #endif | 174 #endif |
175 } | 175 } |
176 | 176 |
177 #if ENABLE(GDI_FONTS_ON_WINDOWS) && !USE(HARFBUZZ) | |
178 FontPlatformData::FontPlatformData(HFONT font, float size, FontOrientation orien
tation) | |
179 : m_font(RefCountedHFONT::create(font)) | |
180 , m_textSize(size) | |
181 , m_syntheticBold(false) | |
182 , m_syntheticItalic(false) | |
183 , m_orientation(orientation) | |
184 , m_scriptCache(0) | |
185 , m_typeface(CreateTypefaceFromHFont(font, 0)) | |
186 , m_isHashTableDeletedValue(false) | |
187 , m_useSubpixelPositioning(false) | |
188 { | |
189 m_paintTextFlags = computePaintTextFlags(fontFamilyName()); | |
190 } | |
191 #endif | |
192 | |
193 // FIXME: this constructor is needed for SVG fonts but doesn't seem to do much | 177 // FIXME: this constructor is needed for SVG fonts but doesn't seem to do much |
194 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) | 178 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) |
195 : m_textSize(size) | 179 : m_textSize(size) |
196 , m_syntheticBold(false) | 180 , m_syntheticBold(false) |
197 , m_syntheticItalic(false) | 181 , m_syntheticItalic(false) |
198 , m_orientation(Horizontal) | 182 , m_orientation(Horizontal) |
199 , m_typeface(adoptRef(SkTypeface::RefDefault())) | 183 , m_typeface(adoptRef(SkTypeface::RefDefault())) |
200 , m_paintTextFlags(0) | 184 , m_paintTextFlags(0) |
201 , m_isHashTableDeletedValue(false) | 185 , m_isHashTableDeletedValue(false) |
202 , m_useSubpixelPositioning(false) | 186 , m_useSubpixelPositioning(false) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 FontPlatformData::~FontPlatformData() | 271 FontPlatformData::~FontPlatformData() |
288 { | 272 { |
289 #if !USE(HARFBUZZ) | 273 #if !USE(HARFBUZZ) |
290 ScriptFreeCache(&m_scriptCache); | 274 ScriptFreeCache(&m_scriptCache); |
291 m_scriptCache = 0; | 275 m_scriptCache = 0; |
292 #endif | 276 #endif |
293 } | 277 } |
294 | 278 |
295 String FontPlatformData::fontFamilyName() const | 279 String FontPlatformData::fontFamilyName() const |
296 { | 280 { |
297 #if ENABLE(GDI_FONTS_ON_WINDOWS) | |
298 HWndDC dc(0); | |
299 HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(dc, hfont())); | |
300 WCHAR name[LF_FACESIZE]; | |
301 unsigned resultLength = GetTextFace(dc, LF_FACESIZE, name); | |
302 if (resultLength > 0) | |
303 resultLength--; // ignore the null terminator | |
304 SelectObject(dc, oldFont); | |
305 return String(name, resultLength); | |
306 #else | |
307 // FIXME: This returns the requested name, perhaps a better solution would b
e to | 281 // FIXME: This returns the requested name, perhaps a better solution would b
e to |
308 // return the list of names provided by SkTypeface::createFamilyNameIterator
. | 282 // return the list of names provided by SkTypeface::createFamilyNameIterator
. |
309 ASSERT(typeface()); | 283 ASSERT(typeface()); |
310 SkString familyName; | 284 SkString familyName; |
311 typeface()->getFamilyName(&familyName); | 285 typeface()->getFamilyName(&familyName); |
312 return String::fromUTF8(familyName.c_str()); | 286 return String::fromUTF8(familyName.c_str()); |
313 #endif | |
314 } | 287 } |
315 | 288 |
316 bool FontPlatformData::isFixedPitch() const | 289 bool FontPlatformData::isFixedPitch() const |
317 { | 290 { |
318 #if ENABLE(GDI_FONTS_ON_WINDOWS) | |
319 // TEXTMETRICS have this. Set m_treatAsFixedPitch based off that. | |
320 HWndDC dc(0); | |
321 HGDIOBJ oldFont = SelectObject(dc, hfont()); | |
322 | |
323 // Yes, this looks backwards, but the fixed pitch bit is actually set if the
font | |
324 // is *not* fixed pitch. Unbelievable but true. | |
325 TEXTMETRIC textMetric = { 0 }; | |
326 if (!GetTextMetrics(dc, &textMetric)) { | |
327 if (ensureFontLoaded(hfont())) { | |
328 // Retry GetTextMetrics. | |
329 // FIXME: Handle gracefully the error if this call also fails. | |
330 // See http://crbug.com/6401. | |
331 if (!GetTextMetrics(dc, &textMetric)) | |
332 WTF_LOG_ERROR("Unable to get the text metrics after second attem
pt"); | |
333 } | |
334 } | |
335 | |
336 bool treatAsFixedPitch = !(textMetric.tmPitchAndFamily & TMPF_FIXED_PITCH); | |
337 | |
338 SelectObject(dc, oldFont); | |
339 | |
340 return treatAsFixedPitch; | |
341 #else | |
342 return typeface() && typeface()->isFixedPitch(); | 291 return typeface() && typeface()->isFixedPitch(); |
343 #endif | |
344 } | 292 } |
345 | 293 |
346 bool FontPlatformData::operator==(const FontPlatformData& a) const | 294 bool FontPlatformData::operator==(const FontPlatformData& a) const |
347 { | 295 { |
348 return SkTypeface::Equal(m_typeface.get(), a.m_typeface.get()) | 296 return SkTypeface::Equal(m_typeface.get(), a.m_typeface.get()) |
349 && m_textSize == a.m_textSize | 297 && m_textSize == a.m_textSize |
350 && m_syntheticBold == a.m_syntheticBold | 298 && m_syntheticBold == a.m_syntheticBold |
351 && m_syntheticItalic == a.m_syntheticItalic | 299 && m_syntheticItalic == a.m_syntheticItalic |
352 && m_orientation == a.m_orientation | 300 && m_orientation == a.m_orientation |
353 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue; | 301 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 { | 347 { |
400 blink::WebSandboxSupport* sandboxSupport = blink::Platform::current()->sandb
oxSupport(); | 348 blink::WebSandboxSupport* sandboxSupport = blink::Platform::current()->sandb
oxSupport(); |
401 // if there is no sandbox, then we can assume the font | 349 // if there is no sandbox, then we can assume the font |
402 // was able to be loaded successfully already | 350 // was able to be loaded successfully already |
403 return sandboxSupport ? sandboxSupport->ensureFontLoaded(font) : true; | 351 return sandboxSupport ? sandboxSupport->ensureFontLoaded(font) : true; |
404 } | 352 } |
405 #endif | 353 #endif |
406 | 354 |
407 bool FontPlatformData::defaultUseSubpixelPositioning() | 355 bool FontPlatformData::defaultUseSubpixelPositioning() |
408 { | 356 { |
409 #if OS(WIN) && !ENABLE(GDI_FONTS_ON_WINDOWS) | 357 #if OS(WIN) |
410 return FontCache::fontCache()->useSubpixelPositioning(); | 358 return FontCache::fontCache()->useSubpixelPositioning(); |
411 #else | 359 #else |
412 return false; | 360 return false; |
413 #endif | 361 #endif |
414 } | 362 } |
415 | 363 |
416 #ifndef NDEBUG | 364 #ifndef NDEBUG |
417 String FontPlatformData::description() const | 365 String FontPlatformData::description() const |
418 { | 366 { |
419 return String(); | 367 return String(); |
420 } | 368 } |
421 #endif | 369 #endif |
422 | 370 |
423 } // namespace WebCore | 371 } // namespace WebCore |
OLD | NEW |