Debian Codegraph @

src/ports/SkTypeface_win_dw.h

raw
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkTypeface_win_dw_DEFINED
9 #define SkTypeface_win_dw_DEFINED
10
11 #include "include/core/SkFontArguments.h"
12 #include "include/core/SkTypeface.h"
13 #include "include/private/base/SkAPI.h"
14 #include "src/base/SkLeanWindows.h"
15 #include "src/core/SkAdvancedTypefaceMetrics.h"
16 #include "src/core/SkTypefaceCache.h"
17 #include "src/utils/win/SkDWrite.h"
18 #include "src/utils/win/SkHRESULT.h"
19 #include "src/utils/win/SkTScopedComPtr.h"
20
21 #include <dwrite.h>
22 #include <dwrite_1.h>
23 #include <dwrite_2.h>
24 #include <dwrite_3.h>
25
26 class SkFontDescriptor;
27 struct SkScalerContextRec;
28
29 /* dwrite_3.h incorrectly uses NTDDI_VERSION to hide immutable interfaces (it should only be used to
30 gate changes to public ABI). The implementation files can (and must) get away with including
31 SkDWriteNTDDI_VERSION.h which simply unsets NTDDI_VERSION, but this doesn't work well for this
32 header which can be included in SkTypeface.cpp. Instead, ensure that any declarations hidden
33 behind the NTDDI_VERSION are forward (backward?) declared here in case dwrite_3.h did not declare
34 them. */
35 interface IDWriteFontFace4;
36 interface IDWriteFontFace5;
37 interface IDWriteFontFace7;
38
39 class DWriteFontTypeface : public SkTypeface {
40 public:
41 struct Loaders : public SkNVRefCnt<Loaders> {
42 Loaders(IDWriteFactory* factory,
43 IDWriteFontFileLoader* fontFileLoader,
44 IDWriteFontCollectionLoader* fontCollectionLoader)
45 : fFactory(SkRefComPtr(factory))
46 , fDWriteFontFileLoader(SkRefComPtr(fontFileLoader))
47 , fDWriteFontCollectionLoader(SkRefComPtr(fontCollectionLoader))
48 {}
49 Loaders(const Loaders&) = delete;
50 Loaders& operator=(const Loaders&) = delete;
51 Loaders(Loaders&&) = delete;
52 Loaders& operator=(Loaders&&) = delete;
53 ~Loaders();
54
55 SkTScopedComPtr<IDWriteFactory> fFactory;
56 SkTScopedComPtr<IDWriteFontFileLoader> fDWriteFontFileLoader;
57 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader;
58 };
59
60 static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('d','w','r','t');
61 static sk_sp<SkTypeface> SK_SPI MakeFromStream(std::unique_ptr<SkStreamAsset>,
62 const SkFontArguments&);
63
64 ~DWriteFontTypeface() override;
65 private:
66 DWriteFontTypeface(const SkFontStyle& style,
67 IDWriteFactory* factory,
68 IDWriteFontFace* fontFace,
69 IDWriteFont* font,
70 IDWriteFontFamily* fontFamily,
71 sk_sp<Loaders> loaders,
72 const SkFontArguments::Palette&);
73 HRESULT initializePalette();
74
75 public:
76 SkTScopedComPtr<IDWriteFactory> fFactory;
77 SkTScopedComPtr<IDWriteFactory2> fFactory2;
78 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily;
79 SkTScopedComPtr<IDWriteFont> fDWriteFont;
80 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace;
81 SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1;
82 SkTScopedComPtr<IDWriteFontFace2> fDWriteFontFace2;
83 SkTScopedComPtr<IDWriteFontFace3> fDWriteFontFace3;
84 SkTScopedComPtr<IDWriteFontFace4> fDWriteFontFace4;
85 SkTScopedComPtr<IDWriteFontFace5> fDWriteFontFace5;
86 // Once WDK 10.0.25357.0 or newer is required to build, fDWriteFontFace7 can be a smart pointer.
87 // If a smart pointer is used then ~DWriteFontTypeface must call the smart pointer's destructor,
88 // which must include code to Release the IDWriteFontFace7, but there may be no IDWriteFontFace7
89 // other than the forward declaration. Skia should never declare an IDWriteFontFace7 (other than
90 // copying the entire interface) for ODR reasons. This header cannot detect if there will be a
91 // full declaration of IDWriteFontFace7 at the ~DWriteFontTypeface implementation because of
92 // NTDDI_VERSION shenanigains, otherwise this definition could just be ifdef'ed.
93 //SkTScopedComPtr<IDWriteFontFace7> fDWriteFontFace7;
94 IDWriteFontFace7* fDWriteFontFace7 = nullptr;
95 bool fIsColorFont;
96
97 std::unique_ptr<SkFontArguments::Palette::Override> fRequestedPaletteEntryOverrides;
98 SkFontArguments::Palette fRequestedPalette;
99
100 size_t fPaletteEntryCount;
101 std::unique_ptr<SkColor[]> fPalette;
102 std::unique_ptr<DWRITE_COLOR_F[]> fDWPalette;
103
104 static SkFontStyle GetStyle(IDWriteFont* font, IDWriteFontFace* fontFace);
105 static sk_sp<DWriteFontTypeface> Make(
106 IDWriteFactory* factory,
107 IDWriteFontFace* fontFace,
108 IDWriteFont* font,
109 IDWriteFontFamily* fontFamily,
110 sk_sp<Loaders> loaders,
111 const SkFontArguments::Palette& palette);
112
113 protected:
114 void weak_dispose() const override {
115 fLoaders.reset();
116
117 //SkTypefaceCache::Remove(this);
118 INHERITED::weak_dispose();
119 }
120
121 sk_sp<SkTypeface> onMakeClone(const SkFontArguments&) const override;
122 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
123 std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&,
124 const SkDescriptor*) const override;
125 void onFilterRec(SkScalerContextRec*) const override;
126 void getGlyphToUnicodeMap(SkSpan<SkUnichar>) const override;
127 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
128 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
129 void onCharsToGlyphs(SkSpan<const SkUnichar>, SkSpan<SkGlyphID>) const override;
130 int onCountGlyphs() const override;
131 void getPostScriptGlyphNames(SkString*) const override;
132 int onGetUPEM() const override;
133 void onGetFamilyName(SkString* familyName) const override;
134 bool onGetPostScriptName(SkString*) const override;
135 int onGetResourceName(SkString*) const override;
136 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
137 bool onGlyphMaskNeedsCurrentColor() const override;
138 int onGetVariationDesignPosition(
139 SkSpan<SkFontArguments::VariationPosition::Coordinate>) const override;
140 int onGetVariationDesignParameters(SkSpan<SkFontParameters::Variation::Axis>) const override;
141 bool onIsSyntheticBold() const override;
142 bool onIsSyntheticOblique() const override;
143 int onGetTableTags(SkSpan<SkFontTableTag>) const override;
144 size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override;
145 sk_sp<SkData> onCopyTableData(SkFontTableTag) const override;
146
147 private:
148 mutable sk_sp<Loaders> fLoaders;
149 using INHERITED = SkTypeface;
150 };
151
152 #endif