OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/css/LocalFontFace.h" | |
6 | |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
9 #include "bindings/core/v8/ScriptState.h" | |
10 #include "core/CSSValueKeywords.h" | |
11 #include "core/css/FontFaceDescriptors.h" | |
12 #include "core/css/parser/CSSParser.h" | |
13 #include "core/dom/DOMArrayBuffer.h" | |
14 #include "core/dom/DOMException.h" | |
15 #include "core/dom/Document.h" | |
16 #include "core/dom/ExceptionCode.h" | |
17 #include "core/frame/UseCounter.h" | |
18 #include "public/platform/Platform.h" | |
19 #include "public/platform/modules/font_access/WebFontAccess.h" | |
20 | |
21 namespace blink { | |
22 PassRefPtrWillBeRawPtr<LocalFontFace> LocalFontFace::createLocalFontFace(Executi onContext* context, const AtomicString& family, const AtomicString& styleName, c onst AtomicString& fullName, StringOrArrayBufferOrArrayBufferView& source, const FontFaceDescriptors& descriptors) | |
23 { | |
24 String sourceString = source.getAsString(); | |
25 RefPtrWillBeRawPtr<LocalFontFace> fontFace = adoptRefWillBeNoop(new LocalFon tFace(context, family, styleName, fullName, descriptors)); | |
26 | |
27 Document* document = toDocument(context); | |
28 CSSParserContext parserContext(*document, UseCounter::getFrom(document)); | |
29 RefPtrWillBeRawPtr<CSSValue> src = CSSParser::parseFontFaceDescriptor(CSSPro pertySrc, sourceString, parserContext); | |
esprehn
2016/02/09 19:29:56
This is copy pasta from FontFace, we probably want
Daniel Nishi
2016/02/11 00:23:51
Added a TODO to figure out how to share it.
| |
30 if (!src || !src->isValueList()) | |
31 fontFace->setError(DOMException::create(SyntaxError, "The source provide d ('" + sourceString + "') could not be parsed as a value list.")); | |
esprehn
2016/02/09 19:29:56
do you have a test for this case? How does it happ
Daniel Nishi
2016/02/11 00:23:51
After looking it over, it shouldn't happen. This s
| |
32 | |
33 fontFace->initCSSFontFace(toDocument(context), src); | |
34 return fontFace.release(); | |
35 } | |
36 | |
37 class FontBinaryResult { | |
38 WTF_MAKE_NONCOPYABLE(FontBinaryResult); | |
39 | |
40 public: | |
41 using WebType = OwnPtr<WebData>; | |
42 | |
43 static PassRefPtr<DOMArrayBuffer> take(ScriptPromiseResolver* resolver, Pass OwnPtr<WebData> webBlob) | |
44 { | |
45 RefPtr<DOMArrayBuffer> domBuffer = DOMArrayBuffer::create(webBlob->data( ), webBlob->size()); | |
46 return domBuffer; | |
47 } | |
48 | |
49 private: | |
50 FontBinaryResult() = delete; | |
51 }; | |
52 | |
53 ScriptPromise LocalFontFace::binaryData(ScriptState* scriptState) const | |
54 { | |
55 WebFontAccess* webfontaccess = Platform::current()->fontAccess(); | |
56 if (!webfontaccess) | |
57 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | |
58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
59 ScriptPromise promise = resolver->promise(); | |
60 | |
61 webfontaccess->getFontWebData(family(), styleName(), new CallbackPromiseAdap ter<FontBinaryResult, void>(resolver)); | |
62 return promise; | |
63 } | |
64 | |
65 LocalFontFace::LocalFontFace(ExecutionContext* context, const AtomicString& fami ly, const AtomicString& styleName, const AtomicString& fullName, const FontFaceD escriptors& descriptor) | |
66 : FontFace(context, family, descriptor) | |
67 , m_style(styleName) | |
68 , m_fullName(fullName) | |
69 { | |
70 } | |
71 | |
72 } // namespace blink | |
OLD | NEW |