Debian Codegraph @

src/utils/SkOrderedFontMgr.cpp

raw
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
20 SkOrderedFontMgr::SkOrderedFontMgr() {}
21 SkOrderedFontMgr::~SkOrderedFontMgr() {}
22
23 void SkOrderedFontMgr::append(sk_sp<SkFontMgr> fm) {
24 fList.push_back(std::move(fm));
25 }
26
27 int SkOrderedFontMgr::onCountFamilies() const {
28 int count = 0;
29 for (const auto& fm : fList) {
30 count += fm->countFamilies();
31 }
32 return count;
33 }
34
35 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
45 sk_sp<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
56 sk_sp<SkFontStyleSet> SkOrderedFontMgr::onMatchFamily(const char familyName[]) const {
57 for (const auto& fm : fList) {
58 const auto fs = fm->matchFamily(familyName);
59 if (fs->count() > 0){
60 return fs;
61 }
62 }
63 return nullptr;
64 }
65
66 sk_sp<SkTypeface> SkOrderedFontMgr::onMatchFamilyStyle(const char family[],
67 const SkFontStyle& style) const {
68 for (const auto& fm : fList) {
69 if (auto tf = fm->matchFamilyStyle(family, style)) {
70 return tf;
71 }
72 }
73 return nullptr;
74 }
75
76 sk_sp<SkTypeface> SkOrderedFontMgr::onMatchFamilyStyleCharacter(
77 const char familyName[], const SkFontStyle& style,
78 const char* bcp47[], int bcp47Count,
79 SkUnichar uni) const
80 {
81 for (const auto& fm : fList) {
82 if (auto tf = fm->matchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, uni)) {
83 return tf;
84 }
85 }
86 return nullptr;
87 }
88
89 sk_sp<SkTypeface> SkOrderedFontMgr::onLegacyMakeTypeface(const char family[], SkFontStyle style) const {
90 for (const auto& fm : fList) {
91 if (auto tf = fm->matchFamilyStyle(family, style)) {
92 return fm->legacyMakeTypeface(family, style);
93 }
94 }
95 return nullptr;
96 }
97
98 // All of these are defined to fail by returning null
99
100 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromData(sk_sp<SkData>, int ttcIndex) const {
101 return nullptr;
102 }
103
104 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
105 int ttcIndex) const {
106 return nullptr;
107 }
108
109 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
110 const SkFontArguments&) const {
111 return nullptr;
112 }
113
114 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromFile(const char path[], int ttcIndex) const {
115 return nullptr;
116 }