1 | /* |
2 | * Copyright 2018 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 SkRemoteTypeface_DEFINED |
9 | #define SkRemoteTypeface_DEFINED |
10 | |
11 | #include "include/core/SkFontStyle.h" |
12 | #include "include/core/SkPaint.h" |
13 | #include "include/core/SkTypeface.h" |
14 | #include "src/core/SkAdvancedTypefaceMetrics.h" |
15 | #include "src/core/SkDescriptor.h" |
16 | #include "src/core/SkFontDescriptor.h" |
17 | #include "src/core/SkRemoteGlyphCache.h" |
18 | #include "src/core/SkScalerContext.h" |
19 | |
20 | class SkTypefaceProxy; |
21 | class SkStrikeCache; |
22 | |
23 | class SkScalerContextProxy : public SkScalerContext { |
24 | public: |
25 | SkScalerContextProxy(sk_sp<SkTypeface> tf, |
26 | const SkScalerContextEffects& effects, |
27 | const SkDescriptor* desc, |
28 | sk_sp<SkStrikeClient::DiscardableHandleManager> manager); |
29 | |
30 | protected: |
31 | unsigned generateGlyphCount() override; |
32 | bool generateAdvance(SkGlyph* glyph) override; |
33 | void generateMetrics(SkGlyph* glyph) override; |
34 | void generateImage(const SkGlyph& glyph) override; |
35 | bool generatePath(SkGlyphID glyphID, SkPath* path) override; |
36 | void generateFontMetrics(SkFontMetrics* metrics) override; |
37 | SkTypefaceProxy* getProxyTypeface() const; |
38 | |
39 | private: |
40 | sk_sp<SkStrikeClient::DiscardableHandleManager> fDiscardableManager; |
41 | typedef SkScalerContext INHERITED; |
42 | }; |
43 | |
44 | class SkTypefaceProxy : public SkTypeface { |
45 | public: |
46 | SkTypefaceProxy(SkFontID fontId, |
47 | int glyphCount, |
48 | const SkFontStyle& style, |
49 | bool isFixed, |
50 | sk_sp<SkStrikeClient::DiscardableHandleManager> manager, |
51 | bool isLogging = true) |
52 | : INHERITED{style, false} |
53 | , fFontId{fontId} |
54 | , fGlyphCount{glyphCount} |
55 | , fIsLogging{isLogging} |
56 | , fDiscardableManager{std::move(manager)} {} |
57 | SkFontID remoteTypefaceID() const {return fFontId;} |
58 | int glyphCount() const {return fGlyphCount;} |
59 | bool isLogging() const {return fIsLogging;} |
60 | |
61 | protected: |
62 | int onGetUPEM() const override { SK_ABORT("Should never be called." ); } |
63 | std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { |
64 | SK_ABORT("Should never be called." ); |
65 | } |
66 | std::unique_ptr<SkFontData> onMakeFontData() const override { |
67 | SK_ABORT("Should never be called." ); |
68 | } |
69 | sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override { |
70 | SK_ABORT("Should never be called." ); |
71 | } |
72 | int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], |
73 | int coordinateCount) const override { |
74 | SK_ABORT("Should never be called." ); |
75 | } |
76 | int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], |
77 | int parameterCount) const override { |
78 | SK_ABORT("Should never be called." ); |
79 | } |
80 | void onGetFamilyName(SkString* familyName) const override { |
81 | // Used by SkStrikeCache::DumpMemoryStatistics. |
82 | *familyName = "" ; |
83 | } |
84 | SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override { |
85 | SK_ABORT("Should never be called." ); |
86 | } |
87 | int onGetTableTags(SkFontTableTag tags[]) const override { |
88 | SK_ABORT("Should never be called." ); |
89 | } |
90 | size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override { |
91 | SK_ABORT("Should never be called." ); |
92 | } |
93 | SkScalerContext* onCreateScalerContext(const SkScalerContextEffects& effects, |
94 | const SkDescriptor* desc) const override { |
95 | return new SkScalerContextProxy(sk_ref_sp(const_cast<SkTypefaceProxy*>(this)), effects, |
96 | desc, fDiscardableManager); |
97 | } |
98 | void onFilterRec(SkScalerContextRec* rec) const override { |
99 | // The rec filtering is already applied by the server when generating |
100 | // the glyphs. |
101 | } |
102 | void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { |
103 | SK_ABORT("Should never be called." ); |
104 | } |
105 | void getGlyphToUnicodeMap(SkUnichar*) const override { |
106 | SK_ABORT("Should never be called." ); |
107 | } |
108 | |
109 | void getPostScriptGlyphNames(SkString*) const override { |
110 | SK_ABORT("Should never be called." ); |
111 | } |
112 | |
113 | std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override { |
114 | SK_ABORT("Should never be called." ); |
115 | } |
116 | void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override { |
117 | SK_ABORT("Should never be called." ); |
118 | } |
119 | int onCountGlyphs() const override { |
120 | return this->glyphCount(); |
121 | } |
122 | |
123 | void* onGetCTFontRef() const override { |
124 | SK_ABORT("Should never be called." ); |
125 | } |
126 | |
127 | private: |
128 | const SkFontID fFontId; |
129 | const int fGlyphCount; |
130 | const bool fIsLogging; |
131 | sk_sp<SkStrikeClient::DiscardableHandleManager> fDiscardableManager; |
132 | |
133 | |
134 | typedef SkTypeface INHERITED; |
135 | }; |
136 | |
137 | #endif // SkRemoteTypeface_DEFINED |
138 | |