// Copyright 2019 Google LLC. #ifndef FontCollection_DEFINED #define FontCollection_DEFINED #include #include #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" #include "include/private/SkTHash.h" #include "modules/skparagraph/include/ParagraphCache.h" #include "modules/skparagraph/include/TextStyle.h" namespace skia { namespace textlayout { class TextStyle; class Paragraph; class FontCollection : public SkRefCnt { public: FontCollection(); ~FontCollection() = default; size_t getFontManagersCount() const; void setAssetFontManager(sk_sp fontManager); void setDynamicFontManager(sk_sp fontManager); void setTestFontManager(sk_sp fontManager); void setDefaultFontManager(sk_sp fontManager); void setDefaultFontManager(sk_sp fontManager, const char defaultFamilyName[]); sk_sp getFallbackManager() const { return fDefaultFontManager; } sk_sp matchTypeface(const char familyName[], SkFontStyle fontStyle, const SkString& locale); sk_sp matchDefaultTypeface(SkFontStyle fontStyle, const SkString& locale); sk_sp defaultFallback(SkUnichar unicode, SkFontStyle fontStyle, const SkString& locale); sk_sp defaultFallback(); void disableFontFallback(); bool fontFallbackEnabled() { return fEnableFontFallback; } ParagraphCache* getParagraphCache() { return &fParagraphCache; } private: std::vector> getFontManagerOrder() const; struct FamilyKey { FamilyKey(const char family[], const char loc[], SkFontStyle style) : fFontFamily(family), fLocale(loc), fFontStyle(style) {} FamilyKey() {} SkString fFontFamily; SkString fLocale; SkFontStyle fFontStyle; bool operator==(const FamilyKey& other) const; struct Hasher { size_t operator()(const FamilyKey& key) const; }; }; bool fEnableFontFallback; SkTHashMap, FamilyKey::Hasher> fTypefaces; sk_sp fDefaultFontManager; sk_sp fAssetFontManager; sk_sp fDynamicFontManager; sk_sp fTestFontManager; SkString fDefaultFamilyName; ParagraphCache fParagraphCache; }; } // namespace textlayout } // namespace skia #endif // FontCollection_DEFINED