• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/core/SkFontDescriptor.h"
10 
SkOrderedFontMgr()11 SkOrderedFontMgr::SkOrderedFontMgr() {}
~SkOrderedFontMgr()12 SkOrderedFontMgr::~SkOrderedFontMgr() {}
13 
append(sk_sp<SkFontMgr> fm)14 void SkOrderedFontMgr::append(sk_sp<SkFontMgr> fm) {
15     fList.push_back(std::move(fm));
16 }
17 
onCountFamilies() const18 int SkOrderedFontMgr::onCountFamilies() const {
19     int count = 0;
20     for (const auto& fm : fList) {
21         count += fm->countFamilies();
22     }
23     return count;
24 }
25 
onGetFamilyName(int index,SkString * familyName) const26 void 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 
onCreateStyleSet(int index) const36 SkFontStyleSet* 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 
onMatchFamily(const char familyName[]) const47 SkFontStyleSet* 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 
onMatchFamilyStyle(const char family[],const SkFontStyle & style) const56 SkTypeface* 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 
onMatchFamilyStyleCharacter(const char familyName[],const SkFontStyle & style,const char * bcp47[],int bcp47Count,SkUnichar uni) const66 SkTypeface* 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 
onMakeFromData(sk_sp<SkData>,int ttcIndex) const80 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromData(sk_sp<SkData>, int ttcIndex) const {
81     return nullptr;
82 }
83 
onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,int ttcIndex) const84 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
85                                                           int ttcIndex) const {
86     return nullptr;
87 }
88 
onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,const SkFontArguments &) const89 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
90                                                          const SkFontArguments&) const {
91     return nullptr;
92 }
93 
onMakeFromFile(const char path[],int ttcIndex) const94 sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromFile(const char path[], int ttcIndex) const {
95     return nullptr;
96 }
97 
onLegacyMakeTypeface(const char family[],SkFontStyle) const98 sk_sp<SkTypeface> SkOrderedFontMgr::onLegacyMakeTypeface(const char family[], SkFontStyle) const {
99     return nullptr;
100 }
101