OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are met: | 5 * modification, are permitted provided that the following conditions are met: |
6 * | 6 * |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 if (!resolveFontStyle(fontString, font)) | 305 if (!resolveFontStyle(fontString, font)) |
306 return false; | 306 return false; |
307 for (const FontFamily* f = &font.family(); f; f = f->next()) { | 307 for (const FontFamily* f = &font.family(); f; f = f->next()) { |
308 CSSSegmentedFontFace* face = m_document->styleResolver()->fontSelector()
->getFontFace(font.fontDescription(), f->family()); | 308 CSSSegmentedFontFace* face = m_document->styleResolver()->fontSelector()
->getFontFace(font.fontDescription(), f->family()); |
309 if (!face || !face->checkFont()) | 309 if (!face || !face->checkFont()) |
310 return false; | 310 return false; |
311 } | 311 } |
312 return true; | 312 return true; |
313 } | 313 } |
314 | 314 |
315 static void applyPropertyToCurrentStyle(StyleResolver* styleResolver, CSSPropert
yID id, const RefPtr<StylePropertySet>& parsedStyle) | |
316 { | |
317 styleResolver->applyPropertyToCurrentStyle(id, parsedStyle->getPropertyCSSVa
lue(id).get()); | |
318 } | |
319 | |
320 bool FontLoader::resolveFontStyle(const String& fontString, Font& font) | 315 bool FontLoader::resolveFontStyle(const String& fontString, Font& font) |
321 { | 316 { |
322 // Interpret fontString in the same way as the 'font' attribute of CanvasRen
deringContext2D. | 317 // Interpret fontString in the same way as the 'font' attribute of CanvasRen
deringContext2D. |
323 RefPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::creat
e(); | 318 RefPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::creat
e(); |
324 CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, fontString, true,
CSSStrictMode, 0); | 319 CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, fontString, true,
CSSStrictMode, 0); |
325 if (parsedStyle->isEmpty()) | 320 if (parsedStyle->isEmpty()) |
326 return false; | 321 return false; |
327 | 322 |
328 String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont); | 323 String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont); |
329 if (fontValue == "inherit" || fontValue == "initial") | 324 if (fontValue == "inherit" || fontValue == "initial") |
330 return false; | 325 return false; |
331 | 326 |
332 RefPtr<RenderStyle> style = RenderStyle::create(); | 327 RefPtr<RenderStyle> style = RenderStyle::create(); |
333 | 328 |
334 FontFamily fontFamily; | 329 FontFamily fontFamily; |
335 fontFamily.setFamily(defaultFontFamily); | 330 fontFamily.setFamily(defaultFontFamily); |
336 | 331 |
337 FontDescription defaultFontDescription; | 332 FontDescription defaultFontDescription; |
338 defaultFontDescription.setFamily(fontFamily); | 333 defaultFontDescription.setFamily(fontFamily); |
339 defaultFontDescription.setSpecifiedSize(defaultFontSize); | 334 defaultFontDescription.setSpecifiedSize(defaultFontSize); |
340 defaultFontDescription.setComputedSize(defaultFontSize); | 335 defaultFontDescription.setComputedSize(defaultFontSize); |
341 | 336 |
342 style->setFontDescription(defaultFontDescription); | 337 style->setFontDescription(defaultFontDescription); |
343 | 338 |
344 style->font().update(style->font().fontSelector()); | 339 style->font().update(style->font().fontSelector()); |
345 | 340 |
346 // Now map the font property longhands into the style. | 341 // Now map the font property longhands into the style. |
| 342 StyleResolver::PropertyValue properties[] = { |
| 343 StyleResolver::PropertyValue(CSSPropertyFontFamily, *parsedStyle), |
| 344 StyleResolver::PropertyValue(CSSPropertyFontStyle, *parsedStyle), |
| 345 StyleResolver::PropertyValue(CSSPropertyFontVariant, *parsedStyle), |
| 346 StyleResolver::PropertyValue(CSSPropertyFontWeight, *parsedStyle), |
| 347 StyleResolver::PropertyValue(CSSPropertyFontSize, *parsedStyle), |
| 348 StyleResolver::PropertyValue(CSSPropertyLineHeight, *parsedStyle), |
| 349 }; |
347 StyleResolver* styleResolver = m_document->styleResolver(); | 350 StyleResolver* styleResolver = m_document->styleResolver(); |
348 styleResolver->applyPropertyToStyle(CSSPropertyFontFamily, parsedStyle->getP
ropertyCSSValue(CSSPropertyFontFamily).get(), style.get()); | 351 styleResolver->applyPropertiesToStyle(properties, arraysize(properties), sty
le.get()); |
349 applyPropertyToCurrentStyle(styleResolver, CSSPropertyFontStyle, parsedStyle
); | |
350 applyPropertyToCurrentStyle(styleResolver, CSSPropertyFontVariant, parsedSty
le); | |
351 applyPropertyToCurrentStyle(styleResolver, CSSPropertyFontWeight, parsedStyl
e); | |
352 | |
353 // As described in BUG66291, setting font-size and line-height on a font may
entail a CSSPrimitiveValue::computeLengthDouble call, | |
354 // which assumes the fontMetrics are available for the affected font, otherw
ise a crash occurs (see http://trac.webkit.org/changeset/96122). | |
355 // The updateFont() calls below update the fontMetrics and ensure the proper
setting of font-size and line-height. | |
356 styleResolver->updateFont(); | |
357 applyPropertyToCurrentStyle(styleResolver, CSSPropertyFontSize, parsedStyle)
; | |
358 styleResolver->updateFont(); | |
359 applyPropertyToCurrentStyle(styleResolver, CSSPropertyLineHeight, parsedStyl
e); | |
360 | 352 |
361 font = style->font(); | 353 font = style->font(); |
362 font.update(styleResolver->fontSelector()); | 354 font.update(styleResolver->fontSelector()); |
363 return true; | 355 return true; |
364 } | 356 } |
365 | 357 |
366 void FontLoader::FontLoadHistogram::record() | 358 void FontLoader::FontLoadHistogram::record() |
367 { | 359 { |
368 if (m_recorded) | 360 if (m_recorded) |
369 return; | 361 return; |
370 m_recorded = true; | 362 m_recorded = true; |
371 HistogramSupport::histogramCustomCounts("WebFont.WebFontsInPage", m_count, 1
, 100, 50); | 363 HistogramSupport::histogramCustomCounts("WebFont.WebFontsInPage", m_count, 1
, 100, 50); |
372 } | 364 } |
373 | 365 |
374 } // namespace WebCore | 366 } // namespace WebCore |
OLD | NEW |