Flutter Engine
 
Loading...
Searching...
No Matches
typeface_font_asset_provider.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
8#include "third_party/skia/include/core/SkString.h"
9#include "third_party/skia/include/core/SkTypeface.h"
10
11namespace txt {
12
14
16
17// |FontAssetProvider|
19 return family_names_.size();
20}
21
22// |FontAssetProvider|
23std::string TypefaceFontAssetProvider::GetFamilyName(int index) const {
24 return family_names_[index];
25}
26
27// |FontAssetProvider|
29 const std::string& family_name) {
30 auto found = registered_families_.find(CanonicalFamilyName(family_name));
31 if (found == registered_families_.end()) {
32 return nullptr;
33 }
34 return found->second;
35}
36
37void TypefaceFontAssetProvider::RegisterTypeface(sk_sp<SkTypeface> typeface) {
38 if (typeface == nullptr) {
39 return;
40 }
41
42 SkString sk_family_name;
43 typeface->getFamilyName(&sk_family_name);
44
45 std::string family_name(sk_family_name.c_str(), sk_family_name.size());
46 RegisterTypeface(std::move(typeface), family_name);
47}
48
50 sk_sp<SkTypeface> typeface,
51 const std::string& family_name_alias) {
52 if (family_name_alias.empty()) {
53 return;
54 }
55
56 std::string canonical_name = CanonicalFamilyName(family_name_alias);
57 auto family_it = registered_families_.find(canonical_name);
58 if (family_it == registered_families_.end()) {
59 family_names_.push_back(family_name_alias);
60 auto value =
61 std::make_pair(canonical_name, sk_make_sp<TypefaceFontStyleSet>());
62 family_it = registered_families_.emplace(value).first;
63 }
64 family_it->second->registerTypeface(std::move(typeface));
65}
66
68
70
71void TypefaceFontStyleSet::registerTypeface(sk_sp<SkTypeface> typeface) {
72 if (typeface == nullptr) {
73 return;
74 }
75 typefaces_.emplace_back(std::move(typeface));
76}
77
79 return typefaces_.size();
80}
81
83 SkFontStyle* style,
84 SkString* name) {
85 FML_DCHECK(static_cast<size_t>(index) < typefaces_.size());
86 if (style) {
87 *style = typefaces_[index]->fontStyle();
88 }
89 if (name) {
90 name->reset();
91 }
92}
93
95 size_t index = i;
96 if (index >= typefaces_.size()) {
97 return nullptr;
98 }
99 return typefaces_[index];
100}
101
102sk_sp<SkTypeface> TypefaceFontStyleSet::matchStyle(const SkFontStyle& pattern) {
103 return matchStyleCSS3(pattern);
104}
105
106} // namespace txt
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)
int32_t value
#define FML_DCHECK(condition)
Definition logging.h:122
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27