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