skia2/modules/skparagraph/include/FontCollection.h
Kevin Lubick 61887c7b88 [canvaskit] Create SkFontMgr from passed in data
This repurposes much of our embedded SkFontMgr code
to take in data directly instead of from compiled-in
variables.

Also makes no_font and no_embedded_font work better.

Bug: skia:9469
Change-Id: Ibde49c9a448cfca79c5712aa9abbe15997a163d0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/244510
Reviewed-by: Ben Wagner <bungeman@google.com>
2019-09-26 19:27:12 +00:00

78 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();
~FontCollection() = default;
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; }
sk_sp<SkTypeface> matchTypeface(const char familyName[], SkFontStyle fontStyle, const SkString& locale);
sk_sp<SkTypeface> matchDefaultTypeface(SkFontStyle fontStyle, const SkString& locale);
sk_sp<SkTypeface> defaultFallback(SkUnichar unicode, SkFontStyle fontStyle, const SkString& locale);
sk_sp<SkTypeface> defaultFallback();
void disableFontFallback();
bool fontFallbackEnabled() { return fEnableFontFallback; }
ParagraphCache* getParagraphCache() { return &fParagraphCache; }
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;
SkString fDefaultFamilyName;
ParagraphCache fParagraphCache;
};
} // namespace textlayout
} // namespace skia
#endif // FontCollection_DEFINED