| 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 | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "sky/engine/core/css/FontFace.h" | 31 #include "sky/engine/core/css/FontFace.h" |
| 32 | 32 |
| 33 #include "gen/sky/core/CSSValueKeywords.h" | 33 #include "gen/sky/core/CSSValueKeywords.h" |
| 34 #include "gen/sky/platform/FontFamilyNames.h" | 34 #include "gen/sky/platform/FontFamilyNames.h" |
| 35 #include "sky/engine/bindings/exception_state.h" | 35 #include "sky/engine/bindings/exception_state.h" |
| 36 #include "sky/engine/core/css/BinaryDataFontFaceSource.h" | 36 #include "sky/engine/core/css/BinaryDataFontFaceSource.h" |
| 37 #include "sky/engine/core/css/CSSFontFace.h" | 37 #include "sky/engine/core/css/CSSFontFace.h" |
| 38 #include "sky/engine/core/css/CSSFontFaceSrcValue.h" | |
| 39 #include "sky/engine/core/css/CSSFontSelector.h" | 38 #include "sky/engine/core/css/CSSFontSelector.h" |
| 40 #include "sky/engine/core/css/CSSPrimitiveValue.h" | 39 #include "sky/engine/core/css/CSSPrimitiveValue.h" |
| 41 #include "sky/engine/core/css/CSSUnicodeRangeValue.h" | 40 #include "sky/engine/core/css/CSSUnicodeRangeValue.h" |
| 42 #include "sky/engine/core/css/CSSValueList.h" | 41 #include "sky/engine/core/css/CSSValueList.h" |
| 43 #include "sky/engine/core/css/LocalFontFaceSource.h" | 42 #include "sky/engine/core/css/LocalFontFaceSource.h" |
| 44 #include "sky/engine/core/css/RemoteFontFaceSource.h" | |
| 45 #include "sky/engine/core/css/StylePropertySet.h" | 43 #include "sky/engine/core/css/StylePropertySet.h" |
| 46 #include "sky/engine/core/css/StyleRule.h" | 44 #include "sky/engine/core/css/StyleRule.h" |
| 47 #include "sky/engine/core/css/parser/BisonCSSParser.h" | 45 #include "sky/engine/core/css/parser/BisonCSSParser.h" |
| 48 #include "sky/engine/core/dom/DOMException.h" | 46 #include "sky/engine/core/dom/DOMException.h" |
| 49 #include "sky/engine/core/dom/Document.h" | 47 #include "sky/engine/core/dom/Document.h" |
| 50 #include "sky/engine/core/dom/ExceptionCode.h" | 48 #include "sky/engine/core/dom/ExceptionCode.h" |
| 51 #include "sky/engine/core/dom/StyleEngine.h" | 49 #include "sky/engine/core/dom/StyleEngine.h" |
| 52 #include "sky/engine/core/frame/LocalFrame.h" | 50 #include "sky/engine/core/frame/LocalFrame.h" |
| 53 #include "sky/engine/core/frame/Settings.h" | 51 #include "sky/engine/core/frame/Settings.h" |
| 54 #include "sky/engine/platform/SharedBuffer.h" | 52 #include "sky/engine/platform/SharedBuffer.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 else | 332 else |
| 335 m_callbacks.append(callback); | 333 m_callbacks.append(callback); |
| 336 } | 334 } |
| 337 | 335 |
| 338 void FontFace::loadInternal(ExecutionContext* context) | 336 void FontFace::loadInternal(ExecutionContext* context) |
| 339 { | 337 { |
| 340 if (m_status != Unloaded) | 338 if (m_status != Unloaded) |
| 341 return; | 339 return; |
| 342 | 340 |
| 343 m_cssFontFace->load(); | 341 m_cssFontFace->load(); |
| 344 toDocument(context)->styleEngine()->fontSelector()->fontLoader()->loadPendin
gFonts(); | |
| 345 } | 342 } |
| 346 | 343 |
| 347 FontTraits FontFace::traits() const | 344 FontTraits FontFace::traits() const |
| 348 { | 345 { |
| 349 FontStyle style = FontStyleNormal; | 346 FontStyle style = FontStyleNormal; |
| 350 if (m_style) { | 347 if (m_style) { |
| 351 if (!m_style->isPrimitiveValue()) | 348 if (!m_style->isPrimitiveValue()) |
| 352 return 0; | 349 return 0; |
| 353 | 350 |
| 354 switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { | 351 switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 ranges.append(CSSFontFace::UnicodeRange(range->from(), range->to()))
; | 446 ranges.append(CSSFontFace::UnicodeRange(range->from(), range->to()))
; |
| 450 } | 447 } |
| 451 } | 448 } |
| 452 | 449 |
| 453 return adoptPtr(new CSSFontFace(fontFace, ranges)); | 450 return adoptPtr(new CSSFontFace(fontFace, ranges)); |
| 454 } | 451 } |
| 455 | 452 |
| 456 void FontFace::initCSSFontFace(Document* document, PassRefPtr<CSSValue> src) | 453 void FontFace::initCSSFontFace(Document* document, PassRefPtr<CSSValue> src) |
| 457 { | 454 { |
| 458 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); | 455 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); |
| 459 if (m_error) | |
| 460 return; | |
| 461 | |
| 462 // Each item in the src property's list is a single CSSFontFaceSource. Put t
hem all into a CSSFontFace. | |
| 463 ASSERT(src); | |
| 464 ASSERT(src->isValueList()); | |
| 465 CSSValueList* srcList = toCSSValueList(src.get()); | |
| 466 int srcLength = srcList->length(); | |
| 467 | |
| 468 for (int i = 0; i < srcLength; i++) { | |
| 469 // An item in the list either specifies a string (local font name) or a
URL (remote font to download). | |
| 470 CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)); | |
| 471 OwnPtr<CSSFontFaceSource> source = nullptr; | |
| 472 | |
| 473 if (!item->isLocal()) { | |
| 474 Settings* settings = document ? document->frame() ? document->frame(
)->settings() : 0 : 0; | |
| 475 bool allowDownloading = settings && settings->downloadableBinaryFont
sEnabled(); | |
| 476 if (allowDownloading && item->isSupportedFormat() && document) { | |
| 477 FontResource* fetched = item->fetch(document); | |
| 478 if (fetched) { | |
| 479 FontLoader* fontLoader = document->styleEngine()->fontSelect
or()->fontLoader(); | |
| 480 source = adoptPtr(new RemoteFontFaceSource(fetched, fontLoad
er)); | |
| 481 } | |
| 482 } | |
| 483 } else { | |
| 484 source = adoptPtr(new LocalFontFaceSource(item->resource())); | |
| 485 } | |
| 486 | |
| 487 if (source) | |
| 488 m_cssFontFace->addSource(source.release()); | |
| 489 } | |
| 490 } | 456 } |
| 491 | 457 |
| 492 void FontFace::initCSSFontFace(const unsigned char* data, unsigned size) | 458 void FontFace::initCSSFontFace(const unsigned char* data, unsigned size) |
| 493 { | 459 { |
| 494 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); | 460 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); |
| 495 if (m_error) | 461 if (m_error) |
| 496 return; | 462 return; |
| 497 | 463 |
| 498 RefPtr<SharedBuffer> buffer = SharedBuffer::create(data, size); | 464 RefPtr<SharedBuffer> buffer = SharedBuffer::create(data, size); |
| 499 OwnPtr<BinaryDataFontFaceSource> source = adoptPtr(new BinaryDataFontFaceSou
rce(buffer.get())); | 465 OwnPtr<BinaryDataFontFaceSource> source = adoptPtr(new BinaryDataFontFaceSou
rce(buffer.get())); |
| 500 if (source->isValid()) | 466 if (source->isValid()) |
| 501 setLoadStatus(Loaded); | 467 setLoadStatus(Loaded); |
| 502 else | 468 else |
| 503 setError(DOMException::create(SyntaxError, "Invalid font data in ArrayBu
ffer.")); | 469 setError(DOMException::create(SyntaxError, "Invalid font data in ArrayBu
ffer.")); |
| 504 m_cssFontFace->addSource(source.release()); | 470 m_cssFontFace->addSource(source.release()); |
| 505 } | 471 } |
| 506 | 472 |
| 507 bool FontFace::hadBlankText() const | 473 bool FontFace::hadBlankText() const |
| 508 { | 474 { |
| 509 return m_cssFontFace->hadBlankText(); | 475 return m_cssFontFace->hadBlankText(); |
| 510 } | 476 } |
| 511 | 477 |
| 512 } // namespace blink | 478 } // namespace blink |
| OLD | NEW |