Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkTypeface_win_dw.h
Go to the documentation of this file.
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
20
21#include <dwrite.h>
22#include <dwrite_1.h>
23#include <dwrite_2.h>
24#include <dwrite_3.h>
25
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. */
35interface IDWriteFontFace4;
36interface IDWriteFontFace7;
37
39public:
40 struct Loaders : public SkNVRefCnt<Loaders> {
41 Loaders(IDWriteFactory* factory,
42 IDWriteFontFileLoader* fontFileLoader,
43 IDWriteFontCollectionLoader* fontCollectionLoader)
44 : fFactory(SkRefComPtr(factory))
45 , fDWriteFontFileLoader(SkRefComPtr(fontFileLoader))
46 , fDWriteFontCollectionLoader(SkRefComPtr(fontCollectionLoader))
47 {}
48 Loaders(const Loaders&) = delete;
49 Loaders& operator=(const Loaders&) = delete;
50 Loaders(Loaders&&) = delete;
53
54 SkTScopedComPtr<IDWriteFactory> fFactory;
55 SkTScopedComPtr<IDWriteFontFileLoader> fDWriteFontFileLoader;
56 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader;
57 };
58
59 static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('d','w','r','t');
60 static sk_sp<SkTypeface> SK_SPI MakeFromStream(std::unique_ptr<SkStreamAsset>,
61 const SkFontArguments&);
62
64private:
66 IDWriteFactory* factory,
67 IDWriteFontFace* fontFace,
68 IDWriteFont* font,
69 IDWriteFontFamily* fontFamily,
70 sk_sp<Loaders> loaders,
72 HRESULT initializePalette();
73
74public:
75 SkTScopedComPtr<IDWriteFactory> fFactory;
76 SkTScopedComPtr<IDWriteFactory2> fFactory2;
77 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily;
78 SkTScopedComPtr<IDWriteFont> fDWriteFont;
79 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace;
80 SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1;
81 SkTScopedComPtr<IDWriteFontFace2> fDWriteFontFace2;
82 SkTScopedComPtr<IDWriteFontFace4> fDWriteFontFace4;
83 // Once WDK 10.0.25357.0 or newer is required to build, fDWriteFontFace7 can be a smart pointer.
84 // If a smart pointer is used then ~DWriteFontTypeface must call the smart pointer's destructor,
85 // which must include code to Release the IDWriteFontFace7, but there may be no IDWriteFontFace7
86 // other than the forward declaration. Skia should never declare an IDWriteFontFace7 (other than
87 // copying the entire interface) for ODR reasons. This header cannot detect if there will be a
88 // full declaration of IDWriteFontFace7 at the ~DWriteFontTypeface implementation because of
89 // NTDDI_VERSION shenanigains, otherwise this defintition could just be ifdef'ed.
90 //SkTScopedComPtr<IDWriteFontFace7> fDWriteFontFace7;
91 IDWriteFontFace7* fDWriteFontFace7 = nullptr;
93
94 std::unique_ptr<SkFontArguments::Palette::Override> fRequestedPaletteEntryOverrides;
96
98 std::unique_ptr<SkColor[]> fPalette;
99 std::unique_ptr<DWRITE_COLOR_F[]> fDWPalette;
100
101 static SkFontStyle GetStyle(IDWriteFont* font, IDWriteFontFace* fontFace);
103 IDWriteFactory* factory,
104 IDWriteFontFace* fontFace,
105 IDWriteFont* font,
106 IDWriteFontFamily* fontFamily,
107 sk_sp<Loaders> loaders,
108 const SkFontArguments::Palette& palette);
109
110protected:
111 void weak_dispose() const override {
112 fLoaders.reset();
113
114 //SkTypefaceCache::Remove(this);
116 }
117
119 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
120 std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&,
121 const SkDescriptor*) const override;
122 void onFilterRec(SkScalerContextRec*) const override;
123 void getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const override;
124 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
125 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
126 void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override;
127 int onCountGlyphs() const override;
128 void getPostScriptGlyphNames(SkString*) const override;
129 int onGetUPEM() const override;
130 void onGetFamilyName(SkString* familyName) const override;
131 bool onGetPostScriptName(SkString*) const override;
133 bool onGlyphMaskNeedsCurrentColor() const override;
135 int coordinateCount) const override;
137 int parameterCount) const override;
138 int onGetTableTags(SkFontTableTag tags[]) const override;
139 size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override;
141
142private:
143 mutable sk_sp<Loaders> fLoaders;
144 using INHERITED = SkTypeface;
145};
146
147#endif
uint16_t glyphs[5]
int count
#define SK_SPI
Definition SkAPI.h:41
uint32_t SkFontTableTag
Definition SkTypeface.h:41
int32_t SkUnichar
Definition SkTypes.h:175
uint16_t SkGlyphID
Definition SkTypes.h:179
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition SkTypes.h:167
SkTScopedComPtr< IDWriteFontFace4 > fDWriteFontFace4
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], int parameterCount) const override
int onGetUPEM() const override
SkTScopedComPtr< IDWriteFontFace2 > fDWriteFontFace2
std::unique_ptr< SkScalerContext > onCreateScalerContext(const SkScalerContextEffects &, const SkDescriptor *) const override
static sk_sp< SkTypeface > SK_SPI MakeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &)
void weak_dispose() const override
SkTypeface::LocalizedStrings * onCreateFamilyNameIterator() const override
SkTScopedComPtr< IDWriteFactory2 > fFactory2
SkTScopedComPtr< IDWriteFactory > fFactory
SkFontArguments::Palette fRequestedPalette
void onFilterRec(SkScalerContextRec *) const override
void getGlyphToUnicodeMap(SkUnichar *glyphToUnicode) const override
size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void *data) const override
static SkFontStyle GetStyle(IDWriteFont *font, IDWriteFontFace *fontFace)
std::unique_ptr< SkAdvancedTypefaceMetrics > onGetAdvancedMetrics() const override
void onCharsToGlyphs(const SkUnichar *chars, int count, SkGlyphID glyphs[]) const override
std::unique_ptr< SkColor[]> fPalette
~DWriteFontTypeface() override
IDWriteFontFace7 * fDWriteFontFace7
SkTScopedComPtr< IDWriteFontFamily > fDWriteFontFamily
SkTScopedComPtr< IDWriteFontFace1 > fDWriteFontFace1
std::unique_ptr< SkStreamAsset > onOpenStream(int *ttcIndex) const override
int onGetTableTags(SkFontTableTag tags[]) const override
std::unique_ptr< DWRITE_COLOR_F[]> fDWPalette
int onCountGlyphs() const override
bool onGetPostScriptName(SkString *) const override
void getPostScriptGlyphNames(SkString *) const override
bool onGlyphMaskNeedsCurrentColor() const override
sk_sp< SkData > onCopyTableData(SkFontTableTag) const override
void onGetFamilyName(SkString *familyName) const override
SkTScopedComPtr< IDWriteFontFace > fDWriteFontFace
SkTScopedComPtr< IDWriteFont > fDWriteFont
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const override
static sk_sp< DWriteFontTypeface > Make(IDWriteFactory *factory, IDWriteFontFace *fontFace, IDWriteFont *font, IDWriteFontFamily *fontFamily, sk_sp< Loaders > loaders, const SkFontArguments::Palette &palette)
std::unique_ptr< SkFontArguments::Palette::Override > fRequestedPaletteEntryOverrides
sk_sp< SkTypeface > onMakeClone(const SkFontArguments &) const override
void onGetFontDescriptor(SkFontDescriptor *, bool *) const override
SkFourByteTag FactoryId
Definition SkTypeface.h:335
virtual void weak_dispose() const
size_t length
Point offset
Loaders & operator=(Loaders &&)=delete
SkTScopedComPtr< IDWriteFactory > fFactory
Loaders(IDWriteFactory *factory, IDWriteFontFileLoader *fontFileLoader, IDWriteFontCollectionLoader *fontCollectionLoader)
Loaders & operator=(const Loaders &)=delete
SkTScopedComPtr< IDWriteFontFileLoader > fDWriteFontFileLoader
Loaders(Loaders &&)=delete
SkTScopedComPtr< IDWriteFontCollectionLoader > fDWriteFontCollectionLoader
Loaders(const Loaders &)=delete