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 #ifndef SkOrderedFontMgr_DEFINED 9 #define SkOrderedFontMgr_DEFINED 10 11 #include "include/core/SkFontMgr.h" 12 #include "include/core/SkRefCnt.h" 13 #include "include/core/SkTypes.h" 14 15 #include <memory> 16 #include <vector> 17 18 class SkData; 19 class SkFontStyle; 20 class SkStreamAsset; 21 class SkString; 22 class SkTypeface; 23 struct SkFontArguments; 24 25 /** 26 * Collects an order list of other font managers, and visits them in order 27 * when a request to find or match is issued. 28 * 29 * Note: this explicitly fails on any attempt to Make a typeface: all of 30 * those requests will return null. 31 */ 32 class SK_API SkOrderedFontMgr : public SkFontMgr { 33 public: 34 SkOrderedFontMgr(); 35 ~SkOrderedFontMgr() override; 36 37 void append(sk_sp<SkFontMgr>); 38 39 protected: 40 int onCountFamilies() const override; 41 void onGetFamilyName(int index, SkString* familyName) const override; 42 SkFontStyleSet* onCreateStyleSet(int index)const override; 43 44 SkFontStyleSet* onMatchFamily(const char familyName[]) const override; 45 46 SkTypeface* onMatchFamilyStyle(const char familyName[], const SkFontStyle&) const override; 47 SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, 48 const char* bcp47[], int bcp47Count, 49 SkUnichar character) const override; 50 51 // Note: all of these always return null 52 sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override; 53 sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, 54 int ttcIndex) const override; 55 sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, 56 const SkFontArguments&) const override; 57 sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override; 58 59 sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override; 60 61 private: 62 std::vector<sk_sp<SkFontMgr>> fList; 63 }; 64 65 #endif 66