2019-05-30 20:12:56 +00:00
|
|
|
// 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"
|
2019-07-30 17:32:08 +00:00
|
|
|
#include "modules/skparagraph/include/ParagraphCache.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "modules/skparagraph/include/TextStyle.h"
|
2019-05-30 20:12:56 +00:00
|
|
|
|
|
|
|
namespace skia {
|
|
|
|
namespace textlayout {
|
|
|
|
|
2019-07-30 17:32:08 +00:00
|
|
|
class TextStyle;
|
|
|
|
class Paragraph;
|
2019-05-30 20:12:56 +00:00
|
|
|
class FontCollection : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
FontCollection();
|
|
|
|
|
2019-06-17 14:34:10 +00:00
|
|
|
~FontCollection() = default;
|
2019-05-30 20:12:56 +00:00
|
|
|
|
|
|
|
size_t getFontManagersCount() const;
|
|
|
|
|
|
|
|
void setAssetFontManager(sk_sp<SkFontMgr> fontManager);
|
|
|
|
void setDynamicFontManager(sk_sp<SkFontMgr> fontManager);
|
|
|
|
void setTestFontManager(sk_sp<SkFontMgr> fontManager);
|
2019-06-21 16:22:32 +00:00
|
|
|
void setDefaultFontManager(sk_sp<SkFontMgr> fontManager);
|
2019-05-30 20:12:56 +00:00
|
|
|
void setDefaultFontManager(sk_sp<SkFontMgr> fontManager, const char defaultFamilyName[]);
|
|
|
|
|
2019-09-26 17:20:50 +00:00
|
|
|
sk_sp<SkFontMgr> getFallbackManager() const { return fDefaultFontManager; }
|
2019-05-30 20:12:56 +00:00
|
|
|
|
2019-08-21 21:49:44 +00:00
|
|
|
sk_sp<SkTypeface> matchTypeface(const char familyName[], SkFontStyle fontStyle, const SkString& locale);
|
|
|
|
sk_sp<SkTypeface> matchDefaultTypeface(SkFontStyle fontStyle, const SkString& locale);
|
2019-06-21 16:22:32 +00:00
|
|
|
sk_sp<SkTypeface> defaultFallback(SkUnichar unicode, SkFontStyle fontStyle, const SkString& locale);
|
2019-08-21 21:49:44 +00:00
|
|
|
sk_sp<SkTypeface> defaultFallback();
|
2019-05-30 20:12:56 +00:00
|
|
|
|
|
|
|
void disableFontFallback();
|
|
|
|
bool fontFallbackEnabled() { return fEnableFontFallback; }
|
|
|
|
|
2019-07-30 17:32:08 +00:00
|
|
|
ParagraphCache* getParagraphCache() { return &fParagraphCache; }
|
|
|
|
|
2019-05-30 20:12:56 +00:00
|
|
|
private:
|
|
|
|
std::vector<sk_sp<SkFontMgr>> 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, sk_sp<SkTypeface>, FamilyKey::Hasher> fTypefaces;
|
|
|
|
sk_sp<SkFontMgr> fDefaultFontManager;
|
|
|
|
sk_sp<SkFontMgr> fAssetFontManager;
|
|
|
|
sk_sp<SkFontMgr> fDynamicFontManager;
|
|
|
|
sk_sp<SkFontMgr> fTestFontManager;
|
2019-07-30 17:32:08 +00:00
|
|
|
|
2019-08-21 17:49:15 +00:00
|
|
|
SkString fDefaultFamilyName;
|
2019-07-30 17:32:08 +00:00
|
|
|
ParagraphCache fParagraphCache;
|
2019-05-30 20:12:56 +00:00
|
|
|
};
|
|
|
|
} // namespace textlayout
|
|
|
|
} // namespace skia
|
|
|
|
|
|
|
|
#endif // FontCollection_DEFINED
|