Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: third_party/WebKit/Source/core/css/LocalFontFace.cpp

Issue 1615133002: Implement API for accessing fonts installed locally on the system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Nasko. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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::create(ExecutionContext* co ntext, const AtomicString& family, const AtomicString& styleName, const AtomicSt ring& fullName, StringOrArrayBufferOrArrayBufferView& source, const FontFaceDesc riptors& 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 // TODO(dhnishi): Remove code duplication with FontFace.
29 CSSParserContext parserContext(*document, UseCounter::getFrom(document));
30 RefPtrWillBeRawPtr<CSSValue> src = CSSParser::parseFontFaceDescriptor(CSSPro pertySrc, sourceString, parserContext);
31 if (!src || !src->isValueList())
32 fontFace->setError(DOMException::create(SyntaxError, "The source provide d ('" + sourceString + "') could not be parsed as a value list."));
33
34 fontFace->initCSSFontFace(toDocument(context), src);
35 return fontFace.release();
36 }
37
38 class FontBinaryResult {
39 WTF_MAKE_NONCOPYABLE(FontBinaryResult);
40
41 public:
42 using WebType = OwnPtr<WebData>;
43
44 static PassRefPtr<DOMArrayBuffer> take(ScriptPromiseResolver* resolver, Pass OwnPtr<WebData> webBlob)
45 {
46 RefPtr<DOMArrayBuffer> domBuffer = DOMArrayBuffer::create(webBlob->data( ), webBlob->size());
47 return domBuffer;
48 }
49
50 private:
51 FontBinaryResult() = delete;
52 };
53
54 ScriptPromise LocalFontFace::binaryData(ScriptState* scriptState) const
55 {
56 WebFontAccess* webfontaccess = Platform::current()->fontAccess();
57 if (!webfontaccess)
58 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
59 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
60 ScriptPromise promise = resolver->promise();
61
62 webfontaccess->getFontWebData(family(), styleName(), new CallbackPromiseAdap ter<FontBinaryResult, void>(resolver));
63 return promise;
64 }
65
66 LocalFontFace::LocalFontFace(ExecutionContext* context, const AtomicString& fami ly, const AtomicString& styleName, const AtomicString& fullName, const FontFaceD escriptors& descriptor)
67 : FontFace(context, family, descriptor)
68 , m_style(styleName)
69 , m_fullName(fullName)
70 {
71 }
72
73 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/LocalFontFace.h ('k') | third_party/WebKit/Source/core/css/LocalFontFace.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698