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