1 | /*
|
---|
2 | * Copyright (C) 2007-2021 Apple Inc. All rights reserved.
|
---|
3 | *
|
---|
4 | * Redistribution and use in source and binary forms, with or without
|
---|
5 | * modification, are permitted provided that the following conditions
|
---|
6 | * are met:
|
---|
7 | * 1. Redistributions of source code must retain the above copyright
|
---|
8 | * notice, this list of conditions and the following disclaimer.
|
---|
9 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer in the
|
---|
11 | * documentation and/or other materials provided with the distribution.
|
---|
12 | *
|
---|
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
---|
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
---|
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
---|
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #pragma once
|
---|
27 |
|
---|
28 | #include "FontLoadRequest.h"
|
---|
29 | #include <JavaScriptCore/ArrayBufferView.h>
|
---|
30 | #include <wtf/WeakPtr.h>
|
---|
31 | #include <wtf/text/AtomString.h>
|
---|
32 |
|
---|
33 | namespace WebCore {
|
---|
34 |
|
---|
35 | class CSSFontFace;
|
---|
36 | class CSSFontSelector;
|
---|
37 | class SharedBuffer;
|
---|
38 | class Document;
|
---|
39 | class Font;
|
---|
40 | class FontCreationContext;
|
---|
41 | struct FontCustomPlatformData;
|
---|
42 | class FontDescription;
|
---|
43 | struct FontSelectionSpecifiedCapabilities;
|
---|
44 | struct FontVariantSettings;
|
---|
45 | class SVGFontFaceElement;
|
---|
46 |
|
---|
47 | template <typename T> class FontTaggedSettings;
|
---|
48 | typedef FontTaggedSettings<int> FontFeatureSettings;
|
---|
49 |
|
---|
50 | class CSSFontFaceSource final : public FontLoadRequestClient {
|
---|
51 | WTF_MAKE_FAST_ALLOCATED;
|
---|
52 | public:
|
---|
53 | CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI);
|
---|
54 | CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CSSFontSelector&, UniqueRef<FontLoadRequest>&&);
|
---|
55 | CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, SVGFontFaceElement&);
|
---|
56 | CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, Ref<JSC::ArrayBufferView>&&);
|
---|
57 | virtual ~CSSFontFaceSource();
|
---|
58 |
|
---|
59 | // => Success
|
---|
60 | // //
|
---|
61 | // Pending => Loading
|
---|
62 | // \\.
|
---|
63 | // => Failure
|
---|
64 | enum class Status {
|
---|
65 | Pending,
|
---|
66 | Loading,
|
---|
67 | Success,
|
---|
68 | Failure
|
---|
69 | };
|
---|
70 | Status status() const { return m_status; }
|
---|
71 |
|
---|
72 | const AtomString& familyNameOrURI() const { return m_familyNameOrURI; }
|
---|
73 |
|
---|
74 | void opportunisticallyStartFontDataURLLoading();
|
---|
75 |
|
---|
76 | void load(Document* = nullptr);
|
---|
77 | RefPtr<Font> font(const FontDescription&, bool syntheticBold, bool syntheticItalic, const FontCreationContext&);
|
---|
78 |
|
---|
79 | FontLoadRequest* fontLoadRequest() const { return m_fontRequest.get(); }
|
---|
80 | bool requiresExternalResource() const { return m_fontRequest.get(); }
|
---|
81 |
|
---|
82 | bool isSVGFontFaceSource() const;
|
---|
83 |
|
---|
84 | private:
|
---|
85 | bool shouldIgnoreFontLoadCompletions() const;
|
---|
86 |
|
---|
87 | void fontLoaded(FontLoadRequest&) override;
|
---|
88 |
|
---|
89 | void setStatus(Status);
|
---|
90 |
|
---|
91 | AtomString m_familyNameOrURI; // URI for remote, built-in font name for local.
|
---|
92 | CSSFontFace& m_face; // Our owning font face.
|
---|
93 | WeakPtr<CSSFontSelector> m_fontSelector; // For remote fonts, to orchestrate loading.
|
---|
94 | std::unique_ptr<FontLoadRequest> m_fontRequest; // Also for remote fonts, a pointer to the resource request.
|
---|
95 |
|
---|
96 | RefPtr<SharedBuffer> m_generatedOTFBuffer;
|
---|
97 | RefPtr<JSC::ArrayBufferView> m_immediateSource;
|
---|
98 | std::unique_ptr<FontCustomPlatformData> m_immediateFontCustomPlatformData;
|
---|
99 |
|
---|
100 | WeakPtr<SVGFontFaceElement> m_svgFontFaceElement;
|
---|
101 | std::unique_ptr<FontCustomPlatformData> m_inDocumentCustomPlatformData;
|
---|
102 |
|
---|
103 | Status m_status { Status::Pending };
|
---|
104 | bool m_hasSVGFontFaceElement { false };
|
---|
105 | };
|
---|
106 |
|
---|
107 | } // namespace WebCore
|
---|