1 | /* |
2 | * Copyright (C) 2007, 2008, 2011 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 "CachedFontClient.h" |
29 | #include "CachedResourceHandle.h" |
30 | #include <JavaScriptCore/ArrayBufferView.h> |
31 | #include <wtf/WeakPtr.h> |
32 | #include <wtf/text/AtomicString.h> |
33 | |
34 | namespace WebCore { |
35 | |
36 | class CSSFontFace; |
37 | class CSSFontSelector; |
38 | class Font; |
39 | struct FontCustomPlatformData; |
40 | class FontDescription; |
41 | struct FontSelectionSpecifiedCapabilities; |
42 | struct FontVariantSettings; |
43 | class SVGFontFaceElement; |
44 | class SharedBuffer; |
45 | |
46 | template <typename T> class FontTaggedSettings; |
47 | typedef FontTaggedSettings<int> FontFeatureSettings; |
48 | |
49 | class CSSFontFaceSource final : public CachedFontClient { |
50 | WTF_MAKE_FAST_ALLOCATED; |
51 | public: |
52 | CSSFontFaceSource(CSSFontFace& owner, const String& familyNameOrURI, CachedFont* = nullptr, SVGFontFaceElement* = nullptr, RefPtr<JSC::ArrayBufferView>&& = nullptr); |
53 | virtual ~CSSFontFaceSource(); |
54 | |
55 | // => Success |
56 | // // |
57 | // Pending => Loading |
58 | // \\. |
59 | // => Failure |
60 | enum class Status { |
61 | Pending, |
62 | Loading, |
63 | Success, |
64 | Failure |
65 | }; |
66 | Status status() const { return m_status; } |
67 | |
68 | const AtomicString& familyNameOrURI() const { return m_familyNameOrURI; } |
69 | |
70 | void opportunisticallyStartFontDataURLLoading(CSSFontSelector&); |
71 | |
72 | void load(CSSFontSelector*); |
73 | RefPtr<Font> font(const FontDescription&, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings&, const FontVariantSettings&, FontSelectionSpecifiedCapabilities); |
74 | |
75 | bool requiresExternalResource() const { return m_font; } |
76 | |
77 | #if ENABLE(SVG_FONTS) |
78 | bool isSVGFontFaceSource() const; |
79 | #endif |
80 | |
81 | private: |
82 | bool shouldIgnoreFontLoadCompletions() const; |
83 | |
84 | void fontLoaded(CachedFont&) override; |
85 | |
86 | void setStatus(Status); |
87 | |
88 | AtomicString m_familyNameOrURI; // URI for remote, built-in font name for local. |
89 | CachedResourceHandle<CachedFont> m_font; // For remote fonts, a pointer to our cached resource. |
90 | CSSFontFace& m_face; // Our owning font face. |
91 | |
92 | RefPtr<SharedBuffer> m_generatedOTFBuffer; |
93 | RefPtr<JSC::ArrayBufferView> m_immediateSource; |
94 | std::unique_ptr<FontCustomPlatformData> m_immediateFontCustomPlatformData; |
95 | |
96 | #if ENABLE(SVG_FONTS) |
97 | WeakPtr<SVGFontFaceElement> m_svgFontFaceElement; |
98 | #endif |
99 | std::unique_ptr<FontCustomPlatformData> m_inDocumentCustomPlatformData; |
100 | |
101 | Status m_status { Status::Pending }; |
102 | #if ENABLE(SVG_FONTS) |
103 | bool m_hasSVGFontFaceElement; |
104 | #endif |
105 | }; |
106 | |
107 | } // namespace WebCore |
108 | |