2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkTestScalerContext_DEFINED
9 #define SkTestScalerContext_DEFINED
14 #include "SkTDArray.h"
15 #include "SkTypeface.h"
19 struct SkTestFontData {
20 const SkScalar* fPoints;
21 const unsigned char* fVerbs;
22 const unsigned* fCharCodes;
23 const size_t fCharCodesCount;
24 const SkFixed* fWidths;
25 const SkPaint::FontMetrics& fMetrics;
27 SkTypeface::Style fStyle;
28 SkTestFont* fFontCache;
31 class SkTestFont : public SkRefCnt {
33 SK_DECLARE_INST_COUNT(SkTestFont)
35 SkTestFont(const SkTestFontData& );
36 virtual ~SkTestFont();
37 int codeToIndex(SkUnichar charCode) const;
38 void init(const SkScalar* pts, const unsigned char* verbs);
39 #ifdef SK_DEBUG // detect missing test font data
40 mutable unsigned char fDebugBits[16];
41 mutable SkUnichar fDebugOverage[8];
42 const char* fDebugName;
43 SkTypeface::Style fDebugStyle;
44 const char* debugFontName() const { return fName; }
47 const unsigned* fCharCodes;
48 const size_t fCharCodesCount;
49 const SkFixed* fWidths;
50 const SkPaint::FontMetrics& fMetrics;
53 friend class SkTestTypeface;
54 typedef SkRefCnt INHERITED;
58 class SkTestTypeface : public SkTypeface {
60 SkTestTypeface(SkTestFont*, const SkFontStyle& style);
61 virtual ~SkTestTypeface() {
62 SkSafeUnref(fTestFont);
64 void getAdvance(SkGlyph* glyph);
65 void getFontMetrics(SkPaint::FontMetrics* metrics);
66 void getMetrics(SkGlyph* glyph);
67 void getPath(const SkGlyph& glyph, SkPath* path);
69 SkScalerContext* onCreateScalerContext(const SkDescriptor* desc) const SK_OVERRIDE;
70 void onFilterRec(SkScalerContextRec* rec) const SK_OVERRIDE;
71 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
72 SkAdvancedTypefaceMetrics::PerGlyphInfo ,
73 const uint32_t* glyphIDs,
74 uint32_t glyphIDsCount) const SK_OVERRIDE;
76 SkStreamAsset* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
77 SkASSERT(0); // don't expect to get here
81 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const SK_OVERRIDE;
83 virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
84 uint16_t glyphs[], int glyphCount) const SK_OVERRIDE;
86 int onCountGlyphs() const SK_OVERRIDE {
87 return (int) fTestFont->fCharCodesCount;
90 int onGetUPEM() const SK_OVERRIDE {
91 SkASSERT(0); // don't expect to get here
95 void onGetFamilyName(SkString* familyName) const SK_OVERRIDE;
96 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE;
98 int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE {
102 virtual size_t onGetTableData(SkFontTableTag tag, size_t offset,
103 size_t length, void* data) const SK_OVERRIDE {
107 SkTestFont* fTestFont;
108 friend class SkTestScalerContext;
111 SkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style);