// 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(); 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[]); void setDefaultFontManager(sk_sp fontManager, const std::vector& defaultFamilyNames); sk_sp getFallbackManager() const { return fDefaultFontManager; } std::vector> findTypefaces(const std::vector& familyNames, SkFontStyle fontStyle); sk_sp defaultFallback(SkUnichar unicode, SkFontStyle fontStyle, const SkString& locale); sk_sp defaultFallback(); void disableFontFallback(); void enableFontFallback(); bool fontFallbackEnabled() { return fEnableFontFallback; } ParagraphCache* getParagraphCache() { return &fParagraphCache; } void clearCaches(); private: std::vector> getFontManagerOrder() const; sk_sp matchTypeface(const SkString& familyName, SkFontStyle fontStyle); struct FamilyKey { FamilyKey(const std::vector& familyNames, SkFontStyle style) : fFamilyNames(familyNames), fFontStyle(style) {} FamilyKey() {} std::vector fFamilyNames; 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; std::vector fDefaultFamilyNames; ParagraphCache fParagraphCache; }; } // namespace textlayout } // namespace skia #endif // FontCollection_DEFINED