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