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 ()
 
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 359 of file font_collection.cc.

References txt::GetDefaultFontFamilies().

359  {
360  font_collections_cache_.clear();
361 
362 #if FLUTTER_ENABLE_SKSHAPER
363  if (skt_collection_) {
364  skt_collection_->clearCaches();
365  }
366 #endif
367 }

◆ DisableFontFallback()

void txt::FontCollection::DisableFontFallback ( )

Definition at line 134 of file font_collection.cc.

134  {
135  enable_font_fallback_ = false;
136 
137 #if FLUTTER_ENABLE_SKSHAPER
138  if (skt_collection_) {
139  skt_collection_->disableFontFallback();
140  }
141 #endif
142 }

◆ 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 145 of file font_collection.cc.

References txt::GetDefaultFontFamilies(), TRACE_EVENT0, and TRACE_EVENT1.

147  {
148  // Look inside the font collections cache first.
149  FamilyKey family_key(font_families, locale);
150  auto cached = font_collections_cache_.find(family_key);
151  if (cached != font_collections_cache_.end()) {
152  return cached->second;
153  }
154 
155  std::vector<std::shared_ptr<minikin::FontFamily>> minikin_families;
156 
157  // Search for all user provided font families.
158  for (size_t fallback_index = 0; fallback_index < font_families.size();
159  fallback_index++) {
160  std::shared_ptr<minikin::FontFamily> minikin_family =
161  FindFontFamilyInManagers(font_families[fallback_index]);
162  if (minikin_family != nullptr) {
163  minikin_families.push_back(minikin_family);
164  }
165  }
166  // Search for default font family if no user font families were found.
167  if (minikin_families.empty()) {
168  const auto default_font_families = GetDefaultFontFamilies();
169  for (const auto& family : default_font_families) {
170  std::shared_ptr<minikin::FontFamily> minikin_family =
171  FindFontFamilyInManagers(family);
172  if (minikin_family != nullptr) {
173  minikin_families.push_back(minikin_family);
174  break;
175  }
176  }
177  }
178  // Default font family also not found. We fail to get a FontCollection.
179  if (minikin_families.empty()) {
180  font_collections_cache_[family_key] = nullptr;
181  return nullptr;
182  }
183  if (enable_font_fallback_) {
184  for (const std::string& fallback_family :
185  fallback_fonts_for_locale_[locale]) {
186  auto it = fallback_fonts_.find(fallback_family);
187  if (it != fallback_fonts_.end()) {
188  minikin_families.push_back(it->second);
189  }
190  }
191  }
192  // Create the minikin font collection.
193  auto font_collection =
194  std::make_shared<minikin::FontCollection>(std::move(minikin_families));
195  if (enable_font_fallback_) {
196  font_collection->set_fallback_font_provider(
197  std::make_unique<TxtFallbackFontProvider>(shared_from_this()));
198  }
199 
200  // Cache the font collection for future queries.
201  font_collections_cache_[family_key] = font_collection;
202 
203  return font_collection;
204 }
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 293 of file font_collection.cc.

References txt::end, and TRACE_EVENT0.

295  {
296  // Check if the ch's matched font has been cached. We cache the results of
297  // this method as repeated matchFamilyStyleCharacter calls can become
298  // extremely laggy when typing a large number of complex emojis.
299  auto lookup = fallback_match_cache_.find(ch);
300  if (lookup != fallback_match_cache_.end()) {
301  return *lookup->second;
302  }
303  const std::shared_ptr<minikin::FontFamily>* match =
304  &DoMatchFallbackFont(ch, locale);
305  fallback_match_cache_.insert(std::make_pair(ch, match));
306  return *match;
307 }

◆ SetAssetFontManager()

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

Definition at line 108 of file font_collection.cc.

108  {
109  asset_font_manager_ = font_manager;
110 }

◆ SetDefaultFontManager()

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

Definition at line 104 of file font_collection.cc.

104  {
105  default_font_manager_ = font_manager;
106 }

◆ SetDynamicFontManager()

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

Definition at line 112 of file font_collection.cc.

112  {
113  dynamic_font_manager_ = font_manager;
114 }

◆ SetTestFontManager()

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

Definition at line 116 of file font_collection.cc.

116  {
117  test_font_manager_ = font_manager;
118 }

◆ SetupDefaultFontManager()

void txt::FontCollection::SetupDefaultFontManager ( )

Definition at line 100 of file font_collection.cc.

References txt::GetDefaultFontManager().

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

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