Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
typeface_font_asset_provider.cc
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
18
19#include "flutter/fml/logging.h"
22
23namespace txt {
24
26
28
29// |FontAssetProvider|
31 return family_names_.size();
32}
33
34// |FontAssetProvider|
35std::string TypefaceFontAssetProvider::GetFamilyName(int index) const {
36 return family_names_[index];
37}
38
39// |FontAssetProvider|
41 const std::string& family_name) {
42 auto found = registered_families_.find(CanonicalFamilyName(family_name));
43 if (found == registered_families_.end()) {
44 return nullptr;
45 }
46 return found->second;
47}
48
50 if (typeface == nullptr) {
51 return;
52 }
53
54 SkString sk_family_name;
55 typeface->getFamilyName(&sk_family_name);
56
57 std::string family_name(sk_family_name.c_str(), sk_family_name.size());
58 RegisterTypeface(std::move(typeface), std::move(family_name));
59}
60
62 sk_sp<SkTypeface> typeface,
63 std::string family_name_alias) {
64 if (family_name_alias.empty()) {
65 return;
66 }
67
68 std::string canonical_name = CanonicalFamilyName(family_name_alias);
69 auto family_it = registered_families_.find(canonical_name);
70 if (family_it == registered_families_.end()) {
71 family_names_.push_back(family_name_alias);
72 auto value =
73 std::make_pair(canonical_name, sk_make_sp<TypefaceFontStyleSet>());
74 family_it = registered_families_.emplace(value).first;
75 }
76 family_it->second->registerTypeface(std::move(typeface));
77}
78
80
82
84 if (typeface == nullptr) {
85 return;
86 }
87 typefaces_.emplace_back(std::move(typeface));
88}
89
91 return typefaces_.size();
92}
93
95 SkFontStyle* style,
96 SkString* name) {
97 FML_DCHECK(static_cast<size_t>(index) < typefaces_.size());
98 if (style) {
99 *style = typefaces_[index]->fontStyle();
100 }
101 if (name) {
102 name->reset();
103 }
104}
105
107 size_t index = i;
108 if (index >= typefaces_.size()) {
109 return nullptr;
110 }
111 return typefaces_[index];
112}
113
115 return matchStyleCSS3(pattern);
116}
117
118} // namespace txt
sk_sp< SkTypeface > matchStyleCSS3(const SkFontStyle &pattern)
Definition: SkFontMgr.cpp:184
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
void getFamilyName(SkString *name) const
Definition: SkTypeface.cpp:459
static std::string CanonicalFamilyName(std::string family_name)
void RegisterTypeface(sk_sp< SkTypeface > typeface)
std::string GetFamilyName(int index) const override
sk_sp< SkFontStyleSet > MatchFamily(const std::string &family_name) override
sk_sp< SkTypeface > matchStyle(const SkFontStyle &pattern) override
~TypefaceFontStyleSet() override
void getStyle(int index, SkFontStyle *style, SkString *name) override
sk_sp< SkTypeface > createTypeface(int index) override
void registerTypeface(sk_sp< SkTypeface > typeface)
uint8_t value
#define FML_DCHECK(condition)
Definition: logging.h:103
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32