skia2/modules/skparagraph/include/FontCollection.h
Jason Simmons 1a47d891c1 Add an API for clearing the SkParagraph font and paragraph caches
Change-Id: Id8de439c8d872a6dad56acb5db4153186a9a9d96
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/320397
Reviewed-by: Julia Lavrova <jlavrova@google.com>
Commit-Queue: Jason Simmons <jsimmons@google.com>
2020-09-29 19:56:08 +00:00

80 lines
2.4 KiB
C++

// Copyright 2019 Google LLC.
#ifndef FontCollection_DEFINED
#define FontCollection_DEFINED
#include <memory>
#include <set>
#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<SkFontMgr> fontManager);
void setDynamicFontManager(sk_sp<SkFontMgr> fontManager);
void setTestFontManager(sk_sp<SkFontMgr> fontManager);
void setDefaultFontManager(sk_sp<SkFontMgr> fontManager);
void setDefaultFontManager(sk_sp<SkFontMgr> fontManager, const char defaultFamilyName[]);
sk_sp<SkFontMgr> getFallbackManager() const { return fDefaultFontManager; }
std::vector<sk_sp<SkTypeface>> findTypefaces(const std::vector<SkString>& familyNames, SkFontStyle fontStyle);
sk_sp<SkTypeface> defaultFallback(SkUnichar unicode, SkFontStyle fontStyle, const SkString& locale);
sk_sp<SkTypeface> defaultFallback();
void disableFontFallback();
void enableFontFallback();
bool fontFallbackEnabled() { return fEnableFontFallback; }
ParagraphCache* getParagraphCache() { return &fParagraphCache; }
void clearCaches();
private:
std::vector<sk_sp<SkFontMgr>> getFontManagerOrder() const;
sk_sp<SkTypeface> matchTypeface(const SkString& familyName, SkFontStyle fontStyle);
struct FamilyKey {
FamilyKey(const std::vector<SkString>& familyNames, SkFontStyle style)
: fFamilyNames(familyNames), fFontStyle(style) {}
FamilyKey() {}
std::vector<SkString> fFamilyNames;
SkFontStyle fFontStyle;
bool operator==(const FamilyKey& other) const;
struct Hasher {
size_t operator()(const FamilyKey& key) const;
};
};
bool fEnableFontFallback;
SkTHashMap<FamilyKey, std::vector<sk_sp<SkTypeface>>, FamilyKey::Hasher> fTypefaces;
sk_sp<SkFontMgr> fDefaultFontManager;
sk_sp<SkFontMgr> fAssetFontManager;
sk_sp<SkFontMgr> fDynamicFontManager;
sk_sp<SkFontMgr> fTestFontManager;
SkString fDefaultFamilyName;
ParagraphCache fParagraphCache;
};
} // namespace textlayout
} // namespace skia
#endif // FontCollection_DEFINED