Flutter Engine
The Flutter Engine
FontCollection.h
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2#ifndef FontCollection_DEFINED
3#define FontCollection_DEFINED
4
5#include <memory>
6#include <optional>
7#include <set>
10#include "include/core/SkSpan.h"
14#include "src/core/SkTHash.h"
15
16namespace skia {
17namespace textlayout {
18
19class TextStyle;
20class Paragraph;
21class FontCollection : public SkRefCnt {
22public:
24
25 size_t getFontManagersCount() const;
26
27 void setAssetFontManager(sk_sp<SkFontMgr> fontManager);
29 void setTestFontManager(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
40 sk_sp<SkTypeface> defaultEmojiFallback(SkUnichar emojiStart, SkFontStyle fontStyle, const SkString& locale);
42
44 void enableFontFallback();
45 bool fontFallbackEnabled() { return fEnableFontFallback; }
46
47 ParagraphCache* getParagraphCache() { return &fParagraphCache; }
48
49 void clearCaches();
50
51private:
52 std::vector<sk_sp<SkFontMgr>> getFontManagerOrder() const;
53
54 sk_sp<SkTypeface> matchTypeface(const SkString& familyName, SkFontStyle fontStyle);
55
56 struct FamilyKey {
57 FamilyKey(const std::vector<SkString>& familyNames, SkFontStyle style, const std::optional<FontArguments>& args)
58 : fFamilyNames(familyNames), fFontStyle(style), fFontArguments(args) {}
59
60 FamilyKey() {}
61
62 std::vector<SkString> fFamilyNames;
63 SkFontStyle fFontStyle;
64 std::optional<FontArguments> fFontArguments;
65
66 bool operator==(const FamilyKey& other) const;
67
68 struct Hasher {
69 size_t operator()(const FamilyKey& key) const;
70 };
71 };
72
73 bool fEnableFontFallback;
75 sk_sp<SkFontMgr> fDefaultFontManager;
76 sk_sp<SkFontMgr> fAssetFontManager;
77 sk_sp<SkFontMgr> fDynamicFontManager;
78 sk_sp<SkFontMgr> fTestFontManager;
79
80 std::vector<SkString> fDefaultFamilyNames;
81 ParagraphCache fParagraphCache;
82};
83} // namespace textlayout
84} // namespace skia
85
86#endif // FontCollection_DEFINED
int32_t SkUnichar
Definition: SkTypes.h:175
sk_sp< SkTypeface > defaultEmojiFallback(SkUnichar emojiStart, SkFontStyle fontStyle, const SkString &locale)
std::vector< sk_sp< SkTypeface > > findTypefaces(const std::vector< SkString > &familyNames, SkFontStyle fontStyle)
void setDefaultFontManager(sk_sp< SkFontMgr > fontManager)
void setAssetFontManager(sk_sp< SkFontMgr > fontManager)
sk_sp< SkFontMgr > getFallbackManager() const
ParagraphCache * getParagraphCache()
void setDynamicFontManager(sk_sp< SkFontMgr > fontManager)
void setTestFontManager(sk_sp< SkFontMgr > fontManager)
sk_sp< SkTypeface > defaultFallback()
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
bool operator==(const FontArguments &a, const FontArguments &b)
Definition: DartTypes.h:13
size_t operator()(const FamilyKey &key) const