Flutter Engine
typeface_font_asset_provider.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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_TYPEFACE_FONT_ASSET_PROVIDER_H_
18 #define TXT_TYPEFACE_FONT_ASSET_PROVIDER_H_
19 
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "flutter/fml/macros.h"
25 #include "third_party/skia/include/core/SkFontMgr.h"
27 
28 namespace txt {
29 
30 class TypefaceFontStyleSet : public SkFontStyleSet {
31  public:
33 
34  ~TypefaceFontStyleSet() override;
35 
36  void registerTypeface(sk_sp<SkTypeface> typeface);
37 
38  // |SkFontStyleSet|
39  int count() override;
40 
41  // |SkFontStyleSet|
42  void getStyle(int index, SkFontStyle* style, SkString* name) override;
43 
44  // |SkFontStyleSet|
45  SkTypeface* createTypeface(int index) override;
46 
47  // |SkFontStyleSet|
48  SkTypeface* matchStyle(const SkFontStyle& pattern) override;
49 
50  private:
51  std::vector<sk_sp<SkTypeface>> typefaces_;
52 
53  FML_DISALLOW_COPY_AND_ASSIGN(TypefaceFontStyleSet);
54 };
55 
57  public:
59  ~TypefaceFontAssetProvider() override;
60 
61  void RegisterTypeface(sk_sp<SkTypeface> typeface);
62 
63  void RegisterTypeface(sk_sp<SkTypeface> typeface,
64  std::string family_name_alias);
65 
66  // |FontAssetProvider|
67  size_t GetFamilyCount() const override;
68 
69  // |FontAssetProvider|
70  std::string GetFamilyName(int index) const override;
71 
72  // |FontAssetProvider|
73  SkFontStyleSet* MatchFamily(const std::string& family_name) override;
74 
75  private:
76  std::unordered_map<std::string, sk_sp<TypefaceFontStyleSet>>
77  registered_families_;
78  std::vector<std::string> family_names_;
79 
81 };
82 
83 } // namespace txt
84 
85 #endif // TXT_TYPEFACE_FONT_ASSET_PROVIDER_H_
void getStyle(int index, SkFontStyle *style, SkString *name) override
SkTypeface * matchStyle(const SkFontStyle &pattern) override
~TypefaceFontStyleSet() override
SkTypeface * createTypeface(int index) override
void registerTypeface(sk_sp< SkTypeface > typeface)
const char * name
Definition: fuchsia.cc:50
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27