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