1 // Copyright 2019 Google LLC. 2 #ifndef TypefaceFontProvider_DEFINED 3 #define TypefaceFontProvider_DEFINED 4 5 #include "include/private/SkTArray.h" 6 #include "include/private/SkTHash.h" 7 #include <string> 8 #include <unordered_map> 9 #include <vector> 10 #include "include/core/SkFontMgr.h" 11 #include "include/core/SkStream.h" 12 #include "include/core/SkString.h" 13 #include "src/core/SkFontDescriptor.h" 14 15 namespace skia { 16 namespace textlayout { 17 18 class TypefaceFontStyleSet : public SkFontStyleSet { 19 public: 20 explicit TypefaceFontStyleSet(const SkString& familyName); 21 22 int count() override; 23 void getStyle(int index, SkFontStyle*, SkString* name) override; 24 SkTypeface* createTypeface(int index) override; 25 SkTypeface* matchStyle(const SkFontStyle& pattern) override; 26 getFamilyName()27 SkString getFamilyName() const { return fFamilyName; } getAlias()28 SkString getAlias() const { return fAlias; } 29 void appendTypeface(sk_sp<SkTypeface> typeface); 30 31 private: 32 SkTArray<sk_sp<SkTypeface>> fStyles; 33 SkString fFamilyName; 34 SkString fAlias; 35 }; 36 37 class TypefaceFontProvider : public SkFontMgr { 38 public: 39 size_t registerTypeface(sk_sp<SkTypeface> typeface); 40 size_t registerTypeface(sk_sp<SkTypeface> typeface, const SkString& alias); 41 42 int onCountFamilies() const override; 43 44 void onGetFamilyName(int index, SkString* familyName) const override; 45 46 SkFontStyleSet* onMatchFamily(const char familyName[]) const override; 47 onCreateStyleSet(int index)48 SkFontStyleSet* onCreateStyleSet(int index) const override { return nullptr; } onMatchFamilyStyle(const char familyName[],const SkFontStyle & style)49 SkTypeface* onMatchFamilyStyle(const char familyName[], 50 const SkFontStyle& style) const override { 51 return nullptr; 52 } onMatchFamilyStyleCharacter(const char familyName[],const SkFontStyle & style,const char * bcp47[],int bcp47Count,SkUnichar character)53 SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style, 54 const char* bcp47[], int bcp47Count, 55 SkUnichar character) const override { 56 return nullptr; 57 } onMatchFaceStyle(const SkTypeface * tf,const SkFontStyle & style)58 SkTypeface* onMatchFaceStyle(const SkTypeface* tf, const SkFontStyle& style) const override { 59 return nullptr; 60 } 61 onMakeFromData(sk_sp<SkData>,int ttcIndex)62 sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override { return nullptr; } onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,int ttcIndex)63 sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, 64 int ttcIndex) const override { 65 return nullptr; 66 } onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,const SkFontArguments &)67 sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, 68 const SkFontArguments&) const override { 69 return nullptr; 70 } onMakeFromFontData(std::unique_ptr<SkFontData>)71 sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const override { 72 return nullptr; 73 } onMakeFromFile(const char path[],int ttcIndex)74 sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override { 75 return nullptr; 76 } 77 onLegacyMakeTypeface(const char familyName[],SkFontStyle style)78 sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], 79 SkFontStyle style) const override { 80 return nullptr; 81 } 82 83 private: 84 SkTHashMap<SkString, sk_sp<TypefaceFontStyleSet>> fRegisteredFamilies; 85 SkTArray<SkString> fFamilyNames; 86 }; 87 } // namespace textlayout 88 } // namespace skia 89 90 #endif // TypefaceFontProvider_DEFINED 91