blob: 7c2fabd48b0700411b90f78ebc9cc36b578f8db9 [file] [log] [blame]
Mike Reede4b8c3a2021-04-27 13:21:05 -04001/*
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#include "src/core/SkFontDescriptor.h"
10
11SkOrderedFontMgr::SkOrderedFontMgr() {}
12SkOrderedFontMgr::~SkOrderedFontMgr() {}
13
14void SkOrderedFontMgr::append(sk_sp<SkFontMgr> fm) {
15 fList.push_back(std::move(fm));
16}
17
18int SkOrderedFontMgr::onCountFamilies() const {
19 int count = 0;
20 for (const auto& fm : fList) {
21 count += fm->countFamilies();
22 }
23 return count;
24}
25
26void SkOrderedFontMgr::onGetFamilyName(int index, SkString* familyName) const {
27 for (const auto& fm : fList) {
28 const int count = fm->countFamilies();
29 if (index < count) {
30 return fm->getFamilyName(index, familyName);
31 }
32 index -= count;
33 }
34}
35
36SkFontStyleSet* SkOrderedFontMgr::onCreateStyleSet(int index) const {
37 for (const auto& fm : fList) {
38 const int count = fm->countFamilies();
39 if (index < count) {
40 return fm->createStyleSet(index);
41 }
42 index -= count;
43 }
44 return nullptr;
45}
46
47SkFontStyleSet* SkOrderedFontMgr::onMatchFamily(const char familyName[]) const {
48 for (const auto& fm : fList) {
49 if (auto fs = fm->matchFamily(familyName)) {
50 return fs;
51 }
52 }
53 return nullptr;
54}
55
56SkTypeface* SkOrderedFontMgr::onMatchFamilyStyle(const char family[],
57 const SkFontStyle& style) const {
58 for (const auto& fm : fList) {
59 if (auto tf = fm->matchFamilyStyle(family, style)) {
60 return tf;
61 }
62 }
63 return nullptr;
64}
65
66SkTypeface* SkOrderedFontMgr::onMatchFamilyStyleCharacter(const char familyName[],
67 const SkFontStyle& style,
68 const char* bcp47[], int bcp47Count,
69 SkUnichar uni) const {
70 for (const auto& fm : fList) {
71 if (auto tf = fm->matchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, uni)) {
72 return tf;
73 }
74 }
75 return nullptr;
76}
77
78// All of these are defined to fail by returning null
79
80sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromData(sk_sp<SkData>, int ttcIndex) const {
81 return nullptr;
82}
83
84sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
85 int ttcIndex) const {
86 return nullptr;
87}
88
89sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
90 const SkFontArguments&) const {
91 return nullptr;
92}
93
Mike Reede4b8c3a2021-04-27 13:21:05 -040094sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromFile(const char path[], int ttcIndex) const {
95 return nullptr;
96}
97
98sk_sp<SkTypeface> SkOrderedFontMgr::onLegacyMakeTypeface(const char family[], SkFontStyle) const {
99 return nullptr;
100}