summaryrefslogtreecommitdiffstats
path: root/gfx/skia/skia/src/utils/SkOrderedFontMgr.cpp
blob: c4ff5a60ef7b98f107049e2533f4a13a03eaf29c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Copyright 2021 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "include/utils/SkOrderedFontMgr.h"

#include "include/core/SkData.h" // IWYU pragma: keep
#include "include/core/SkFontStyle.h"
#include "include/core/SkStream.h" // IWYU pragma: keep
#include "include/core/SkTypeface.h" // IWYU pragma: keep

#include <utility>

class SkString;
struct SkFontArguments;

SkOrderedFontMgr::SkOrderedFontMgr() {}
SkOrderedFontMgr::~SkOrderedFontMgr() {}

void SkOrderedFontMgr::append(sk_sp<SkFontMgr> fm) {
    fList.push_back(std::move(fm));
}

int SkOrderedFontMgr::onCountFamilies() const {
    int count = 0;
    for (const auto& fm : fList) {
        count += fm->countFamilies();
    }
    return count;
}

void SkOrderedFontMgr::onGetFamilyName(int index, SkString* familyName) const {
    for (const auto& fm : fList) {
        const int count = fm->countFamilies();
        if (index < count) {
            return fm->getFamilyName(index, familyName);
        }
        index -= count;
    }
}

SkFontStyleSet* SkOrderedFontMgr::onCreateStyleSet(int index) const {
    for (const auto& fm : fList) {
        const int count = fm->countFamilies();
        if (index < count) {
            return fm->createStyleSet(index);
        }
        index -= count;
    }
    return nullptr;
}

SkFontStyleSet* SkOrderedFontMgr::onMatchFamily(const char familyName[]) const {
    for (const auto& fm : fList) {
        if (auto fs = fm->matchFamily(familyName)) {
            return fs;
        }
    }
    return nullptr;
}

SkTypeface* SkOrderedFontMgr::onMatchFamilyStyle(const char family[],
                                                 const SkFontStyle& style) const {
    for (const auto& fm : fList) {
        if (auto tf = fm->matchFamilyStyle(family, style)) {
            return tf;
        }
    }
    return nullptr;
}

SkTypeface* SkOrderedFontMgr::onMatchFamilyStyleCharacter(const char familyName[],
                                                          const SkFontStyle& style,
                                                          const char* bcp47[], int bcp47Count,
                                                          SkUnichar uni) const {
    for (const auto& fm : fList) {
        if (auto tf = fm->matchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, uni)) {
            return tf;
        }
    }
    return nullptr;
}

// All of these are defined to fail by returning null

sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromData(sk_sp<SkData>, int ttcIndex) const {
    return nullptr;
}

sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
                                                          int ttcIndex) const {
    return nullptr;
}

sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
                                                         const SkFontArguments&) const {
    return nullptr;
}

sk_sp<SkTypeface> SkOrderedFontMgr::onMakeFromFile(const char path[], int ttcIndex) const {
    return nullptr;
}

sk_sp<SkTypeface> SkOrderedFontMgr::onLegacyMakeTypeface(const char family[], SkFontStyle) const {
    return nullptr;
}