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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 } | 424 } |
425 | 425 |
426 if (!m_readyResolvers.isEmpty()) { | 426 if (!m_readyResolvers.isEmpty()) { |
427 Vector<OwnPtr<FontsReadyPromiseResolver> > resolvers; | 427 Vector<OwnPtr<FontsReadyPromiseResolver> > resolvers; |
428 m_readyResolvers.swap(resolvers); | 428 m_readyResolvers.swap(resolvers); |
429 for (size_t index = 0; index < resolvers.size(); ++index) | 429 for (size_t index = 0; index < resolvers.size(); ++index) |
430 resolvers[index]->resolve(this); | 430 resolvers[index]->resolve(this); |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 static const String& nullToSpace(const String& s) | |
435 { | |
436 DEFINE_STATIC_LOCAL(String, space, (" ")); | |
437 return s.isNull() ? space : s; | |
438 } | |
439 | |
440 ScriptPromise FontFaceSet::load(ScriptState* scriptState, const String& fontStri
ng, const String& text) | 434 ScriptPromise FontFaceSet::load(ScriptState* scriptState, const String& fontStri
ng, const String& text) |
441 { | 435 { |
442 if (!inActiveDocumentContext()) | 436 if (!inActiveDocumentContext()) |
443 return ScriptPromise(); | 437 return ScriptPromise(); |
444 | 438 |
445 Font font; | 439 Font font; |
446 if (!resolveFontStyle(fontString, font)) { | 440 if (!resolveFontStyle(fontString, font)) { |
447 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s
criptState); | 441 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s
criptState); |
448 ScriptPromise promise = resolver->promise(); | 442 ScriptPromise promise = resolver->promise(); |
449 resolver->reject(DOMException::create(SyntaxError, "Could not resolve '"
+ fontString + "' as a font.")); | 443 resolver->reject(DOMException::create(SyntaxError, "Could not resolve '"
+ fontString + "' as a font.")); |
450 return promise; | 444 return promise; |
451 } | 445 } |
452 | 446 |
453 FontFaceCache* fontFaceCache = document()->styleEngine()->fontSelector()->fo
ntFaceCache(); | 447 FontFaceCache* fontFaceCache = document()->styleEngine()->fontSelector()->fo
ntFaceCache(); |
454 FontFaceArray faces; | 448 FontFaceArray faces; |
455 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { | 449 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { |
456 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe
scription(), f->family()); | 450 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe
scription(), f->family()); |
457 if (segmentedFontFace) | 451 if (segmentedFontFace) |
458 segmentedFontFace->match(nullToSpace(text), faces); | 452 segmentedFontFace->match(text, faces); |
459 } | 453 } |
460 | 454 |
461 RefPtrWillBeRawPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolv
er::create(faces, scriptState); | 455 RefPtrWillBeRawPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolv
er::create(faces, scriptState); |
462 ScriptPromise promise = resolver->promise(); | 456 ScriptPromise promise = resolver->promise(); |
463 resolver->loadFonts(executionContext()); // After this, resolver->promise()
may return null. | 457 resolver->loadFonts(executionContext()); // After this, resolver->promise()
may return null. |
464 return promise; | 458 return promise; |
465 } | 459 } |
466 | 460 |
467 bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
tate& exceptionState) | 461 bool FontFaceSet::check(const String& fontString, const String& text, ExceptionS
tate& exceptionState) |
468 { | 462 { |
469 if (!inActiveDocumentContext()) | 463 if (!inActiveDocumentContext()) |
470 return false; | 464 return false; |
471 | 465 |
472 Font font; | 466 Font font; |
473 if (!resolveFontStyle(fontString, font)) { | 467 if (!resolveFontStyle(fontString, font)) { |
474 exceptionState.throwDOMException(SyntaxError, "Could not resolve '" + fo
ntString + "' as a font."); | 468 exceptionState.throwDOMException(SyntaxError, "Could not resolve '" + fo
ntString + "' as a font."); |
475 return false; | 469 return false; |
476 } | 470 } |
477 | 471 |
478 CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); | 472 CSSFontSelector* fontSelector = document()->styleEngine()->fontSelector(); |
479 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); | 473 FontFaceCache* fontFaceCache = fontSelector->fontFaceCache(); |
480 | 474 |
481 bool hasLoadedFaces = false; | 475 bool hasLoadedFaces = false; |
482 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { | 476 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { |
483 CSSSegmentedFontFace* face = fontFaceCache->get(font.fontDescription(),
f->family()); | 477 CSSSegmentedFontFace* face = fontFaceCache->get(font.fontDescription(),
f->family()); |
484 if (face) { | 478 if (face) { |
485 if (!face->checkFont(nullToSpace(text))) | 479 if (!face->checkFont(text)) |
486 return false; | 480 return false; |
487 hasLoadedFaces = true; | 481 hasLoadedFaces = true; |
488 } | 482 } |
489 } | 483 } |
490 if (hasLoadedFaces) | 484 if (hasLoadedFaces) |
491 return true; | 485 return true; |
492 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { | 486 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next(
)) { |
493 if (fontSelector->isPlatformFontAvailable(font.fontDescription(), f->fam
ily())) | 487 if (fontSelector->isPlatformFontAvailable(font.fontDescription(), f->fam
ily())) |
494 return true; | 488 return true; |
495 } | 489 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 visitor->trace(m_loadingFonts); | 587 visitor->trace(m_loadingFonts); |
594 visitor->trace(m_loadedFonts); | 588 visitor->trace(m_loadedFonts); |
595 visitor->trace(m_failedFonts); | 589 visitor->trace(m_failedFonts); |
596 visitor->trace(m_nonCSSConnectedFaces); | 590 visitor->trace(m_nonCSSConnectedFaces); |
597 DocumentSupplement::trace(visitor); | 591 DocumentSupplement::trace(visitor); |
598 EventTargetWithInlineData::trace(visitor); | 592 EventTargetWithInlineData::trace(visitor); |
599 } | 593 } |
600 #endif | 594 #endif |
601 | 595 |
602 } // namespace blink | 596 } // namespace blink |
OLD | NEW |