1 | /* |
2 | * Copyright (C) 2007, 2008 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 "CachedResource.h" |
29 | #include "CachedResourceClient.h" |
30 | #include "Font.h" |
31 | #include "TextFlags.h" |
32 | |
33 | namespace WebCore { |
34 | |
35 | class CachedResourceLoader; |
36 | class FontDescription; |
37 | class FontPlatformData; |
38 | struct FontSelectionSpecifiedCapabilities; |
39 | class SVGDocument; |
40 | class SVGFontElement; |
41 | struct FontCustomPlatformData; |
42 | |
43 | template <typename T> class FontTaggedSettings; |
44 | typedef FontTaggedSettings<int> FontFeatureSettings; |
45 | |
46 | class CachedFont : public CachedResource { |
47 | public: |
48 | CachedFont(CachedResourceRequest&&, const PAL::SessionID&, const CookieJar*, Type = Type::FontResource); |
49 | virtual ~CachedFont(); |
50 | |
51 | void beginLoadIfNeeded(CachedResourceLoader&); |
52 | bool stillNeedsLoad() const override { return !m_loadInitiated; } |
53 | |
54 | virtual bool ensureCustomFontData(const AtomicString& remoteURI); |
55 | static std::unique_ptr<FontCustomPlatformData> createCustomFontData(SharedBuffer&, const String& itemInCollection, bool& wrapping); |
56 | static FontPlatformData platformDataFromCustomData(FontCustomPlatformData&, const FontDescription&, bool bold, bool italic, const FontFeatureSettings&, const FontVariantSettings&, FontSelectionSpecifiedCapabilities); |
57 | |
58 | virtual RefPtr<Font> createFont(const FontDescription&, const AtomicString& remoteURI, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings&, const FontVariantSettings&, FontSelectionSpecifiedCapabilities); |
59 | |
60 | protected: |
61 | FontPlatformData platformDataFromCustomData(const FontDescription&, bool bold, bool italic, const FontFeatureSettings&, const FontVariantSettings&, FontSelectionSpecifiedCapabilities); |
62 | |
63 | bool ensureCustomFontData(SharedBuffer* data); |
64 | |
65 | private: |
66 | String calculateItemInCollection() const; |
67 | |
68 | void checkNotify() override; |
69 | bool mayTryReplaceEncodedData() const override; |
70 | |
71 | void load(CachedResourceLoader&) override; |
72 | NO_RETURN_DUE_TO_ASSERT void setBodyDataFrom(const CachedResource&) final { ASSERT_NOT_REACHED(); } |
73 | |
74 | void didAddClient(CachedResourceClient&) override; |
75 | void finishLoading(SharedBuffer*) override; |
76 | |
77 | void allClientsRemoved() override; |
78 | |
79 | bool m_loadInitiated; |
80 | bool m_hasCreatedFontDataWrappingResource; |
81 | |
82 | std::unique_ptr<FontCustomPlatformData> m_fontCustomPlatformData; |
83 | |
84 | friend class MemoryCache; |
85 | }; |
86 | |
87 | } // namespace WebCore |
88 | |
89 | SPECIALIZE_TYPE_TRAITS_CACHED_RESOURCE(CachedFont, CachedResource::Type::FontResource) |
90 | |