Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
flutter::AssetManagerFontStyleSet Class Reference

#include <asset_manager_font_provider.h>

Inheritance diagram for flutter::AssetManagerFontStyleSet:
SkFontStyleSet SkRefCnt SkRefCntBase

Public Types

using CreateTypefaceRet = decltype(std::declval< SkFontStyleSet >().createTypeface(0))
 
using MatchStyleRet = decltype(std::declval< SkFontStyleSet >().matchStyle(std::declval< SkFontStyle >()))
 

Public Member Functions

 AssetManagerFontStyleSet (std::shared_ptr< AssetManager > asset_manager, std::string family_name)
 
 ~AssetManagerFontStyleSet () override
 
void registerAsset (const std::string &asset)
 
int count () override
 
void getStyle (int index, SkFontStyle *, SkString *style) override
 
CreateTypefaceRet createTypeface (int index) override
 
MatchStyleRet matchStyle (const SkFontStyle &pattern) override
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Static Public Member Functions inherited from SkFontStyleSet
static sk_sp< SkFontStyleSetCreateEmpty ()
 
- Protected Member Functions inherited from SkFontStyleSet
sk_sp< SkTypefacematchStyleCSS3 (const SkFontStyle &pattern)
 

Detailed Description

Definition at line 21 of file asset_manager_font_provider.h.

Member Typedef Documentation

◆ CreateTypefaceRet

Definition at line 37 of file asset_manager_font_provider.h.

◆ MatchStyleRet

using flutter::AssetManagerFontStyleSet::MatchStyleRet = decltype(std::declval<SkFontStyleSet>().matchStyle( std::declval<SkFontStyle>()))

Definition at line 42 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 70 of file asset_manager_font_provider.cc.

73 : asset_manager_(std::move(asset_manager)),
74 family_name_(std::move(family_name)) {}

◆ ~AssetManagerFontStyleSet()

flutter::AssetManagerFontStyleSet::~AssetManagerFontStyleSet ( )
overridedefault

Member Function Documentation

◆ count()

int flutter::AssetManagerFontStyleSet::count ( )
overridevirtual

Implements SkFontStyleSet.

Definition at line 82 of file asset_manager_font_provider.cc.

82 {
83 return assets_.size();
84}

◆ createTypeface()

auto flutter::AssetManagerFontStyleSet::createTypeface ( int  index)
overridevirtual

Implements SkFontStyleSet.

Definition at line 101 of file asset_manager_font_provider.cc.

101 {
102 size_t index = i;
103 if (index >= assets_.size()) {
104 return nullptr;
105 }
106
107 TypefaceAsset& asset = assets_[index];
108 if (!asset.typeface) {
109 std::unique_ptr<fml::Mapping> asset_mapping =
110 asset_manager_->GetAsMapping(asset.asset);
111 if (asset_mapping == nullptr) {
112 return nullptr;
113 }
114
115 fml::Mapping* asset_mapping_ptr = asset_mapping.release();
117 asset_mapping_ptr->GetMapping(), asset_mapping_ptr->GetSize(),
118 MappingReleaseProc, asset_mapping_ptr);
119 std::unique_ptr<SkMemoryStream> stream = SkMemoryStream::Make(asset_data);
120
122 // Ownership of the stream is transferred.
123 asset.typeface = font_mgr->makeFromStream(std::move(stream));
124 if (!asset.typeface) {
125 FML_DLOG(ERROR) << "Unable to load font asset for family: "
126 << family_name_;
127 return nullptr;
128 }
129 }
130
131 return CreateTypefaceRet(SkRef(asset.typeface.get()));
132}
static T * SkRef(T *obj)
Definition SkRefCnt.h:132
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
Definition SkData.cpp:128
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
Definition SkStream.cpp:314
decltype(std::declval< SkFontStyleSet >().createTypeface(0)) CreateTypefaceRet
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0
#define FML_DLOG(severity)
Definition logging.h:102
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition platform.cc:17
#define ERROR(message)

◆ getStyle()

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

Implements SkFontStyleSet.

Definition at line 86 of file asset_manager_font_provider.cc.

88 {
89 FML_DCHECK(index < static_cast<int>(assets_.size()));
90 if (style) {
91 sk_sp<SkTypeface> typeface(createTypeface(index));
92 if (typeface) {
93 *style = typeface->fontStyle();
94 }
95 }
96 if (name) {
97 *name = family_name_.c_str();
98 }
99}
CreateTypefaceRet createTypeface(int index) override
#define FML_DCHECK(condition)
Definition logging.h:103
DEF_SWITCHES_START aot vmservice shared library name
Definition switches.h:32

◆ matchStyle()

auto flutter::AssetManagerFontStyleSet::matchStyle ( const SkFontStyle pattern)
overridevirtual

Implements SkFontStyleSet.

Definition at line 134 of file asset_manager_font_provider.cc.

135 {
136 return matchStyleCSS3(pattern);
137}
sk_sp< SkTypeface > matchStyleCSS3(const SkFontStyle &pattern)

◆ registerAsset()

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

Definition at line 78 of file asset_manager_font_provider.cc.

78 {
79 assets_.emplace_back(asset);
80}

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