1 /*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "include/utils/SkOrderedFontMgr.h"
9
10 #include "include/core/SkData.h" // IWYU pragma: keep
11 #include "include/core/SkFontStyle.h"
12 #include "include/core/SkStream.h" // IWYU pragma: keep
13 #include "include/core/SkTypeface.h" // IWYU pragma: keep
14
15 #include <utility>
16
17 class SkString;
18 struct SkFontArguments;
19
SkOrderedFontMgr()20 SkOrderedFontMgr::SkOrderedFontMgr() {}
~SkOrderedFontMgr()21 SkOrderedFontMgr::~SkOrderedFontMgr() {}
22
append(sk_sp<SkFontMgr> fm)23 void SkOrderedFontMgr::append(sk_sp<SkFontMgr> fm) {
24 fList.push_back(std::move(fm));
25 }
26
onCountFamilies() const27 int SkOrderedFontMgr::onCountFamilies() const {
28 int count = 0;
29 for (const auto& fm : fList) {
30 count += fm->countFamilies();
31 }
32 return count;
33 }
34
onGetFamilyName(int index,SkString * familyName) const35 void SkOrderedFontMgr::onGetFamilyName(int index, SkString* familyName) const {
36 for (const auto& fm : fList) {
37 const int count = fm->countFamilies();
38 if (index < count) {
39 return fm->getFamilyName(index, familyName);
40 }
41 index -= count;
42 }
43 }
44
onCreateStyleSet(int index) const45 SkFontStyleSet* SkOrderedFontMgr::onCreateStyleSet(int index) const {
46 for (const auto& fm : fList) {
47 const int count = fm->countFamilies();
48 if (index < count) {
49 return fm->createStyleSet(index);
50 }
51 index -= count;
52 }
53 return nullptr;
54 }
55
onMatchFamily(const char familyName[]) const56 SkFontStyleSet* SkOrderedFontMgr::onMatchFamily(const char familyName[]) const {
57 for (const auto& fm : fList) {
58 if (auto fs = fm->matchFamily(familyName)) {
59 return fs;
60 }
61 }
62 return nullptr;
63 }
64
onMatchFamilyStyle(const char family[],const SkFontStyle & style) const65 SkTypeface* SkOrderedFontMgr::onMatchFamilyStyle(const char family[],
66 const SkFontStyle& style) const {
67 for (const auto& fm : fList) {
68 if (auto tf = fm->matchFamilyStyle(family, style)) {
69 return tf;
70 }
71 }
72 return nullptr;
73 }
74
onMatchFamilyStyleCharacter(const char familyName[],const SkFontStyle & style,const char * bcp47[],int bcp47Count,SkUnichar uni) const75 SkTypeface* SkOrderedFontMgr::onMatchFamilyStyleCharacter(const char familyName[],
76 const SkFontStyle& style,
77 const char* bcp47[], int bcp47Count,
78 SkUnichar uni) const {
79 for (const auto& fm : fList) {
80 if (auto tf = fm->matchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, uni)) {
81 return tf;
82 }
83 }
84 return nullptr;
85 }
86
87 // All of these are defined to fail by returning null
88
onMakeFromData(sk_sp<SkData>,int ttcIndex) const89 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromData(sk_sp<SkData>, int ttcIndex) const {
90 return nullptr;
91 }
92
onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,int ttcIndex) const93 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
94 int ttcIndex) const {
95 return nullptr;
96 }
97
onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,const SkFontArguments &) const98 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
99 const SkFontArguments&) const {
100 return nullptr;
101 }
102
onMakeFromFile(const char path[],int ttcIndex) const103 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromFile(const char path[], int ttcIndex) const {
104 return nullptr;
105 }
106
onLegacyMakeTypeface(const char family[],SkFontStyle) const107 sk_sp<SkTypeface> SkOrderedFontMgr::onLegacyMakeTypeface(const char family[], SkFontStyle) const {
108 return nullptr;
109 }
110