1 | // Copyright 2019 Google LLC. |
---|---|
2 | #ifndef FontCollection_DEFINED |
3 | #define FontCollection_DEFINED |
4 | |
5 | #include <memory> |
6 | #include <set> |
7 | #include "include/core/SkFontMgr.h" |
8 | #include "include/core/SkRefCnt.h" |
9 | #include "include/private/SkTHash.h" |
10 | #include "modules/skparagraph/include/ParagraphCache.h" |
11 | #include "modules/skparagraph/include/TextStyle.h" |
12 | |
13 | namespace skia { |
14 | namespace textlayout { |
15 | |
16 | class TextStyle; |
17 | class Paragraph; |
18 | class FontCollection : public SkRefCnt { |
19 | public: |
20 | FontCollection(); |
21 | |
22 | size_t getFontManagersCount() const; |
23 | |
24 | void setAssetFontManager(sk_sp<SkFontMgr> fontManager); |
25 | void setDynamicFontManager(sk_sp<SkFontMgr> fontManager); |
26 | void setTestFontManager(sk_sp<SkFontMgr> fontManager); |
27 | void setDefaultFontManager(sk_sp<SkFontMgr> fontManager); |
28 | void setDefaultFontManager(sk_sp<SkFontMgr> fontManager, const char defaultFamilyName[]); |
29 | |
30 | sk_sp<SkFontMgr> getFallbackManager() const { return fDefaultFontManager; } |
31 | |
32 | std::vector<sk_sp<SkTypeface>> findTypefaces(const std::vector<SkString>& familyNames, SkFontStyle fontStyle); |
33 | |
34 | sk_sp<SkTypeface> defaultFallback(SkUnichar unicode, SkFontStyle fontStyle, const SkString& locale); |
35 | sk_sp<SkTypeface> defaultFallback(); |
36 | |
37 | void disableFontFallback(); |
38 | void enableFontFallback(); |
39 | bool fontFallbackEnabled() { return fEnableFontFallback; } |
40 | |
41 | ParagraphCache* getParagraphCache() { return &fParagraphCache; } |
42 | |
43 | private: |
44 | std::vector<sk_sp<SkFontMgr>> getFontManagerOrder() const; |
45 | |
46 | sk_sp<SkTypeface> matchTypeface(const SkString& familyName, SkFontStyle fontStyle); |
47 | |
48 | struct FamilyKey { |
49 | FamilyKey(const std::vector<SkString>& familyNames, SkFontStyle style) |
50 | : fFamilyNames(familyNames), fFontStyle(style) {} |
51 | |
52 | FamilyKey() {} |
53 | |
54 | std::vector<SkString> fFamilyNames; |
55 | SkFontStyle fFontStyle; |
56 | |
57 | bool operator==(const FamilyKey& other) const; |
58 | |
59 | struct Hasher { |
60 | size_t operator()(const FamilyKey& key) const; |
61 | }; |
62 | }; |
63 | |
64 | bool fEnableFontFallback; |
65 | SkTHashMap<FamilyKey, std::vector<sk_sp<SkTypeface>>, FamilyKey::Hasher> fTypefaces; |
66 | sk_sp<SkFontMgr> fDefaultFontManager; |
67 | sk_sp<SkFontMgr> fAssetFontManager; |
68 | sk_sp<SkFontMgr> fDynamicFontManager; |
69 | sk_sp<SkFontMgr> fTestFontManager; |
70 | |
71 | SkString fDefaultFamilyName; |
72 | ParagraphCache fParagraphCache; |
73 | }; |
74 | } // namespace textlayout |
75 | } // namespace skia |
76 | |
77 | #endif // FontCollection_DEFINED |
78 |