9 #include "flutter/fml/icu_util.h"
10 #include "flutter/txt/src/txt/platform.h"
12 #include "impeller/toolkit/interop/embedded_icu_data.h"
17 : collection_(
std::make_shared<txt::FontCollection>()) {
18 static std::once_flag sICUInitOnceFlag;
19 std::call_once(sICUInitOnceFlag, []() {
20 auto icu_data = std::make_unique<fml::NonOwnedMapping>(
21 impeller_embedded_icu_data_data, impeller_embedded_icu_data_length);
22 fml::icu::InitializeICUFromMapping(std::move(icu_data));
25 collection_->SetupDefaultFontManager(0u);
28 asset_font_manager_ = sk_make_sp<skia::textlayout::TypefaceFontProvider>();
29 collection_->SetAssetFontManager(asset_font_manager_);
38 const std::shared_ptr<txt::FontCollection>&
44 std::unique_ptr<fml::Mapping> font_data) {
49 auto sk_data_context = font_data.release();
50 auto sk_data = SkData::MakeWithProc(
51 sk_data_context->GetMapping(),
52 sk_data_context->GetSize(),
53 [](
const void*,
void* context) {
54 delete reinterpret_cast<decltype(sk_data_context)>(context);
58 auto sk_data_stream = SkMemoryStream::Make(sk_data);
60 txt::GetDefaultFontManager()->makeFromStream(std::move(sk_data_stream));
69 const char* family_name_alias) {
71 if (typeface ==
nullptr) {
75 if (family_name_alias ==
nullptr) {
76 result = asset_font_manager_->registerTypeface(std::move(typeface));
78 result = asset_font_manager_->registerTypeface(std::move(typeface),
79 SkString{family_name_alias});
bool RegisterFont(std::unique_ptr< fml::Mapping > font_data, const char *family_name_alias)
Registers custom font data. If an alias for the family name is provided, subsequent lookups will need...
const std::shared_ptr< txt::FontCollection > & GetFontCollection() const
~TypographyContext() override
static sk_sp< SkTypeface > CreateTypefaceFromFontData(std::unique_ptr< fml::Mapping > font_data)