Debian Codegraph @

modules/skparagraph/include/TypefaceFontProvider.h

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