| 1 |
/* |
| 2 |
* Copyright 2024 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/core/SkFontArguments.h" |
| 9 |
#include "include/core/SkFontMgr.h" |
| 10 |
#include "include/core/SkFontStyle.h" |
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkStream.h" |
| 13 |
#include "include/core/SkTypeface.h" |
| 14 |
#include "include/core/SkTypes.h" |
| 15 |
#include "include/ports/SkFontMgr_Fontations.h" |
| 16 |
#include "src/ports/SkTypeface_fontations_priv.h" |
| 17 |
|
| 18 |
#include <memory> |
| 19 |
#include <utility> |
| 20 |
|
| 21 |
class SkData; |
| 22 |
class SkString; |
| 23 |
|
| 24 |
|
| 25 |
namespace { |
| 26 |
|
| 27 |
/** |
| 28 |
* SkFontMgr_Fontations_Empty |
| 29 |
* |
| 30 |
* A SkFontMgr with an empty list of fonts, meant as a basic tool for font instantiation from |
| 31 |
* data in testing, see TestFontMgr in FontToolUtils. |
| 32 |
*/ |
| 33 |
class SkFontMgr_Fontations_Empty : public SkFontMgr { |
| 34 |
public: |
| 35 |
SkFontMgr_Fontations_Empty() = default; |
| 36 |
|
| 37 |
protected: |
| 38 |
int onCountFamilies() const override { return 0; } |
| 39 |
void onGetFamilyName(int index, SkString* familyName) const override {} |
| 40 |
sk_sp<SkFontStyleSet> onCreateStyleSet(int index) const override { |
| 41 |
return SkFontStyleSet::CreateEmpty(); |
| 42 |
} |
| 43 |
sk_sp<SkFontStyleSet> onMatchFamily(const char familyName[]) const override { |
| 44 |
return SkFontStyleSet::CreateEmpty(); |
| 45 |
} |
| 46 |
sk_sp<SkTypeface> onMatchFamilyStyle(const char familyName[], |
| 47 |
const SkFontStyle& fontStyle) const override { |
| 48 |
return nullptr; |
| 49 |
} |
| 50 |
sk_sp<SkTypeface> onMatchFamilyStyleCharacter(const char familyName[], |
| 51 |
const SkFontStyle&, |
| 52 |
const char* bcp47[], |
| 53 |
int bcp47Count, |
| 54 |
SkUnichar character) const override { |
| 55 |
return nullptr; |
| 56 |
} |
| 57 |
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override { |
| 58 |
return this->makeFromStream(std::make_unique<SkMemoryStream>(std::move(data)), ttcIndex); |
| 59 |
} |
| 60 |
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, |
| 61 |
int ttcIndex) const override { |
| 62 |
return this->makeFromStream(std::move(stream), |
| 63 |
SkFontArguments().setCollectionIndex(ttcIndex)); |
| 64 |
} |
| 65 |
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream, |
| 66 |
const SkFontArguments& args) const override { |
| 67 |
return SkTypeface_Fontations::MakeFromStream(std::move(stream), args); |
| 68 |
} |
| 69 |
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override { |
| 70 |
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path); |
| 71 |
return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr; |
| 72 |
} |
| 73 |
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], |
| 74 |
SkFontStyle style) const override { |
| 75 |
return nullptr; |
| 76 |
} |
| 77 |
}; |
| 78 |
|
| 79 |
} // namespace |
| 80 |
|
| 81 |
sk_sp<SkFontMgr> SkFontMgr_New_Fontations_Empty() { |
| 82 |
return sk_make_sp<SkFontMgr_Fontations_Empty>(); |
| 83 |
} |