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