| 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 { | 332 { |
| 333 Vector<RefPtr<FontFace> > matchedFonts; | 333 Vector<RefPtr<FontFace> > matchedFonts; |
| 334 | 334 |
| 335 Font font; | 335 Font font; |
| 336 if (!resolveFontStyle(fontString, font)) { | 336 if (!resolveFontStyle(fontString, font)) { |
| 337 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); | 337 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); |
| 338 return matchedFonts; | 338 return matchedFonts; |
| 339 } | 339 } |
| 340 | 340 |
| 341 for (const FontFamily* f = &font.family(); f; f = f->next()) { | 341 for (const FontFamily* f = &font.family(); f; f = f->next()) { |
| 342 CSSSegmentedFontFace* face = document()->styleResolver()->fontSelector()
->getFontFace(font.fontDescription(), f->family()); | 342 CSSSegmentedFontFace* face = document()->fontSelector()->getFontFace(fon
t.fontDescription(), f->family()); |
| 343 if (face) | 343 if (face) |
| 344 matchedFonts.append(face->fontFaces(nullToSpace(text))); | 344 matchedFonts.append(face->fontFaces(nullToSpace(text))); |
| 345 } | 345 } |
| 346 return matchedFonts; | 346 return matchedFonts; |
| 347 } | 347 } |
| 348 | 348 |
| 349 ScriptPromise FontFaceSet::load(const String& fontString, const String& text, Ex
ceptionState& exceptionState) | 349 ScriptPromise FontFaceSet::load(const String& fontString, const String& text, Ex
ceptionState& exceptionState) |
| 350 { | 350 { |
| 351 Font font; | 351 Font font; |
| 352 if (!resolveFontStyle(fontString, font)) { | 352 if (!resolveFontStyle(fontString, font)) { |
| 353 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); | 353 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); |
| 354 return ScriptPromise(); | 354 return ScriptPromise(); |
| 355 } | 355 } |
| 356 | 356 |
| 357 Document* d = document(); | 357 Document* d = document(); |
| 358 ScriptPromise promise = ScriptPromise::createPending(executionContext()); | 358 ScriptPromise promise = ScriptPromise::createPending(executionContext()); |
| 359 RefPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolver::create(f
ont.family(), promise, executionContext()); | 359 RefPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolver::create(f
ont.family(), promise, executionContext()); |
| 360 for (const FontFamily* f = &font.family(); f; f = f->next()) { | 360 for (const FontFamily* f = &font.family(); f; f = f->next()) { |
| 361 CSSSegmentedFontFace* face = d->styleResolver()->fontSelector()->getFont
Face(font.fontDescription(), f->family()); | 361 CSSSegmentedFontFace* face = d->fontSelector()->getFontFace(font.fontDes
cription(), f->family()); |
| 362 if (!face) { | 362 if (!face) { |
| 363 resolver->error(d); | 363 resolver->error(d); |
| 364 continue; | 364 continue; |
| 365 } | 365 } |
| 366 face->loadFont(font.fontDescription(), nullToSpace(text), resolver); | 366 face->loadFont(font.fontDescription(), nullToSpace(text), resolver); |
| 367 } | 367 } |
| 368 return promise; | 368 return promise; |
| 369 } | 369 } |
| 370 | 370 |
| 371 bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
tate& exceptionState) | 371 bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
tate& exceptionState) |
| 372 { | 372 { |
| 373 Font font; | 373 Font font; |
| 374 if (!resolveFontStyle(fontString, font)) { | 374 if (!resolveFontStyle(fontString, font)) { |
| 375 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); | 375 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); |
| 376 return false; | 376 return false; |
| 377 } | 377 } |
| 378 | 378 |
| 379 for (const FontFamily* f = &font.family(); f; f = f->next()) { | 379 for (const FontFamily* f = &font.family(); f; f = f->next()) { |
| 380 CSSSegmentedFontFace* face = document()->styleResolver()->fontSelector()
->getFontFace(font.fontDescription(), f->family()); | 380 CSSSegmentedFontFace* face = document()->fontSelector()->getFontFace(fon
t.fontDescription(), f->family()); |
| 381 if (!face || !face->checkFont(nullToSpace(text))) | 381 if (!face || !face->checkFont(nullToSpace(text))) |
| 382 return false; | 382 return false; |
| 383 } | 383 } |
| 384 return true; | 384 return true; |
| 385 } | 385 } |
| 386 | 386 |
| 387 bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font) | 387 bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font) |
| 388 { | 388 { |
| 389 if (fontString.isEmpty()) | 389 if (fontString.isEmpty()) |
| 390 return false; | 390 return false; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 419 CSSPropertyValue(CSSPropertyFontStyle, *parsedStyle), | 419 CSSPropertyValue(CSSPropertyFontStyle, *parsedStyle), |
| 420 CSSPropertyValue(CSSPropertyFontVariant, *parsedStyle), | 420 CSSPropertyValue(CSSPropertyFontVariant, *parsedStyle), |
| 421 CSSPropertyValue(CSSPropertyFontWeight, *parsedStyle), | 421 CSSPropertyValue(CSSPropertyFontWeight, *parsedStyle), |
| 422 CSSPropertyValue(CSSPropertyFontSize, *parsedStyle), | 422 CSSPropertyValue(CSSPropertyFontSize, *parsedStyle), |
| 423 CSSPropertyValue(CSSPropertyLineHeight, *parsedStyle), | 423 CSSPropertyValue(CSSPropertyLineHeight, *parsedStyle), |
| 424 }; | 424 }; |
| 425 StyleResolver* styleResolver = document()->styleResolver(); | 425 StyleResolver* styleResolver = document()->styleResolver(); |
| 426 styleResolver->applyPropertiesToStyle(properties, WTF_ARRAY_LENGTH(propertie
s), style.get()); | 426 styleResolver->applyPropertiesToStyle(properties, WTF_ARRAY_LENGTH(propertie
s), style.get()); |
| 427 | 427 |
| 428 font = style->font(); | 428 font = style->font(); |
| 429 font.update(styleResolver->fontSelector()); | 429 font.update(document()->fontSelector()); |
| 430 return true; | 430 return true; |
| 431 } | 431 } |
| 432 | 432 |
| 433 void FontFaceSet::FontLoadHistogram::record() | 433 void FontFaceSet::FontLoadHistogram::record() |
| 434 { | 434 { |
| 435 if (m_recorded) | 435 if (m_recorded) |
| 436 return; | 436 return; |
| 437 m_recorded = true; | 437 m_recorded = true; |
| 438 blink::Platform::current()->histogramCustomCounts("WebFont.WebFontsInPage",
m_count, 1, 100, 50); | 438 blink::Platform::current()->histogramCustomCounts("WebFont.WebFontsInPage",
m_count, 1, 100, 50); |
| 439 } | 439 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 455 } | 455 } |
| 456 | 456 |
| 457 void FontFaceSet::didLayout(Document* document) | 457 void FontFaceSet::didLayout(Document* document) |
| 458 { | 458 { |
| 459 if (FontFaceSet* fonts = static_cast<FontFaceSet*>(SupplementType::from(docu
ment, supplementName()))) | 459 if (FontFaceSet* fonts = static_cast<FontFaceSet*>(SupplementType::from(docu
ment, supplementName()))) |
| 460 fonts->didLayout(); | 460 fonts->didLayout(); |
| 461 } | 461 } |
| 462 | 462 |
| 463 | 463 |
| 464 } // namespace WebCore | 464 } // namespace WebCore |
| OLD | NEW |