Flutter Engine
The Flutter Engine
asset_manager_font_provider.h
Go to the documentation of this file.
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#ifndef FLUTTER_LIB_UI_TEXT_ASSET_MANAGER_FONT_PROVIDER_H_
6#define FLUTTER_LIB_UI_TEXT_ASSET_MANAGER_FONT_PROVIDER_H_
7
8#include <memory>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13#include "flutter/assets/asset_manager.h"
14#include "flutter/fml/macros.h"
18
19namespace flutter {
20
22 public:
23 AssetManagerFontStyleSet(std::shared_ptr<AssetManager> asset_manager,
24 std::string family_name);
25
27
28 void registerAsset(const std::string& asset);
29
30 // |SkFontStyleSet|
31 int count() override;
32
33 // |SkFontStyleSet|
34 void getStyle(int index, SkFontStyle*, SkString* style) override;
35
36 // |SkFontStyleSet|
38 decltype(std::declval<SkFontStyleSet>().createTypeface(0));
39 CreateTypefaceRet createTypeface(int index) override;
40
41 // |SkFontStyleSet|
42 using MatchStyleRet = decltype(std::declval<SkFontStyleSet>().matchStyle(
43 std::declval<SkFontStyle>()));
44 MatchStyleRet matchStyle(const SkFontStyle& pattern) override;
45
46 private:
47 std::shared_ptr<AssetManager> asset_manager_;
48 std::string family_name_;
49
50 struct TypefaceAsset {
51 explicit TypefaceAsset(std::string a);
52
53 TypefaceAsset(const TypefaceAsset& other);
54
55 ~TypefaceAsset();
56
57 std::string asset;
58 sk_sp<SkTypeface> typeface;
59 };
60 std::vector<TypefaceAsset> assets_;
61
62 FML_DISALLOW_COPY_AND_ASSIGN(AssetManagerFontStyleSet);
63};
64
66 public:
68 std::shared_ptr<AssetManager> asset_manager);
69
71
72 void RegisterAsset(const std::string& family_name, const std::string& asset);
73
74 // |FontAssetProvider|
75 size_t GetFamilyCount() const override;
76
77 // |FontAssetProvider|
78 std::string GetFamilyName(int index) const override;
79
80 // |FontAssetProvider|
81 sk_sp<SkFontStyleSet> MatchFamily(const std::string& family_name) override;
82
83 private:
84 std::shared_ptr<AssetManager> asset_manager_;
85 std::unordered_map<std::string, sk_sp<AssetManagerFontStyleSet>>
86 registered_families_;
87 std::vector<std::string> family_names_;
88
89 FML_DISALLOW_COPY_AND_ASSIGN(AssetManagerFontProvider);
90};
91
92} // namespace flutter
93
94#endif // FLUTTER_LIB_UI_TEXT_ASSET_MANAGER_FONT_PROVIDER_H_
std::string GetFamilyName(int index) const override
void RegisterAsset(const std::string &family_name, const std::string &asset)
sk_sp< SkFontStyleSet > MatchFamily(const std::string &family_name) 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
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)
struct MyStruct a[10]