Flutter Engine
The Flutter Engine
TypefaceFontProvider.cpp
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
3#include <algorithm>
8
9namespace skia {
10namespace textlayout {
11
12int TypefaceFontProvider::onCountFamilies() const { return fRegisteredFamilies.count(); }
13
14void TypefaceFontProvider::onGetFamilyName(int index, SkString* familyName) const {
15 SkASSERT(index < fRegisteredFamilies.count());
16 familyName->set(fFamilyNames[index]);
17}
18
20 auto found = fRegisteredFamilies.find(SkString(familyName));
21 return found ? *found : nullptr;
22}
23
25 SkASSERT(index < fRegisteredFamilies.count());
26 auto found = fRegisteredFamilies.find(fFamilyNames[index]);
27 return found ? *found : nullptr;
28}
29
30sk_sp<SkTypeface> TypefaceFontProvider::onMatchFamilyStyle(const char familyName[], const SkFontStyle& pattern) const {
31 sk_sp<SkFontStyleSet> sset(this->matchFamily(familyName));
32 if (sset) {
33 return sset->matchStyle(pattern);
34 }
35
36 return nullptr;
37}
38
40 if (typeface == nullptr) {
41 return 0;
42 }
43
44 SkString familyName;
45 typeface->getFamilyName(&familyName);
46
47 return registerTypeface(std::move(typeface), std::move(familyName));
48}
49
51 if (familyName.size() == 0) {
52 return 0;
53 }
54
55 auto found = fRegisteredFamilies.find(familyName);
56 if (found == nullptr) {
57 found = fRegisteredFamilies.set(familyName, sk_make_sp<TypefaceFontStyleSet>(familyName));
58 fFamilyNames.emplace_back(familyName);
59 }
60
61 (*found)->appendTypeface(std::move(typeface));
62
63 return 1;
64}
65
67 SkFontStyle style) const {
68 if (familyName) {
69 sk_sp<SkTypeface> matchedByFamily = this->matchFamilyStyle(familyName, style);
70 if (matchedByFamily) {
71 return matchedByFamily;
72 }
73 }
74 if (this->countFamilies() == 0) {
75 return nullptr;
76 }
77 sk_sp<SkFontStyleSet> defaultFamily = this->createStyleSet(0);
78 if (!defaultFamily) {
79 return nullptr;
80 }
81 return defaultFamily->matchStyle(style);
82}
83
85 : fFamilyName(familyName) {}
86
87int TypefaceFontStyleSet::count() { return fStyles.size(); }
88
90 SkASSERT(index < fStyles.size());
91 if (style) {
92 *style = fStyles[index]->fontStyle();
93 }
94 if (name) {
95 *name = fFamilyName;
96 }
97}
98
100 SkASSERT(index < fStyles.size());
101 return fStyles[index];
102}
103
105 return this->matchStyleCSS3(pattern);
106}
107
109 if (typeface.get() != nullptr) {
110 fStyles.emplace_back(std::move(typeface));
111 }
112}
113
114} // namespace textlayout
115} // namespace skia
#define SkASSERT(cond)
Definition: SkAssert.h:116
sk_sp< SkFontStyleSet > createStyleSet(int index) const
Definition: SkFontMgr.cpp:101
sk_sp< SkFontStyleSet > matchFamily(const char familyName[]) const
Definition: SkFontMgr.cpp:105
int countFamilies() const
Definition: SkFontMgr.cpp:93
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
sk_sp< SkTypeface > matchStyleCSS3(const SkFontStyle &pattern)
Definition: SkFontMgr.cpp:184
virtual sk_sp< SkTypeface > matchStyle(const SkFontStyle &pattern)=0
size_t size() const
Definition: SkString.h:131
void set(const SkString &src)
Definition: SkString.h:186
void getFamilyName(SkString *name) const
Definition: SkTypeface.cpp:459
T * get() const
Definition: SkRefCnt.h:303
void onGetFamilyName(int index, SkString *familyName) const override
sk_sp< SkFontStyleSet > onCreateStyleSet(int) const override
sk_sp< SkTypeface > onLegacyMakeTypeface(const char[], SkFontStyle) const override
size_t registerTypeface(sk_sp< SkTypeface > typeface)
sk_sp< SkFontStyleSet > onMatchFamily(const char familyName[]) const override
sk_sp< SkTypeface > onMatchFamilyStyle(const char familyName[], const SkFontStyle &pattern) const override
sk_sp< SkTypeface > createTypeface(int index) override
void getStyle(int index, SkFontStyle *, SkString *name) override
TypefaceFontStyleSet(const SkString &familyName)
sk_sp< SkTypeface > matchStyle(const SkFontStyle &pattern) override
void appendTypeface(sk_sp< SkTypeface > typeface)
int size() const
Definition: SkTArray.h:421
T & emplace_back(Args &&... args)
Definition: SkTArray.h:248
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: DartTypes.h:13