blob: fe5c8d6ffca0653347e455635d280541b750b556 [file] [log] [blame]
caryclark5fb6bd42014-06-23 11:25:00 -07001/*
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 SkTestScalerContext_DEFINED
9#define SkTestScalerContext_DEFINED
10
11#include "SkPaint.h"
12#include "SkPath.h"
Cary Clark992c7b02014-07-31 08:58:44 -040013#include "SkRefCnt.h"
caryclark5fb6bd42014-06-23 11:25:00 -070014#include "SkTDArray.h"
15#include "SkTypeface.h"
16
Cary Clark992c7b02014-07-31 08:58:44 -040017class SkTestFont;
18
19struct 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;
26 const char* fName;
27 SkTypeface::Style fStyle;
28 SkTestFont* fFontCache;
29};
30
31class SkTestFont : public SkRefCnt {
32public:
mtklein2766c002015-06-26 11:45:03 -070033
Cary Clark992c7b02014-07-31 08:58:44 -040034
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; }
45#endif
46private:
47 const unsigned* fCharCodes;
48 const size_t fCharCodesCount;
49 const SkFixed* fWidths;
50 const SkPaint::FontMetrics& fMetrics;
51 const char* fName;
52 SkPath** fPaths;
53 friend class SkTestTypeface;
54 typedef SkRefCnt INHERITED;
55};
56
57
58class SkTestTypeface : public SkTypeface {
59public:
bungemana4c4a2d2014-10-20 13:33:19 -070060 SkTestTypeface(SkTestFont*, const SkFontStyle& style);
Cary Clark992c7b02014-07-31 08:58:44 -040061 virtual ~SkTestTypeface() {
62 SkSafeUnref(fTestFont);
63 }
64 void getAdvance(SkGlyph* glyph);
65 void getFontMetrics(SkPaint::FontMetrics* metrics);
66 void getMetrics(SkGlyph* glyph);
67 void getPath(const SkGlyph& glyph, SkPath* path);
68protected:
mtklein36352bf2015-03-25 18:17:31 -070069 SkScalerContext* onCreateScalerContext(const SkDescriptor* desc) const override;
70 void onFilterRec(SkScalerContextRec* rec) const override;
tfarina37a92b42015-04-24 14:25:33 -070071 SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
reed39a9a502015-05-12 09:50:04 -070072 PerGlyphInfo,
tfarina37a92b42015-04-24 14:25:33 -070073 const uint32_t* glyphIDs,
74 uint32_t glyphIDsCount) const override;
Cary Clark992c7b02014-07-31 08:58:44 -040075
mtklein36352bf2015-03-25 18:17:31 -070076 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
halcanary96fcdcc2015-08-27 07:41:13 -070077 return nullptr;
Cary Clark992c7b02014-07-31 08:58:44 -040078 }
79
mtklein36352bf2015-03-25 18:17:31 -070080 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override;
Cary Clark992c7b02014-07-31 08:58:44 -040081
tfarina37a92b42015-04-24 14:25:33 -070082 int onCharsToGlyphs(const void* chars, Encoding encoding,
83 uint16_t glyphs[], int glyphCount) const override;
Cary Clark992c7b02014-07-31 08:58:44 -040084
mtklein36352bf2015-03-25 18:17:31 -070085 int onCountGlyphs() const override {
Cary Clark992c7b02014-07-31 08:58:44 -040086 return (int) fTestFont->fCharCodesCount;
87 }
88
mtklein36352bf2015-03-25 18:17:31 -070089 int onGetUPEM() const override {
Cary Clark992c7b02014-07-31 08:58:44 -040090 SkASSERT(0); // don't expect to get here
91 return 1;
92 }
93
mtklein36352bf2015-03-25 18:17:31 -070094 void onGetFamilyName(SkString* familyName) const override;
95 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
Cary Clark992c7b02014-07-31 08:58:44 -040096
mtklein36352bf2015-03-25 18:17:31 -070097 int onGetTableTags(SkFontTableTag tags[]) const override {
Cary Clark992c7b02014-07-31 08:58:44 -040098 return 0;
99 }
100
tfarina37a92b42015-04-24 14:25:33 -0700101 size_t onGetTableData(SkFontTableTag tag, size_t offset,
102 size_t length, void* data) const override {
Cary Clark992c7b02014-07-31 08:58:44 -0400103 return 0;
104 }
105private:
106 SkTestFont* fTestFont;
107 friend class SkTestScalerContext;
108};
109
110SkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style);
caryclark5fb6bd42014-06-23 11:25:00 -0700111
112#endif