Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::FontCollection Class Reference

#include <font_collection.h>

Public Member Functions

 FontCollection ()
 
virtual ~FontCollection ()
 
std::shared_ptr< txt::FontCollectionGetFontCollection () const
 
void SetupDefaultFontManager (uint32_t font_initialization_data)
 
virtual void RegisterFonts (const std::shared_ptr< AssetManager > &asset_manager)
 
void RegisterTestFonts ()
 

Static Public Member Functions

static void LoadFontFromList (Dart_Handle font_data_handle, Dart_Handle callback, const std::string &family_name)
 

Detailed Description

Definition at line 19 of file font_collection.h.

Constructor & Destructor Documentation

◆ FontCollection()

txt::FontCollection::FontCollection ( )

Definition at line 33 of file font_collection.cc.

34 : collection_(std::make_shared<txt::FontCollection>()) {
35 dynamic_font_manager_ = sk_make_sp<txt::DynamicFontManager>();
36 collection_->SetDynamicFontManager(dynamic_font_manager_);
37}

◆ ~FontCollection()

txt::FontCollection::~FontCollection ( )
virtual

Definition at line 39 of file font_collection.cc.

39 {
40 collection_.reset();
42}
static void PurgeFontCache()
Definition: SkGraphics.cpp:72

Member Function Documentation

◆ GetFontCollection()

std::shared_ptr< txt::FontCollection > flutter::FontCollection::GetFontCollection ( ) const

Definition at line 44 of file font_collection.cc.

44 {
45 return collection_;
46}

◆ LoadFontFromList()

void flutter::FontCollection::LoadFontFromList ( Dart_Handle  font_data_handle,
Dart_Handle  callback,
const std::string &  family_name 
)
static

Definition at line 151 of file font_collection.cc.

153 {
154 tonic::Uint8List font_data(font_data_handle);
156 FontCollection& font_collection = UIDartState::Current()
158 ->client()
160
161 std::unique_ptr<SkStreamAsset> font_stream = std::make_unique<SkMemoryStream>(
162 font_data.data(), font_data.num_elements(), true);
164 sk_sp<SkTypeface> typeface = font_mgr->makeFromStream(std::move(font_stream));
165 txt::TypefaceFontAssetProvider& font_provider =
166 font_collection.dynamic_font_manager_->font_provider();
167 if (family_name.empty()) {
168 font_provider.RegisterTypeface(typeface);
169 } else {
170 font_provider.RegisterTypeface(typeface, family_name);
171 }
172 font_collection.collection_->ClearFontFamilyCache();
173
174 font_data.Release();
176}
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
Definition: SkFontMgr.cpp:127
virtual FontCollection & GetFontCollection()=0
Returns the current collection of fonts available on the platform.
PlatformConfigurationClient * client() const
Access to the platform configuration client (which typically is implemented by the RuntimeController)...
PlatformConfiguration * platform_configuration() const
static UIDartState * Current()
static void ThrowIfUIOperationsProhibited()
void RegisterTypeface(sk_sp< SkTypeface > typeface)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
Definition: dart_invoke.cc:20
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition: platform.cc:17

◆ RegisterFonts()

void flutter::FontCollection::RegisterFonts ( const std::shared_ptr< AssetManager > &  asset_manager)
virtual

Definition at line 69 of file font_collection.cc.

70 {
71#if FML_OS_MACOSX || FML_OS_IOS
72 RegisterSystemFonts(*dynamic_font_manager_);
73#endif
74 std::unique_ptr<fml::Mapping> manifest_mapping =
75 asset_manager->GetAsMapping("FontManifest.json");
76 if (manifest_mapping == nullptr) {
77 FML_DLOG(WARNING) << "Could not find the font manifest in the asset store.";
78 return;
79 }
80
81 rapidjson::Document document;
82 static_assert(sizeof(decltype(document)::Ch) == sizeof(uint8_t), "");
83 document.Parse(reinterpret_cast<const decltype(document)::Ch*>(
84 manifest_mapping->GetMapping()),
85 manifest_mapping->GetSize());
86
87 if (document.HasParseError()) {
88 FML_DLOG(WARNING) << "Error parsing the font manifest in the asset store.";
89 return;
90 }
91
92 if (!document.IsArray()) {
93 return;
94 }
95
96 auto font_provider =
97 std::make_unique<AssetManagerFontProvider>(asset_manager);
98
99 for (const auto& family : document.GetArray()) {
100 auto family_name = family.FindMember("family");
101 if (family_name == family.MemberEnd() || !family_name->value.IsString()) {
102 continue;
103 }
104
105 auto family_fonts = family.FindMember("fonts");
106 if (family_fonts == family.MemberEnd() || !family_fonts->value.IsArray()) {
107 continue;
108 }
109
110 for (const auto& family_font : family_fonts->value.GetArray()) {
111 if (!family_font.IsObject()) {
112 continue;
113 }
114
115 auto font_asset = family_font.FindMember("asset");
116 if (font_asset == family_font.MemberEnd() ||
117 !font_asset->value.IsString()) {
118 continue;
119 }
120
121 // TODO(chinmaygarde): Handle weights and styles.
122 font_provider->RegisterAsset(family_name->value.GetString(),
123 font_asset->value.GetString());
124 }
125 }
126
127 collection_->SetAssetFontManager(
128 sk_make_sp<txt::AssetFontManager>(std::move(font_provider)));
129}
#define FML_DLOG(severity)
Definition: logging.h:102
void RegisterSystemFonts(const DynamicFontManager &dynamic_font_manager)
Definition: platform_mac.mm:83

◆ RegisterTestFonts()

void flutter::FontCollection::RegisterTestFonts ( )

Definition at line 131 of file font_collection.cc.

131 {
132 std::vector<sk_sp<SkTypeface>> test_typefaces = GetTestFontData();
133 std::unique_ptr<txt::TypefaceFontAssetProvider> font_provider =
134 std::make_unique<txt::TypefaceFontAssetProvider>();
135
136 size_t index = 0;
137 std::vector<std::string> names = GetTestFontFamilyNames();
138 for (sk_sp<SkTypeface> typeface : test_typefaces) {
139 if (typeface) {
140 font_provider->RegisterTypeface(std::move(typeface), names[index]);
141 }
142 index++;
143 }
144
145 collection_->SetTestFontManager(
146 sk_make_sp<txt::TestFontManager>(std::move(font_provider), names));
147
148 collection_->DisableFontFallback();
149}
static const char *const names[]
Definition: symbols.cc:24
std::vector< std::string > GetTestFontFamilyNames()
std::vector< sk_sp< SkTypeface > > GetTestFontData()

◆ SetupDefaultFontManager()

void txt::FontCollection::SetupDefaultFontManager ( uint32_t  font_initialization_data)

Definition at line 48 of file font_collection.cc.

49 {
50 collection_->SetupDefaultFontManager(font_initialization_data);
51}

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