Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
skia::textlayout::FontCollection Class Reference

#include <FontCollection.h>

Inheritance diagram for skia::textlayout::FontCollection:
SkRefCnt SkRefCntBase skia::textlayout::TestFontCollection

Public Member Functions

 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[])
 
void setDefaultFontManager (sk_sp< SkFontMgr > fontManager, const std::vector< SkString > &defaultFamilyNames)
 
sk_sp< SkFontMgrgetFallbackManager () const
 
std::vector< sk_sp< SkTypeface > > findTypefaces (const std::vector< SkString > &familyNames, SkFontStyle fontStyle)
 
std::vector< sk_sp< SkTypeface > > findTypefaces (const std::vector< SkString > &familyNames, SkFontStyle fontStyle, const std::optional< FontArguments > &fontArgs)
 
sk_sp< SkTypefacedefaultFallback (SkUnichar unicode, SkFontStyle fontStyle, const SkString &locale)
 
sk_sp< SkTypefacedefaultEmojiFallback (SkUnichar emojiStart, SkFontStyle fontStyle, const SkString &locale)
 
sk_sp< SkTypefacedefaultFallback ()
 
void disableFontFallback ()
 
void enableFontFallback ()
 
bool fontFallbackEnabled ()
 
ParagraphCachegetParagraphCache ()
 
void clearCaches ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Detailed Description

Definition at line 21 of file FontCollection.h.

Constructor & Destructor Documentation

◆ FontCollection()

skia::textlayout::FontCollection::FontCollection ( )

Definition at line 36 of file FontCollection.cpp.

37 : fEnableFontFallback(true)
38 , fDefaultFamilyNames({SkString(DEFAULT_FONT_FAMILY)}) { }
#define DEFAULT_FONT_FAMILY
Definition: TextStyle.h:19

Member Function Documentation

◆ clearCaches()

void skia::textlayout::FontCollection::clearCaches ( )

Definition at line 221 of file FontCollection.cpp.

221 {
222 fParagraphCache.reset();
223 fTypefaces.reset();
225}
SKSHAPER_API void PurgeCaches()

◆ defaultEmojiFallback()

sk_sp< SkTypeface > skia::textlayout::FontCollection::defaultEmojiFallback ( SkUnichar  emojiStart,
SkFontStyle  fontStyle,
const SkString locale 
)

Definition at line 173 of file FontCollection.cpp.

175 {
176
177 for (const auto& manager : this->getFontManagerOrder()) {
178 std::vector<const char*> bcp47;
179#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
180 sk_sp<SkTypeface> emojiTypeface =
181 fDefaultFontManager->matchFamilyStyle(kColorEmojiFontMac, SkFontStyle());
182 if (emojiTypeface != nullptr) {
183 return emojiTypeface;
184 }
185#else
186 bcp47.push_back(kColorEmojiLocale);
187#endif
188 if (!locale.isEmpty()) {
189 bcp47.push_back(locale.c_str());
190 }
191
192 // Not really ideal since the first codepoint may not be the best one
193 // but we start from a good colored emoji at least
194 sk_sp<SkTypeface> typeface(manager->matchFamilyStyleCharacter(
195 nullptr, fontStyle, bcp47.data(), bcp47.size(), emojiStart));
196 if (typeface != nullptr) {
197 // ... and stop as soon as we find something in hope it will work for all of them
198 return typeface;
199 }
200 }
201 return nullptr;
202}
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
bool isEmpty() const
Definition: SkString.h:130
const char * c_str() const
Definition: SkString.h:133
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font manager
Definition: switches.h:218

◆ defaultFallback() [1/2]

sk_sp< SkTypeface > skia::textlayout::FontCollection::defaultFallback ( )

Definition at line 204 of file FontCollection.cpp.

204 {
205 if (fDefaultFontManager == nullptr) {
206 return nullptr;
207 }
208 for (const SkString& familyName : fDefaultFamilyNames) {
209 sk_sp<SkTypeface> match = fDefaultFontManager->matchFamilyStyle(familyName.c_str(),
210 SkFontStyle());
211 if (match) {
212 return match;
213 }
214 }
215 return nullptr;
216}
def match(bench, filt)
Definition: benchmark.py:23

◆ defaultFallback() [2/2]

sk_sp< SkTypeface > skia::textlayout::FontCollection::defaultFallback ( SkUnichar  unicode,
SkFontStyle  fontStyle,
const SkString locale 
)

Definition at line 153 of file FontCollection.cpp.

155 {
156
157 for (const auto& manager : this->getFontManagerOrder()) {
158 std::vector<const char*> bcp47;
159 if (!locale.isEmpty()) {
160 bcp47.push_back(locale.c_str());
161 }
162 sk_sp<SkTypeface> typeface(manager->matchFamilyStyleCharacter(
163 nullptr, fontStyle, bcp47.data(), bcp47.size(), unicode));
164
165 if (typeface != nullptr) {
166 return typeface;
167 }
168 }
169 return nullptr;
170}

◆ disableFontFallback()

void skia::textlayout::FontCollection::disableFontFallback ( )

Definition at line 218 of file FontCollection.cpp.

218{ fEnableFontFallback = false; }

◆ enableFontFallback()

void skia::textlayout::FontCollection::enableFontFallback ( )

Definition at line 219 of file FontCollection.cpp.

219{ fEnableFontFallback = true; }

◆ findTypefaces() [1/2]

std::vector< sk_sp< SkTypeface > > skia::textlayout::FontCollection::findTypefaces ( const std::vector< SkString > &  familyNames,
SkFontStyle  fontStyle 
)

Definition at line 88 of file FontCollection.cpp.

88 {
89 return findTypefaces(familyNames, fontStyle, std::nullopt);
90}
std::vector< sk_sp< SkTypeface > > findTypefaces(const std::vector< SkString > &familyNames, SkFontStyle fontStyle)

◆ findTypefaces() [2/2]

std::vector< sk_sp< SkTypeface > > skia::textlayout::FontCollection::findTypefaces ( const std::vector< SkString > &  familyNames,
SkFontStyle  fontStyle,
const std::optional< FontArguments > &  fontArgs 
)

Definition at line 92 of file FontCollection.cpp.

92 {
93 // Look inside the font collections cache first
94 FamilyKey familyKey(familyNames, fontStyle, fontArgs);
95 auto found = fTypefaces.find(familyKey);
96 if (found) {
97 return *found;
98 }
99
100 std::vector<sk_sp<SkTypeface>> typefaces;
101 for (const SkString& familyName : familyNames) {
102 sk_sp<SkTypeface> match = matchTypeface(familyName, fontStyle);
103 if (match && fontArgs) {
104 match = fontArgs->CloneTypeface(match);
105 }
106 if (match) {
107 typefaces.emplace_back(std::move(match));
108 }
109 }
110
111 if (typefaces.empty()) {
113 for (const SkString& familyName : fDefaultFamilyNames) {
114 match = matchTypeface(familyName, fontStyle);
115 if (match) {
116 break;
117 }
118 }
119 if (!match) {
120 for (const auto& manager : this->getFontManagerOrder()) {
121 match = manager->legacyMakeTypeface(nullptr, fontStyle);
122 if (match) {
123 break;
124 }
125 }
126 }
127 if (match) {
128 typefaces.emplace_back(std::move(match));
129 }
130 }
131
132 fTypefaces.set(familyKey, typefaces);
133 return typefaces;
134}

◆ fontFallbackEnabled()

bool skia::textlayout::FontCollection::fontFallbackEnabled ( )
inline

Definition at line 45 of file FontCollection.h.

45{ return fEnableFontFallback; }

◆ getFallbackManager()

sk_sp< SkFontMgr > skia::textlayout::FontCollection::getFallbackManager ( ) const
inline

Definition at line 34 of file FontCollection.h.

34{ return fDefaultFontManager; }

◆ getFontManagersCount()

size_t skia::textlayout::FontCollection::getFontManagersCount ( ) const

Definition at line 40 of file FontCollection.cpp.

40{ return this->getFontManagerOrder().size(); }

◆ getParagraphCache()

ParagraphCache * skia::textlayout::FontCollection::getParagraphCache ( )
inline

Definition at line 47 of file FontCollection.h.

47{ return &fParagraphCache; }

◆ setAssetFontManager()

void skia::textlayout::FontCollection::setAssetFontManager ( sk_sp< SkFontMgr fontManager)

Definition at line 42 of file FontCollection.cpp.

42 {
43 fAssetFontManager = std::move(font_manager);
44}

◆ setDefaultFontManager() [1/3]

void skia::textlayout::FontCollection::setDefaultFontManager ( sk_sp< SkFontMgr fontManager)

Definition at line 66 of file FontCollection.cpp.

66 {
67 fDefaultFontManager = std::move(fontManager);
68}

◆ setDefaultFontManager() [2/3]

void skia::textlayout::FontCollection::setDefaultFontManager ( sk_sp< SkFontMgr fontManager,
const char  defaultFamilyName[] 
)

Definition at line 54 of file FontCollection.cpp.

55 {
56 fDefaultFontManager = std::move(fontManager);
57 fDefaultFamilyNames.emplace_back(defaultFamilyName);
58}

◆ setDefaultFontManager() [3/3]

void skia::textlayout::FontCollection::setDefaultFontManager ( sk_sp< SkFontMgr fontManager,
const std::vector< SkString > &  defaultFamilyNames 
)

Definition at line 60 of file FontCollection.cpp.

61 {
62 fDefaultFontManager = std::move(fontManager);
63 fDefaultFamilyNames = defaultFamilyNames;
64}

◆ setDynamicFontManager()

void skia::textlayout::FontCollection::setDynamicFontManager ( sk_sp< SkFontMgr fontManager)

Definition at line 46 of file FontCollection.cpp.

46 {
47 fDynamicFontManager = std::move(font_manager);
48}

◆ setTestFontManager()

void skia::textlayout::FontCollection::setTestFontManager ( sk_sp< SkFontMgr fontManager)

Definition at line 50 of file FontCollection.cpp.

50 {
51 fTestFontManager = std::move(font_manager);
52}

The documentation for this class was generated from the following files: