• 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 
30 private:
31     SkTArray<sk_sp<SkTypeface>> fStyles;
32     SkString fFamilyName;
33     SkString fAlias;
34 };
35 
36 class TypefaceFontProvider : public SkFontMgr {
37 public:
38     size_t registerTypeface(sk_sp<SkTypeface> typeface);
39     size_t registerTypeface(sk_sp<SkTypeface> typeface, const SkString& alias);
40 
41     int onCountFamilies() const override;
42 
43     void onGetFamilyName(int index, SkString* familyName) const override;
44 
45     SkFontStyleSet* onMatchFamily(const char familyName[]) const override;
46 
onCreateStyleSet(int)47     SkFontStyleSet* onCreateStyleSet(int) const override { return nullptr; }
onMatchFamilyStyle(const char[],const SkFontStyle &)48     SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override {
49         return nullptr;
50     }
onMatchFamilyStyleCharacter(const char[],const SkFontStyle &,const char * [],int,SkUnichar)51     SkTypeface* onMatchFamilyStyleCharacter(const char[], const SkFontStyle&,
52                                             const char*[], int,
53                                             SkUnichar) const override {
54         return nullptr;
55     }
56 
onMakeFromData(sk_sp<SkData>,int)57     sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int) const override { return nullptr; }
onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,int)58     sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int) const override {
59         return nullptr;
60     }
onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,const SkFontArguments &)61     sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
62                                            const SkFontArguments&) const override {
63         return nullptr;
64     }
65     sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const override;
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