• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 namespace skia {
15 namespace textlayout {
16 
17 class TypefaceFontStyleSet : public SkFontStyleSet {
18 public:
19     explicit TypefaceFontStyleSet(const SkString& familyName);
20 
21     int count() override;
22     void getStyle(int index, SkFontStyle*, SkString* name) override;
23     SkTypeface* createTypeface(int index) override;
24     SkTypeface* matchStyle(const SkFontStyle& pattern) override;
25 
getFamilyName()26     SkString getFamilyName() const { return fFamilyName; }
getAlias()27     SkString getAlias() const { return fAlias; }
28     void appendTypeface(sk_sp<SkTypeface> typeface);
29     void clearTypefaces();
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)48     SkFontStyleSet* onCreateStyleSet(int) const override { return nullptr; }
onMatchFamilyStyle(const char[],const SkFontStyle &)49     SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override {
50         return nullptr;
51     }
onMatchFamilyStyleCharacter(const char[],const SkFontStyle &,const char * [],int,SkUnichar)52     SkTypeface* onMatchFamilyStyleCharacter(const char[], const SkFontStyle&,
53                                                   const char*[], int,
54                                                   SkUnichar) const override {
55         return nullptr;
56     }
57 
onMakeFromData(sk_sp<SkData>,int)58     sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int) const override { return nullptr; }
onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,int)59     sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int) const override {
60         return nullptr;
61     }
onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,const SkFontArguments &)62     sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
63                                            const SkFontArguments&) const override {
64         return nullptr;
65     }
onMakeFromFile(const char[],int)66     sk_sp<SkTypeface> onMakeFromFile(const char[], int) const override {
67         return nullptr;
68     }
69 
onLegacyMakeTypeface(const char[],SkFontStyle)70     sk_sp<SkTypeface> onLegacyMakeTypeface(const char[], SkFontStyle) const override {
71         return nullptr;
72     }
73 
74 private:
75     SkTHashMap<SkString, sk_sp<TypefaceFontStyleSet>> fRegisteredFamilies;
76     SkTArray<SkString> fFamilyNames;
77 };
78 
79 }  // namespace textlayout
80 }  // namespace skia
81 
82 #endif  // TypefaceFontProvider_DEFINED
83