Flutter Engine
asset_font_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TXT_ASSET_FONT_MANAGER_H_
18 #define TXT_ASSET_FONT_MANAGER_H_
19 
20 #include <memory>
21 
22 #include "flutter/fml/macros.h"
23 #include "third_party/skia/include/core/SkFontMgr.h"
24 #include "third_party/skia/include/core/SkStream.h"
27 
28 namespace txt {
29 
30 class AssetFontManager : public SkFontMgr {
31  public:
32  AssetFontManager(std::unique_ptr<FontAssetProvider> font_provider);
33 
34  ~AssetFontManager() override;
35 
36  protected:
37  // |SkFontMgr|
38  SkFontStyleSet* onMatchFamily(const char familyName[]) const override;
39 
40  std::unique_ptr<FontAssetProvider> font_provider_;
41 
42  private:
43  // |SkFontMgr|
44  int onCountFamilies() const override;
45 
46  // |SkFontMgr|
47  void onGetFamilyName(int index, SkString* familyName) const override;
48 
49  // |SkFontMgr|
50  SkFontStyleSet* onCreateStyleSet(int index) const override;
51 
52  // |SkFontMgr|
53  SkTypeface* onMatchFamilyStyle(const char familyName[],
54  const SkFontStyle&) const override;
55 
56  // |SkFontMgr|
57  SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
58  const SkFontStyle&,
59  const char* bcp47[],
60  int bcp47Count,
61  SkUnichar character) const override;
62 
63  // |SkFontMgr|
64  SkTypeface* onMatchFaceStyle(const SkTypeface*,
65  const SkFontStyle&) const override;
66 
67  // |SkFontMgr|
68  sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override;
69 
70  // |SkFontMgr|
71  sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
72  int ttcIndex) const override;
73 
74  // |SkFontMgr|
75  sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
76  const SkFontArguments&) const override;
77 
78  // |SkFontMgr|
79  sk_sp<SkTypeface> onMakeFromFile(const char path[],
80  int ttcIndex) const override;
81 
82  // |SkFontMgr|
83  sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[],
84  SkFontStyle) const override;
85 
86  FML_DISALLOW_COPY_AND_ASSIGN(AssetFontManager);
87 };
88 
90  public:
92  : AssetFontManager(std::make_unique<TypefaceFontAssetProvider>()) {}
93 
95  return static_cast<TypefaceFontAssetProvider&>(*font_provider_);
96  }
97 };
98 
99 } // namespace txt
100 
101 #endif // TXT_ASSET_FONT_MANAGER_H_
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
Definition: ref_ptr.h:252
SkFontStyleSet * onMatchFamily(const char familyName[]) const override
~AssetFontManager() override
TypefaceFontAssetProvider & font_provider()
AssetFontManager(std::unique_ptr< FontAssetProvider > font_provider)
std::unique_ptr< FontAssetProvider > font_provider_