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
AssetFontManager(std::unique_ptr<FontAssetProvider> font_provider)27 AssetFontManager::AssetFontManager(
28 std::unique_ptr<FontAssetProvider> font_provider)
29 : font_provider_(std::move(font_provider)) {
30 FML_DCHECK(font_provider_ != nullptr);
31 }
32
33 AssetFontManager::~AssetFontManager() = default;
34
onCountFamilies() const35 int AssetFontManager::onCountFamilies() const {
36 return font_provider_->GetFamilyCount();
37 }
38
onGetFamilyName(int index,SkString * familyName) const39 void AssetFontManager::onGetFamilyName(int index, SkString* familyName) const {
40 familyName->set(font_provider_->GetFamilyName(index).c_str());
41 }
42
onCreateStyleSet(int index) const43 SkFontStyleSet* AssetFontManager::onCreateStyleSet(int index) const {
44 FML_DCHECK(false);
45 return nullptr;
46 }
47
onMatchFamily(const char family_name_string[]) const48 SkFontStyleSet* AssetFontManager::onMatchFamily(
49 const char family_name_string[]) const {
50 std::string family_name(family_name_string);
51 return font_provider_->MatchFamily(family_name);
52 }
53
onMatchFamilyStyle(const char familyName[],const SkFontStyle & style) const54 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
onMatchFamilyStyleCharacter(const char familyName[],const SkFontStyle &,const char * bcp47[],int bcp47Count,SkUnichar character) const64 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
onMatchFaceStyle(const SkTypeface *,const SkFontStyle &) const73 SkTypeface* AssetFontManager::onMatchFaceStyle(const SkTypeface*,
74 const SkFontStyle&) const {
75 FML_DCHECK(false);
76 return nullptr;
77 }
78
onMakeFromData(sk_sp<SkData>,int ttcIndex) const79 sk_sp<SkTypeface> AssetFontManager::onMakeFromData(sk_sp<SkData>,
80 int ttcIndex) const {
81 FML_DCHECK(false);
82 return nullptr;
83 }
84
onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,int ttcIndex) const85 sk_sp<SkTypeface> AssetFontManager::onMakeFromStreamIndex(
86 std::unique_ptr<SkStreamAsset>,
87 int ttcIndex) const {
88 FML_DCHECK(false);
89 return nullptr;
90 }
91
onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,const SkFontArguments &) const92 sk_sp<SkTypeface> AssetFontManager::onMakeFromStreamArgs(
93 std::unique_ptr<SkStreamAsset>,
94 const SkFontArguments&) const {
95 FML_DCHECK(false);
96 return nullptr;
97 }
98
onMakeFromFile(const char path[],int ttcIndex) const99 sk_sp<SkTypeface> AssetFontManager::onMakeFromFile(const char path[],
100 int ttcIndex) const {
101 FML_DCHECK(false);
102 return nullptr;
103 }
104
onLegacyMakeTypeface(const char familyName[],SkFontStyle) const105 sk_sp<SkTypeface> AssetFontManager::onLegacyMakeTypeface(
106 const char familyName[],
107 SkFontStyle) const {
108 FML_DCHECK(false);
109 return nullptr;
110 }
111
112 } // namespace txt
113