5#include "flutter/lib/ui/text/asset_manager_font_provider.h"
9#include "flutter/fml/logging.h"
21void MappingReleaseProc(
const void* ptr,
void* context) {
28 std::shared_ptr<AssetManager> asset_manager)
29 : asset_manager_(
std::move(asset_manager)) {}
35 return family_names_.size();
40 FML_DCHECK(index >= 0 &&
static_cast<size_t>(index) < family_names_.size());
41 return family_names_[index];
46 const std::string& family_name) {
48 if (found == registered_families_.end()) {
55 const std::string& asset) {
57 auto family_it = registered_families_.find(canonical_name);
59 if (family_it == registered_families_.end()) {
60 family_names_.push_back(family_name);
61 auto value = std::make_pair(
63 sk_make_sp<AssetManagerFontStyleSet>(asset_manager_, family_name));
64 family_it = registered_families_.emplace(
value).first;
67 family_it->second->registerAsset(asset);
71 std::shared_ptr<AssetManager> asset_manager,
72 std::string family_name)
73 : asset_manager_(
std::move(asset_manager)),
74 family_name_(
std::move(family_name)) {}
79 assets_.emplace_back(asset);
83 return assets_.size();
89 FML_DCHECK(index <
static_cast<int>(assets_.size()));
97 *
name = family_name_.c_str();
103 if (index >= assets_.size()) {
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) {
115 fml::Mapping* asset_mapping_ptr = asset_mapping.release();
118 MappingReleaseProc, asset_mapping_ptr);
124 if (!asset.typeface) {
136 return matchStyleCSS3(pattern);
139AssetManagerFontStyleSet::TypefaceAsset::TypefaceAsset(std::string
a)
140 : asset(
std::move(
a)) {}
142AssetManagerFontStyleSet::TypefaceAsset::TypefaceAsset(
143 const AssetManagerFontStyleSet::TypefaceAsset& other) =
default;
145AssetManagerFontStyleSet::TypefaceAsset::~TypefaceAsset() =
default;
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
SkFontStyle fontStyle() const
std::string GetFamilyName(int index) const override
void RegisterAsset(const std::string &family_name, const std::string &asset)
~AssetManagerFontProvider() override
sk_sp< SkFontStyleSet > MatchFamily(const std::string &family_name) override
size_t GetFamilyCount() const override
AssetManagerFontProvider(std::shared_ptr< AssetManager > asset_manager)
MatchStyleRet matchStyle(const SkFontStyle &pattern) override
decltype(std::declval< SkFontStyleSet >().matchStyle(std::declval< SkFontStyle >())) MatchStyleRet
decltype(std::declval< SkFontStyleSet >().createTypeface(0)) CreateTypefaceRet
~AssetManagerFontStyleSet() override
void registerAsset(const std::string &asset)
void getStyle(int index, SkFontStyle *, SkString *style) override
CreateTypefaceRet createTypeface(int index) override
AssetManagerFontStyleSet(std::shared_ptr< AssetManager > asset_manager, std::string family_name)
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0
static std::string CanonicalFamilyName(std::string family_name)
#define FML_DLOG(severity)
#define FML_DCHECK(condition)
DEF_SWITCHES_START aot vmservice shared library name
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)