5#include "flutter/lib/ui/text/font_collection.h"
9#include "flutter/lib/ui/text/asset_manager_font_provider.h"
10#include "flutter/lib/ui/ui_dart_state.h"
11#include "flutter/lib/ui/window/platform_configuration.h"
12#include "flutter/runtime/test_font_data.h"
13#include "rapidjson/document.h"
14#include "rapidjson/rapidjson.h"
27#if FML_OS_MACOSX || FML_OS_IOS
35 dynamic_font_manager_ = sk_make_sp<txt::DynamicFontManager>();
36 collection_->SetDynamicFontManager(dynamic_font_manager_);
49 uint32_t font_initialization_data) {
50 collection_->SetupDefaultFontManager(font_initialization_data);
70 const std::shared_ptr<AssetManager>& asset_manager) {
71#if FML_OS_MACOSX || FML_OS_IOS
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.";
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());
87 if (document.HasParseError()) {
88 FML_DLOG(WARNING) <<
"Error parsing the font manifest in the asset store.";
92 if (!document.IsArray()) {
97 std::make_unique<AssetManagerFontProvider>(asset_manager);
99 for (
const auto& family : document.GetArray()) {
100 auto family_name = family.FindMember(
"family");
101 if (family_name == family.MemberEnd() || !family_name->value.IsString()) {
105 auto family_fonts = family.FindMember(
"fonts");
106 if (family_fonts == family.MemberEnd() || !family_fonts->value.IsArray()) {
110 for (
const auto& family_font : family_fonts->value.GetArray()) {
111 if (!family_font.IsObject()) {
115 auto font_asset = family_font.FindMember(
"asset");
116 if (font_asset == family_font.MemberEnd() ||
117 !font_asset->value.IsString()) {
122 font_provider->RegisterAsset(family_name->value.GetString(),
123 font_asset->value.GetString());
127 collection_->SetAssetFontManager(
128 sk_make_sp<txt::AssetFontManager>(std::move(font_provider)));
133 std::unique_ptr<txt::TypefaceFontAssetProvider> font_provider =
134 std::make_unique<txt::TypefaceFontAssetProvider>();
140 font_provider->RegisterTypeface(std::move(typeface),
names[index]);
145 collection_->SetTestFontManager(
146 sk_make_sp<txt::TestFontManager>(std::move(font_provider),
names));
148 collection_->DisableFontFallback();
153 const std::string& family_name) {
154 tonic::Uint8List font_data(font_data_handle);
161 std::unique_ptr<SkStreamAsset> font_stream = std::make_unique<SkMemoryStream>(
162 font_data.data(), font_data.num_elements(),
true);
167 if (family_name.empty()) {
172 font_collection.collection_->ClearFontFamilyCache();
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
static void PurgeFontCache()
std::shared_ptr< txt::FontCollection > GetFontCollection() const
virtual void RegisterFonts(const std::shared_ptr< AssetManager > &asset_manager)
static void LoadFontFromList(Dart_Handle font_data_handle, Dart_Handle callback, const std::string &family_name)
void SetupDefaultFontManager(uint32_t font_initialization_data)
virtual ~FontCollection()
PlatformConfiguration * platform_configuration() const
static UIDartState * Current()
static void ThrowIfUIOperationsProhibited()
TypefaceFontAssetProvider & font_provider() const
void RegisterTypeface(sk_sp< SkTypeface > typeface)
struct _Dart_Handle * Dart_Handle
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DLOG(severity)
static const char *const names[]
std::vector< std::string > GetTestFontFamilyNames()
std::vector< sk_sp< SkTypeface > > GetTestFontData()
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
void RegisterSystemFonts(const DynamicFontManager &dynamic_font_manager)