Flutter Engine
The Flutter Engine
TestTypeface.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 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 TestTypeface_DEFINED
9#define TestTypeface_DEFINED
10
21
22#include <memory>
23
24class SkDescriptor;
26class SkGlyph;
27class SkPath;
28class SkScalerContext;
29class SkStreamAsset;
30class SkString;
31class SkTestFont;
35
38 const unsigned char* fVerbs;
40 const size_t fCharCodesCount;
43 const char* fName;
45};
46
47class SkTestFont : public SkRefCnt {
48public:
50 ~SkTestFont() override;
51 SkGlyphID glyphForUnichar(SkUnichar charCode) const;
52 void init(const SkScalar* pts, const unsigned char* verbs);
53
54private:
55 const SkUnichar* fCharCodes;
56 const size_t fCharCodesCount;
57 const SkFixed* fWidths;
58 const SkFontMetrics& fMetrics;
59 const char* fName;
60 SkPath* fPaths;
61 friend class TestTypeface;
62 using INHERITED = SkRefCnt;
63};
64
65class TestTypeface : public SkTypeface {
66public:
67 struct List {
68 struct Family {
69 struct Face {
71 const char* name;
73 };
74 std::vector<Face> faces;
75 const char* name;
76 };
77 std::vector<Family> families;
78 };
79 static const List& Typefaces();
80
82 void getFontMetrics(SkFontMetrics* metrics);
84
85 struct Register { Register(); };
86protected:
87 std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&,
88 const SkDescriptor* desc) const override;
89 void onFilterRec(SkScalerContextRec* rec) const override;
90 void getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const override;
91 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
92
93 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
94
96 return sk_ref_sp(this);
97 }
98
99 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override;
100
101 void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override;
102
103 int onCountGlyphs() const override { return (int)fTestFont->fCharCodesCount; }
104
105 void getPostScriptGlyphNames(SkString*) const override {}
106
107 int onGetUPEM() const override { return 2048; }
108
109 void onGetFamilyName(SkString* familyName) const override;
110 bool onGetPostScriptName(SkString*) const override;
112
113 bool onGlyphMaskNeedsCurrentColor() const override { return false; }
114
116 int coordinateCount) const override {
117 return 0;
118 }
119
121 int parameterCount) const override {
122 return 0;
123 }
124
125 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
126
128 size_t offset,
129 size_t length,
130 void* data) const override {
131 return 0;
132 }
133
134private:
135 static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('t','e','s','t');
136 static sk_sp<SkTypeface> MakeFromStream(std::unique_ptr<SkStreamAsset>, const SkFontArguments&);
138 sk_sp<SkTestFont> fTestFont;
140};
141
142#endif
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50
int32_t SkFixed
Definition: SkFixed.h:25
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
uint32_t SkFontTableTag
Definition: SkTypeface.h:41
int32_t SkUnichar
Definition: SkTypes.h:175
uint16_t SkGlyphID
Definition: SkTypes.h:179
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
Definition: SkPath.h:59
~SkTestFont() override
void init(const SkScalar *pts, const unsigned char *verbs)
SkTestFont(const SkTestFontData &)
SkGlyphID glyphForUnichar(SkUnichar charCode) const
void serialize(SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
Definition: SkTypeface.cpp:202
SkFourByteTag FactoryId
Definition: SkTypeface.h:335
void getGlyphToUnicodeMap(SkUnichar *glyphToUnicode) const override
SkVector getAdvance(SkGlyphID) const
bool onGlyphMaskNeedsCurrentColor() const override
Definition: TestTypeface.h:113
void onCharsToGlyphs(const SkUnichar *chars, int count, SkGlyphID glyphs[]) const override
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const override
Definition: TestTypeface.h:115
SkTypeface::LocalizedStrings * onCreateFamilyNameIterator() const override
int onGetUPEM() const override
Definition: TestTypeface.h:107
void getPostScriptGlyphNames(SkString *) const override
Definition: TestTypeface.h:105
bool onGetPostScriptName(SkString *) const override
std::unique_ptr< SkAdvancedTypefaceMetrics > onGetAdvancedMetrics() const override
void onGetFamilyName(SkString *familyName) const override
SkPath getPath(SkGlyphID glyph)
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], int parameterCount) const override
Definition: TestTypeface.h:120
int onGetTableTags(SkFontTableTag tags[]) const override
Definition: TestTypeface.h:125
static const List & Typefaces()
std::unique_ptr< SkStreamAsset > onOpenStream(int *ttcIndex) const override
size_t onGetTableData(SkFontTableTag tag, size_t offset, size_t length, void *data) const override
Definition: TestTypeface.h:127
std::unique_ptr< SkScalerContext > onCreateScalerContext(const SkScalerContextEffects &, const SkDescriptor *desc) const override
void getFontMetrics(SkFontMetrics *metrics)
void onFilterRec(SkScalerContextRec *rec) const override
sk_sp< SkTypeface > onMakeClone(const SkFontArguments &args) const override
Definition: TestTypeface.h:95
int onCountGlyphs() const override
Definition: TestTypeface.h:103
void onGetFontDescriptor(SkFontDescriptor *desc, bool *serialize) const override
float SkScalar
Definition: extension.cpp:12
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
size_t length
SeparatedVector2 offset
const size_t fCharCodesCount
Definition: TestTypeface.h:40
SkFontStyle fStyle
Definition: TestTypeface.h:44
const SkUnichar * fCharCodes
Definition: TestTypeface.h:39
const char * fName
Definition: TestTypeface.h:43
const SkFontMetrics & fMetrics
Definition: TestTypeface.h:42
const SkScalar * fPoints
Definition: TestTypeface.h:37
const unsigned char * fVerbs
Definition: TestTypeface.h:38
const SkFixed * fWidths
Definition: TestTypeface.h:41
sk_sp< SkTypeface > typeface
Definition: TestTypeface.h:70
std::vector< Face > faces
Definition: TestTypeface.h:74
std::vector< Family > families
Definition: TestTypeface.h:77
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63