Flutter Engine
txt::FontCollection Class Reference

#include <font_collection.h>

Inheritance diagram for txt::FontCollection:

Public Member Functions

 FontCollection ()
 
 ~FontCollection ()
 
size_t GetFontManagersCount () const
 
void SetupDefaultFontManager (uint32_t font_initialization_data)
 
void SetDefaultFontManager (sk_sp< SkFontMgr > font_manager)
 
void SetAssetFontManager (sk_sp< SkFontMgr > font_manager)
 
void SetDynamicFontManager (sk_sp< SkFontMgr > font_manager)
 
void SetTestFontManager (sk_sp< SkFontMgr > font_manager)
 
std::shared_ptr< minikin::FontCollectionGetMinikinFontCollectionForFamilies (const std::vector< std::string > &font_families, const std::string &locale)
 
const std::shared_ptr< minikin::FontFamily > & MatchFallbackFont (uint32_t ch, std::string locale)
 
void DisableFontFallback ()
 
void ClearFontFamilyCache ()
 

Detailed Description

Definition at line 40 of file font_collection.h.

Constructor & Destructor Documentation

◆ FontCollection()

txt::FontCollection::FontCollection ( )

Definition at line 84 of file font_collection.cc.

84 : enable_font_fallback_(true) {}

◆ ~FontCollection()

txt::FontCollection::~FontCollection ( )

Definition at line 86 of file font_collection.cc.

References minikin::Layout::purgeCaches().

86  {
88 
89 #if FLUTTER_ENABLE_SKSHAPER
90  if (skt_collection_) {
91  skt_collection_->clearCaches();
92  }
93 #endif
94 }
static void purgeCaches()

Member Function Documentation

◆ ClearFontFamilyCache()

void txt::FontCollection::ClearFontFamilyCache ( )

Definition at line 384 of file font_collection.cc.

References txt::GetDefaultFontFamilies().

384  {
385  font_collections_cache_.clear();
386 
387 #if FLUTTER_ENABLE_SKSHAPER
388  if (skt_collection_) {
389  skt_collection_->clearCaches();
390  }
391 #endif
392 }

◆ DisableFontFallback()

void txt::FontCollection::DisableFontFallback ( )

Definition at line 151 of file font_collection.cc.

151  {
152  enable_font_fallback_ = false;
153 
154 #if FLUTTER_ENABLE_SKSHAPER
155  if (skt_collection_) {
156  skt_collection_->disableFontFallback();
157  }
158 #endif
159 }

◆ GetFontManagersCount()

size_t txt::FontCollection::GetFontManagersCount ( ) const

Definition at line 96 of file font_collection.cc.

96  {
97  return GetFontManagerOrder().size();
98 }

◆ GetMinikinFontCollectionForFamilies()

std::shared_ptr< minikin::FontCollection > txt::FontCollection::GetMinikinFontCollectionForFamilies ( const std::vector< std::string > &  font_families,
const std::string &  locale 
)

Definition at line 162 of file font_collection.cc.

References minikin::FontCollection::Create(), txt::GetDefaultFontFamilies(), TRACE_EVENT0, and TRACE_EVENT1.

164  {
165  // Look inside the font collections cache first.
166  FamilyKey family_key(font_families, locale);
167  auto cached = font_collections_cache_.find(family_key);
168  if (cached != font_collections_cache_.end()) {
169  return cached->second;
170  }
171 
172  std::vector<std::shared_ptr<minikin::FontFamily>> minikin_families;
173 
174  // Search for all user provided font families.
175  for (size_t fallback_index = 0; fallback_index < font_families.size();
176  fallback_index++) {
177  std::shared_ptr<minikin::FontFamily> minikin_family =
178  FindFontFamilyInManagers(font_families[fallback_index]);
179  if (minikin_family != nullptr) {
180  minikin_families.push_back(minikin_family);
181  }
182  }
183  // Search for default font family if no user font families were found.
184  if (minikin_families.empty()) {
185  const auto default_font_families = GetDefaultFontFamilies();
186  for (const auto& family : default_font_families) {
187  std::shared_ptr<minikin::FontFamily> minikin_family =
188  FindFontFamilyInManagers(family);
189  if (minikin_family != nullptr) {
190  minikin_families.push_back(minikin_family);
191  break;
192  }
193  }
194  }
195  // Default font family also not found. We fail to get a FontCollection.
196  if (minikin_families.empty()) {
197  font_collections_cache_[family_key] = nullptr;
198  return nullptr;
199  }
200  if (enable_font_fallback_) {
201  for (const std::string& fallback_family :
202  fallback_fonts_for_locale_[locale]) {
203  auto it = fallback_fonts_.find(fallback_family);
204  if (it != fallback_fonts_.end()) {
205  minikin_families.push_back(it->second);
206  }
207  }
208  }
209  // Create the minikin font collection.
210  auto font_collection =
211  minikin::FontCollection::Create(std::move(minikin_families));
212  if (!font_collection) {
213  font_collections_cache_[family_key] = nullptr;
214  return nullptr;
215  }
216  if (enable_font_fallback_) {
217  font_collection->set_fallback_font_provider(
218  std::make_unique<TxtFallbackFontProvider>(shared_from_this()));
219  }
220 
221  // Cache the font collection for future queries.
222  font_collections_cache_[family_key] = font_collection;
223 
224  return font_collection;
225 }
static std::shared_ptr< minikin::FontCollection > Create(const std::vector< std::shared_ptr< FontFamily >> &typefaces)
std::vector< std::string > GetDefaultFontFamilies()
Definition: platform.cc:9

◆ MatchFallbackFont()

const std::shared_ptr< minikin::FontFamily > & txt::FontCollection::MatchFallbackFont ( uint32_t  ch,
std::string  locale 
)

Definition at line 318 of file font_collection.cc.

References txt::end, match, and TRACE_EVENT0.

320  {
321  // Check if the ch's matched font has been cached. We cache the results of
322  // this method as repeated matchFamilyStyleCharacter calls can become
323  // extremely laggy when typing a large number of complex emojis.
324  auto lookup = fallback_match_cache_.find(ch);
325  if (lookup != fallback_match_cache_.end()) {
326  return *lookup->second;
327  }
328  const std::shared_ptr<minikin::FontFamily>* match =
329  &DoMatchFallbackFont(ch, locale);
330  fallback_match_cache_.insert(std::make_pair(ch, match));
331  return *match;
332 }
gchar * match
Definition: fl_engine.cc:78

◆ SetAssetFontManager()

void txt::FontCollection::SetAssetFontManager ( sk_sp< SkFontMgr >  font_manager)

Definition at line 113 of file font_collection.cc.

113  {
114  asset_font_manager_ = font_manager;
115 
116 #if FLUTTER_ENABLE_SKSHAPER
117  skt_collection_.reset();
118 #endif
119 }

◆ SetDefaultFontManager()

void txt::FontCollection::SetDefaultFontManager ( sk_sp< SkFontMgr >  font_manager)

Definition at line 105 of file font_collection.cc.

105  {
106  default_font_manager_ = font_manager;
107 
108 #if FLUTTER_ENABLE_SKSHAPER
109  skt_collection_.reset();
110 #endif
111 }

◆ SetDynamicFontManager()

void txt::FontCollection::SetDynamicFontManager ( sk_sp< SkFontMgr >  font_manager)

Definition at line 121 of file font_collection.cc.

121  {
122  dynamic_font_manager_ = font_manager;
123 
124 #if FLUTTER_ENABLE_SKSHAPER
125  skt_collection_.reset();
126 #endif
127 }

◆ SetTestFontManager()

void txt::FontCollection::SetTestFontManager ( sk_sp< SkFontMgr >  font_manager)

Definition at line 129 of file font_collection.cc.

129  {
130  test_font_manager_ = font_manager;
131 
132 #if FLUTTER_ENABLE_SKSHAPER
133  skt_collection_.reset();
134 #endif
135 }

◆ SetupDefaultFontManager()

void txt::FontCollection::SetupDefaultFontManager ( uint32_t  font_initialization_data)

Definition at line 100 of file font_collection.cc.

References txt::GetDefaultFontManager().

101  {
102  default_font_manager_ = GetDefaultFontManager(font_initialization_data);
103 }
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition: platform.cc:13

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