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 TestTypeface_DEFINED 9 #define TestTypeface_DEFINED 10 11 #include "include/core/SkFontArguments.h" 12 #include "include/core/SkFontMetrics.h" 13 #include "include/core/SkFontStyle.h" 14 #include "include/core/SkPaint.h" 15 #include "include/core/SkRefCnt.h" 16 #include "include/core/SkScalar.h" 17 #include "include/core/SkStream.h" 18 #include "include/core/SkTypeface.h" 19 #include "include/core/SkTypes.h" 20 #include "include/private/SkFixed.h" 21 22 #include <memory> 23 24 class SkDescriptor; 25 class SkFontDescriptor; 26 class SkGlyph; 27 class SkPath; 28 class SkScalerContext; 29 class SkStreamAsset; 30 class SkString; 31 class SkTestFont; 32 struct SkAdvancedTypefaceMetrics; 33 struct SkScalerContextEffects; 34 struct SkScalerContextRec; 35 36 struct SkTestFontData { 37 const SkScalar* fPoints; 38 const unsigned char* fVerbs; 39 const SkUnichar* fCharCodes; 40 const size_t fCharCodesCount; 41 const SkFixed* fWidths; 42 const SkFontMetrics& fMetrics; 43 const char* fName; 44 SkFontStyle fStyle; 45 }; 46 47 class SkTestFont : public SkRefCnt { 48 public: 49 SkTestFont(const SkTestFontData&); 50 ~SkTestFont() override; 51 SkGlyphID glyphForUnichar(SkUnichar charCode) const; 52 void init(const SkScalar* pts, const unsigned char* verbs); 53 54 private: 55 const SkUnichar* fCharCodes; 56 const size_t fCharCodesCount; 57 const SkFixed* fWidths; 58 const SkFontMetrics& fMetrics; 59 const char* fName; 60 SkPath* fPaths; 61 friend class TestTypeface; 62 using INHERITED = SkRefCnt; 63 }; 64 65 class TestTypeface : public SkTypeface { 66 public: 67 TestTypeface(sk_sp<SkTestFont>, const SkFontStyle& style); 68 void getAdvance(SkGlyph* glyph); 69 void getFontMetrics(SkFontMetrics* metrics); 70 SkPath getPath(SkGlyphID glyph); 71 72 protected: 73 std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&, 74 const SkDescriptor* desc) const override; 75 void onFilterRec(SkScalerContextRec* rec) const override; 76 void getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const override; 77 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; 78 onOpenStream(int * ttcIndex)79 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; } 80 onMakeClone(const SkFontArguments & args)81 sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override { 82 return sk_ref_sp(this); 83 } 84 85 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override; 86 87 void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override; 88 onCountGlyphs()89 int onCountGlyphs() const override { return (int)fTestFont->fCharCodesCount; } 90 getPostScriptGlyphNames(SkString *)91 void getPostScriptGlyphNames(SkString*) const override {} 92 onGetUPEM()93 int onGetUPEM() const override { return 2048; } 94 95 void onGetFamilyName(SkString* familyName) const override; 96 bool onGetPostScriptName(SkString*) const override; 97 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; 98 onGlyphMaskNeedsCurrentColor()99 bool onGlyphMaskNeedsCurrentColor() const override { return false; } 100 onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],int coordinateCount)101 int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], 102 int coordinateCount) const override { 103 return 0; 104 } 105 onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],int parameterCount)106 int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], 107 int parameterCount) const override { 108 return 0; 109 } 110 onGetTableTags(SkFontTableTag tags[])111 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; } 112 onGetTableData(SkFontTableTag tag,size_t offset,size_t length,void * data)113 size_t onGetTableData(SkFontTableTag tag, 114 size_t offset, 115 size_t length, 116 void* data) const override { 117 return 0; 118 } 119 120 private: 121 sk_sp<SkTestFont> fTestFont; 122 friend class SkTestScalerContext; 123 }; 124 125 #endif 126