Flutter Engine
asset_font_manager.cc
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 #include "txt/asset_font_manager.h"
18 
19 #include <memory>
20 
21 #include "flutter/fml/logging.h"
22 #include "third_party/skia/include/core/SkString.h"
23 #include "third_party/skia/include/core/SkTypeface.h"
24 
25 namespace txt {
26 
28  std::unique_ptr<FontAssetProvider> font_provider)
29  : font_provider_(std::move(font_provider)) {
30  FML_DCHECK(font_provider_ != nullptr);
31 }
32 
34 
35 int AssetFontManager::onCountFamilies() const {
36  return font_provider_->GetFamilyCount();
37 }
38 
39 void AssetFontManager::onGetFamilyName(int index, SkString* familyName) const {
40  familyName->set(font_provider_->GetFamilyName(index).c_str());
41 }
42 
43 SkFontStyleSet* AssetFontManager::onCreateStyleSet(int index) const {
44  FML_DCHECK(false);
45  return nullptr;
46 }
47 
49  const char family_name_string[]) const {
50  std::string family_name(family_name_string);
51  return font_provider_->MatchFamily(family_name);
52 }
53 
54 SkTypeface* AssetFontManager::onMatchFamilyStyle(
55  const char familyName[],
56  const SkFontStyle& style) const {
57  SkFontStyleSet* font_style_set =
58  font_provider_->MatchFamily(std::string(familyName));
59  if (font_style_set == nullptr)
60  return nullptr;
61  return font_style_set->matchStyle(style);
62 }
63 
64 SkTypeface* AssetFontManager::onMatchFamilyStyleCharacter(
65  const char familyName[],
66  const SkFontStyle&,
67  const char* bcp47[],
68  int bcp47Count,
69  SkUnichar character) const {
70  return nullptr;
71 }
72 
73 SkTypeface* AssetFontManager::onMatchFaceStyle(const SkTypeface*,
74  const SkFontStyle&) const {
75  FML_DCHECK(false);
76  return nullptr;
77 }
78 
79 sk_sp<SkTypeface> AssetFontManager::onMakeFromData(sk_sp<SkData>,
80  int ttcIndex) const {
81  FML_DCHECK(false);
82  return nullptr;
83 }
84 
85 sk_sp<SkTypeface> AssetFontManager::onMakeFromStreamIndex(
86  std::unique_ptr<SkStreamAsset>,
87  int ttcIndex) const {
88  FML_DCHECK(false);
89  return nullptr;
90 }
91 
92 sk_sp<SkTypeface> AssetFontManager::onMakeFromStreamArgs(
93  std::unique_ptr<SkStreamAsset>,
94  const SkFontArguments&) const {
95  FML_DCHECK(false);
96  return nullptr;
97 }
98 
99 sk_sp<SkTypeface> AssetFontManager::onMakeFromFile(const char path[],
100  int ttcIndex) const {
101  FML_DCHECK(false);
102  return nullptr;
103 }
104 
105 sk_sp<SkTypeface> AssetFontManager::onLegacyMakeTypeface(
106  const char familyName[],
107  SkFontStyle) const {
108  FML_DCHECK(false);
109  return nullptr;
110 }
111 
112 } // namespace txt
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
#define FML_DCHECK(condition)
Definition: logging.h:86
Definition: ref_ptr.h:252
SkFontStyleSet * onMatchFamily(const char familyName[]) const override
~AssetFontManager() override
AssetFontManager(std::unique_ptr< FontAssetProvider > font_provider)
std::unique_ptr< FontAssetProvider > font_provider_