Mike Reed | e4b8c3a | 2021-04-27 13:21:05 -0400 | [diff] [blame] | 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 | |
| 11 | SkOrderedFontMgr::SkOrderedFontMgr() {} |
| 12 | SkOrderedFontMgr::~SkOrderedFontMgr() {} |
| 13 | |
| 14 | void SkOrderedFontMgr::append(sk_sp<SkFontMgr> fm) { |
| 15 | fList.push_back(std::move(fm)); |
| 16 | } |
| 17 | |
| 18 | int SkOrderedFontMgr::onCountFamilies() const { |
| 19 | int count = 0; |
| 20 | for (const auto& fm : fList) { |
| 21 | count += fm->countFamilies(); |
| 22 | } |
| 23 | return count; |
| 24 | } |
| 25 | |
| 26 | 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 | |
| 36 | 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 | |
| 47 | 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 | |
| 56 | 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 | |
| 66 | 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 | |
| 80 | sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromData(sk_sp<SkData>, int ttcIndex) const { |
| 81 | return nullptr; |
| 82 | } |
| 83 | |
| 84 | sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, |
| 85 | int ttcIndex) const { |
| 86 | return nullptr; |
| 87 | } |
| 88 | |
| 89 | sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, |
| 90 | const SkFontArguments&) const { |
| 91 | return nullptr; |
| 92 | } |
| 93 | |
Mike Reed | e4b8c3a | 2021-04-27 13:21:05 -0400 | [diff] [blame] | 94 | sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromFile(const char path[], int ttcIndex) const { |
| 95 | return nullptr; |
| 96 | } |
| 97 | |
| 98 | sk_sp<SkTypeface> SkOrderedFontMgr::onLegacyMakeTypeface(const char family[], SkFontStyle) const { |
| 99 | return nullptr; |
| 100 | } |