Flutter Engine
flutter::AssetManagerFontStyleSet Class Reference

#include <asset_manager_font_provider.h>

Inheritance diagram for flutter::AssetManagerFontStyleSet:

Public Member Functions

 AssetManagerFontStyleSet (std::shared_ptr< AssetManager > asset_manager, std::string family_name)
 
 ~AssetManagerFontStyleSet () override
 
void registerAsset (std::string asset)
 
int count () override
 
void getStyle (int index, SkFontStyle *, SkString *style) override
 
SkTypeface * createTypeface (int index) override
 
SkTypeface * matchStyle (const SkFontStyle &pattern) override
 

Detailed Description

Definition at line 21 of file asset_manager_font_provider.h.

Constructor & Destructor Documentation

◆ AssetManagerFontStyleSet()

flutter::AssetManagerFontStyleSet::AssetManagerFontStyleSet ( std::shared_ptr< AssetManager asset_manager,
std::string  family_name 
)

Definition at line 67 of file asset_manager_font_provider.cc.

References ~AssetManagerFontStyleSet().

70  : asset_manager_(asset_manager), family_name_(family_name) {}

◆ ~AssetManagerFontStyleSet()

flutter::AssetManagerFontStyleSet::~AssetManagerFontStyleSet ( )
overridedefault

Member Function Documentation

◆ count()

int flutter::AssetManagerFontStyleSet::count ( )
override

Definition at line 78 of file asset_manager_font_provider.cc.

78  {
79  return assets_.size();
80 }

◆ createTypeface()

SkTypeface * flutter::AssetManagerFontStyleSet::createTypeface ( int  index)
override

Definition at line 97 of file asset_manager_font_provider.cc.

References fml::Mapping::GetMapping(), and fml::Mapping::GetSize().

Referenced by getStyle().

97  {
98  size_t index = i;
99  if (index >= assets_.size()) {
100  return nullptr;
101  }
102 
103  TypefaceAsset& asset = assets_[index];
104  if (!asset.typeface) {
105  std::unique_ptr<fml::Mapping> asset_mapping =
106  asset_manager_->GetAsMapping(asset.asset);
107  if (asset_mapping == nullptr) {
108  return nullptr;
109  }
110 
111  fml::Mapping* asset_mapping_ptr = asset_mapping.release();
112  sk_sp<SkData> asset_data = SkData::MakeWithProc(
113  asset_mapping_ptr->GetMapping(), asset_mapping_ptr->GetSize(),
114  MappingReleaseProc, asset_mapping_ptr);
115  std::unique_ptr<SkMemoryStream> stream = SkMemoryStream::Make(asset_data);
116 
117  // Ownership of the stream is transferred.
118  asset.typeface = SkTypeface::MakeFromStream(std::move(stream));
119  if (!asset.typeface) {
120  return nullptr;
121  }
122  }
123 
124  return SkRef(asset.typeface.get());
125 }
virtual size_t GetSize() const =0
virtual const uint8_t * GetMapping() const =0

◆ getStyle()

void flutter::AssetManagerFontStyleSet::getStyle ( int  index,
SkFontStyle *  style,
SkString *  style 
)
override

Definition at line 82 of file asset_manager_font_provider.cc.

References createTypeface(), and FML_DCHECK.

84  {
85  FML_DCHECK(index < static_cast<int>(assets_.size()));
86  if (style) {
87  sk_sp<SkTypeface> typeface(createTypeface(index));
88  if (typeface) {
89  *style = typeface->fontStyle();
90  }
91  }
92  if (name) {
93  *name = family_name_.c_str();
94  }
95 }
#define FML_DCHECK(condition)
Definition: logging.h:86
const char * name
Definition: fuchsia.cc:50
SkTypeface * createTypeface(int index) override

◆ matchStyle()

SkTypeface * flutter::AssetManagerFontStyleSet::matchStyle ( const SkFontStyle &  pattern)
override

Definition at line 127 of file asset_manager_font_provider.cc.

127  {
128  return matchStyleCSS3(pattern);
129 }

◆ registerAsset()

void flutter::AssetManagerFontStyleSet::registerAsset ( std::string  asset)

Definition at line 74 of file asset_manager_font_provider.cc.

74  {
75  assets_.emplace_back(asset);
76 }

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