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 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkTestScalerContext_DEFINED
#define SkTestScalerContext_DEFINED
#include "SkFixed.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkRefCnt.h"
#include "SkTDArray.h"
#include "SkTypeface.h"
class SkTestFont;
struct SkTestFontData {
const SkScalar* fPoints;
const unsigned char* fVerbs;
const unsigned* fCharCodes;
const size_t fCharCodesCount;
const SkFixed* fWidths;
const SkPaint::FontMetrics& fMetrics;
const char* fName;
SkTypeface::Style fStyle;
sk_sp<SkTestFont> fCachedFont;
};
class SkTestFont : public SkRefCnt {
public:
SkTestFont(const SkTestFontData& );
virtual ~SkTestFont();
int codeToIndex(SkUnichar charCode) const;
void init(const SkScalar* pts, const unsigned char* verbs);
#ifdef SK_DEBUG // detect missing test font data
mutable unsigned char fDebugBits[16];
mutable SkUnichar fDebugOverage[8];
const char* fDebugName;
SkFontStyle fDebugStyle;
const char* debugFontName() const { return fName; }
#endif
private:
const unsigned* fCharCodes;
const size_t fCharCodesCount;
const SkFixed* fWidths;
const SkPaint::FontMetrics& fMetrics;
const char* fName;
SkPath** fPaths;
friend class SkTestTypeface;
typedef SkRefCnt INHERITED;
};
class SkTestTypeface : public SkTypeface {
public:
SkTestTypeface(sk_sp<SkTestFont>, const SkFontStyle& style);
void getAdvance(SkGlyph* glyph);
void getFontMetrics(SkPaint::FontMetrics* metrics);
void getMetrics(SkGlyph* glyph);
void getPath(SkGlyphID glyph, SkPath* path);
protected:
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const override;
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
return nullptr;
}
void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override;
int onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const override;
int onCountGlyphs() const override {
return (int) fTestFont->fCharCodesCount;
}
int onGetUPEM() const override {
SkASSERT(0); // don't expect to get here
return 1;
}
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetTableTags(SkFontTableTag tags[]) const override {
return 0;
}
size_t onGetTableData(SkFontTableTag tag, size_t offset,
size_t length, void* data) const override {
return 0;
}
private:
sk_sp<SkTestFont> fTestFont;
friend class SkTestScalerContext;
};
SkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style);
#endif
|