Debian Codegraph @

modules/skparagraph/include/FontCollection.h

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