• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/lib/ui/text/font_collection.h"
6 
7 #include <mutex>
8 
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/window.h"
12 #include "flutter/runtime/test_font_data.h"
13 #include "third_party/skia/include/core/SkFontMgr.h"
14 #include "third_party/skia/include/core/SkGraphics.h"
15 #include "third_party/skia/include/core/SkStream.h"
16 #include "third_party/skia/include/core/SkTypeface.h"
17 #include "txt/asset_font_manager.h"
18 #include "txt/test_font_manager.h"
19 
20 namespace flutter {
21 
FontCollection()22 FontCollection::FontCollection()
23     : collection_(std::make_shared<txt::FontCollection>()) {
24   collection_->SetupDefaultFontManager();
25 
26   dynamic_font_manager_ = sk_make_sp<txt::DynamicFontManager>();
27   collection_->SetDynamicFontManager(dynamic_font_manager_);
28 }
29 
~FontCollection()30 FontCollection::~FontCollection() {
31   collection_.reset();
32   SkGraphics::PurgeFontCache();
33 }
34 
RegisterNatives(tonic::DartLibraryNatives * natives)35 void FontCollection::RegisterNatives(tonic::DartLibraryNatives* natives) {
36 }
37 
GetFontCollection() const38 std::shared_ptr<txt::FontCollection> FontCollection::GetFontCollection() const {
39   return collection_;
40 }
41 
RegisterFonts(std::shared_ptr<AssetManager> asset_manager)42 void FontCollection::RegisterFonts(
43     std::shared_ptr<AssetManager> asset_manager) {
44 }
45 
RegisterTestFonts()46 void FontCollection::RegisterTestFonts() {
47 }
48 
LoadFontFromList(const uint8_t * font_data,int length,std::string family_name)49 void FontCollection::LoadFontFromList(const uint8_t* font_data,
50                                       int length,
51                                       std::string family_name) {
52   std::unique_ptr<SkStreamAsset> font_stream =
53       std::make_unique<SkMemoryStream>(font_data, length, true);
54   sk_sp<SkTypeface> typeface =
55       SkTypeface::MakeFromStream(std::move(font_stream));
56   txt::TypefaceFontAssetProvider& font_provider =
57       dynamic_font_manager_->font_provider();
58   if (family_name.empty()) {
59     font_provider.RegisterTypeface(typeface);
60   } else {
61     font_provider.RegisterTypeface(typeface, family_name);
62   }
63   collection_->ClearFontFamilyCache();
64 }
65 
66 }  // namespace flutter
67