Flutter Engine
txt::TypefaceFontAssetProvider Class Reference

#include <typeface_font_asset_provider.h>

Inheritance diagram for txt::TypefaceFontAssetProvider:
txt::FontAssetProvider

Public Member Functions

 TypefaceFontAssetProvider ()
 
 ~TypefaceFontAssetProvider () override
 
void RegisterTypeface (sk_sp< SkTypeface > typeface)
 
void RegisterTypeface (sk_sp< SkTypeface > typeface, std::string family_name_alias)
 
size_t GetFamilyCount () const override
 
std::string GetFamilyName (int index) const override
 
SkFontStyleSet * MatchFamily (const std::string &family_name) override
 
- Public Member Functions inherited from txt::FontAssetProvider
virtual ~FontAssetProvider ()=default
 

Additional Inherited Members

- Static Protected Member Functions inherited from txt::FontAssetProvider
static std::string CanonicalFamilyName (std::string family_name)
 

Detailed Description

Definition at line 56 of file typeface_font_asset_provider.h.

Constructor & Destructor Documentation

◆ TypefaceFontAssetProvider()

txt::TypefaceFontAssetProvider::TypefaceFontAssetProvider ( )
default

◆ ~TypefaceFontAssetProvider()

txt::TypefaceFontAssetProvider::~TypefaceFontAssetProvider ( )
overridedefault

Member Function Documentation

◆ GetFamilyCount()

size_t txt::TypefaceFontAssetProvider::GetFamilyCount ( ) const
overridevirtual

Implements txt::FontAssetProvider.

Definition at line 30 of file typeface_font_asset_provider.cc.

30  {
31  return family_names_.size();
32 }

◆ GetFamilyName()

std::string txt::TypefaceFontAssetProvider::GetFamilyName ( int  index) const
overridevirtual

Implements txt::FontAssetProvider.

Definition at line 35 of file typeface_font_asset_provider.cc.

35  {
36  return family_names_[index];
37 }

◆ MatchFamily()

SkFontStyleSet * txt::TypefaceFontAssetProvider::MatchFamily ( const std::string &  family_name)
overridevirtual

Implements txt::FontAssetProvider.

Definition at line 40 of file typeface_font_asset_provider.cc.

References txt::FontAssetProvider::CanonicalFamilyName().

41  {
42  auto found = registered_families_.find(CanonicalFamilyName(family_name));
43  if (found == registered_families_.end()) {
44  return nullptr;
45  }
46  sk_sp<TypefaceFontStyleSet> font_style_set = found->second;
47  return font_style_set.release();
48 }
static std::string CanonicalFamilyName(std::string family_name)

◆ RegisterTypeface() [1/2]

void txt::TypefaceFontAssetProvider::RegisterTypeface ( sk_sp< SkTypeface >  typeface)

Definition at line 50 of file typeface_font_asset_provider.cc.

Referenced by flutter::FontCollection::LoadFontFromList(), and txt::RegisterFontsFromPath().

50  {
51  if (typeface == nullptr) {
52  return;
53  }
54 
55  SkString sk_family_name;
56  typeface->getFamilyName(&sk_family_name);
57 
58  std::string family_name(sk_family_name.c_str(), sk_family_name.size());
59  RegisterTypeface(std::move(typeface), std::move(family_name));
60 }
void RegisterTypeface(sk_sp< SkTypeface > typeface)

◆ RegisterTypeface() [2/2]

void txt::TypefaceFontAssetProvider::RegisterTypeface ( sk_sp< SkTypeface >  typeface,
std::string  family_name_alias 
)

Definition at line 62 of file typeface_font_asset_provider.cc.

References txt::FontAssetProvider::CanonicalFamilyName(), txt::TypefaceFontStyleSet::TypefaceFontStyleSet(), value, and txt::TypefaceFontStyleSet::~TypefaceFontStyleSet().

64  {
65  if (family_name_alias.empty()) {
66  return;
67  }
68 
69  std::string canonical_name = CanonicalFamilyName(family_name_alias);
70  auto family_it = registered_families_.find(canonical_name);
71  if (family_it == registered_families_.end()) {
72  family_names_.push_back(family_name_alias);
73  auto value =
74  std::make_pair(canonical_name, sk_make_sp<TypefaceFontStyleSet>());
75  family_it = registered_families_.emplace(value).first;
76  }
77  family_it->second->registerTypeface(std::move(typeface));
78 }
uint8_t value
static std::string CanonicalFamilyName(std::string family_name)

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