caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 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 SkTestScalerContext_DEFINED |
| 9 | #define SkTestScalerContext_DEFINED |
| 10 | |
benjaminwagner | 6c71e0a | 2016-04-07 08:49:31 -0700 | [diff] [blame^] | 11 | #include "SkFixed.h" |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 12 | #include "SkPaint.h" |
| 13 | #include "SkPath.h" |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 14 | #include "SkRefCnt.h" |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 15 | #include "SkTDArray.h" |
| 16 | #include "SkTypeface.h" |
| 17 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 18 | class SkTestFont; |
| 19 | |
| 20 | struct SkTestFontData { |
| 21 | const SkScalar* fPoints; |
| 22 | const unsigned char* fVerbs; |
| 23 | const unsigned* fCharCodes; |
| 24 | const size_t fCharCodesCount; |
| 25 | const SkFixed* fWidths; |
| 26 | const SkPaint::FontMetrics& fMetrics; |
| 27 | const char* fName; |
| 28 | SkTypeface::Style fStyle; |
| 29 | SkTestFont* fFontCache; |
| 30 | }; |
| 31 | |
| 32 | class SkTestFont : public SkRefCnt { |
| 33 | public: |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 34 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 35 | |
| 36 | SkTestFont(const SkTestFontData& ); |
| 37 | virtual ~SkTestFont(); |
| 38 | int codeToIndex(SkUnichar charCode) const; |
| 39 | void init(const SkScalar* pts, const unsigned char* verbs); |
| 40 | #ifdef SK_DEBUG // detect missing test font data |
| 41 | mutable unsigned char fDebugBits[16]; |
| 42 | mutable SkUnichar fDebugOverage[8]; |
| 43 | const char* fDebugName; |
| 44 | SkTypeface::Style fDebugStyle; |
| 45 | const char* debugFontName() const { return fName; } |
| 46 | #endif |
| 47 | private: |
| 48 | const unsigned* fCharCodes; |
| 49 | const size_t fCharCodesCount; |
| 50 | const SkFixed* fWidths; |
| 51 | const SkPaint::FontMetrics& fMetrics; |
| 52 | const char* fName; |
| 53 | SkPath** fPaths; |
| 54 | friend class SkTestTypeface; |
| 55 | typedef SkRefCnt INHERITED; |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | class SkTestTypeface : public SkTypeface { |
| 60 | public: |
bungeman | a4c4a2d | 2014-10-20 13:33:19 -0700 | [diff] [blame] | 61 | SkTestTypeface(SkTestFont*, const SkFontStyle& style); |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 62 | virtual ~SkTestTypeface() { |
| 63 | SkSafeUnref(fTestFont); |
| 64 | } |
| 65 | void getAdvance(SkGlyph* glyph); |
| 66 | void getFontMetrics(SkPaint::FontMetrics* metrics); |
| 67 | void getMetrics(SkGlyph* glyph); |
| 68 | void getPath(const SkGlyph& glyph, SkPath* path); |
| 69 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 70 | SkScalerContext* onCreateScalerContext(const SkDescriptor* desc) const override; |
| 71 | void onFilterRec(SkScalerContextRec* rec) const override; |
tfarina | 37a92b4 | 2015-04-24 14:25:33 -0700 | [diff] [blame] | 72 | SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
reed | 39a9a50 | 2015-05-12 09:50:04 -0700 | [diff] [blame] | 73 | PerGlyphInfo, |
tfarina | 37a92b4 | 2015-04-24 14:25:33 -0700 | [diff] [blame] | 74 | const uint32_t* glyphIDs, |
| 75 | uint32_t glyphIDsCount) const override; |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 76 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 77 | SkStreamAsset* onOpenStream(int* ttcIndex) const override { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 78 | return nullptr; |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 79 | } |
| 80 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 81 | void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override; |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 82 | |
tfarina | 37a92b4 | 2015-04-24 14:25:33 -0700 | [diff] [blame] | 83 | int onCharsToGlyphs(const void* chars, Encoding encoding, |
| 84 | uint16_t glyphs[], int glyphCount) const override; |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 85 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 86 | int onCountGlyphs() const override { |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 87 | return (int) fTestFont->fCharCodesCount; |
| 88 | } |
| 89 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 90 | int onGetUPEM() const override { |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 91 | SkASSERT(0); // don't expect to get here |
| 92 | return 1; |
| 93 | } |
| 94 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 95 | void onGetFamilyName(SkString* familyName) const override; |
| 96 | SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 97 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 98 | int onGetTableTags(SkFontTableTag tags[]) const override { |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
tfarina | 37a92b4 | 2015-04-24 14:25:33 -0700 | [diff] [blame] | 102 | size_t onGetTableData(SkFontTableTag tag, size_t offset, |
| 103 | size_t length, void* data) const override { |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 104 | return 0; |
| 105 | } |
| 106 | private: |
| 107 | SkTestFont* fTestFont; |
| 108 | friend class SkTestScalerContext; |
| 109 | }; |
| 110 | |
| 111 | SkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style); |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 112 | |
| 113 | #endif |