1 /*
2  * Copyright 2018 The Android Open Source Project
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 TestEmptyTypeface_DEFINED
9 #define TestEmptyTypeface_DEFINED
10 
11 #include "include/core/SkStream.h"
12 #include "include/core/SkTypeface.h"
13 #include "src/core/SkAdvancedTypefaceMetrics.h"
14 #include "src/core/SkScalerContext.h"
15 
16 class TestEmptyTypeface : public SkTypeface {
17 public:
Make()18     static sk_sp<SkTypeface> Make() { return sk_sp<SkTypeface>(new TestEmptyTypeface); }
19 
20 protected:
TestEmptyTypeface()21     TestEmptyTypeface() : SkTypeface(SkFontStyle(), true) {}
22 
23     std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
24     sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
25         return sk_ref_sp(this);
26     }
27     std::unique_ptr<SkScalerContext> onCreateScalerContext(
28         const SkScalerContextEffects& effects, const SkDescriptor* desc) const override
29     {
30         return SkScalerContext::MakeEmpty(
31                 sk_ref_sp(const_cast<TestEmptyTypeface*>(this)), effects, desc);
32     }
33     void onFilterRec(SkScalerContextRec*) const override {}
34     std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
35         return nullptr;
36     }
37     void onGetFontDescriptor(SkFontDescriptor*, bool*) const override {}
38     void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override {
39         sk_bzero(glyphs, count * sizeof(glyphs[0]));
40     }
41     int onCountGlyphs() const override { return 0; }
42     void getPostScriptGlyphNames(SkString*) const override {}
43     void getGlyphToUnicodeMap(SkUnichar*) const override {}
44     int onGetUPEM() const override { return 0; }
45     class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
46     public:
47         bool next(SkTypeface::LocalizedString*) override { return false; }
48     };
49     void onGetFamilyName(SkString* familyName) const override { familyName->reset(); }
50     bool onGetPostScriptName(SkString*) const override { return false; }
51     SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
52         return new EmptyLocalizedStrings;
53     }
54     bool onGlyphMaskNeedsCurrentColor() const override { return false; }
55     int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
56                                      int coordinateCount) const override {
57         return 0;
58     }
59     int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
60                                        int parameterCount) const override {
61         return 0;
62     }
63     int    onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
64     size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { return 0; }
65 };
66 
67 #endif  // TestEmptyTypeface_DEFINED
68