| 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 |
|
| 11 |
#include "include/core/SkFontArguments.h" |
| 12 |
#include "include/core/SkFontMetrics.h" |
| 13 |
#include "include/core/SkFontStyle.h" |
| 14 |
#include "include/core/SkPaint.h" |
| 15 |
#include "include/core/SkRefCnt.h" |
| 16 |
#include "include/core/SkScalar.h" |
| 17 |
#include "include/core/SkStream.h" |
| 18 |
#include "include/core/SkTypeface.h" |
| 19 |
#include "include/core/SkTypes.h" |
| 20 |
#include "include/private/base/SkFixed.h" |
| 21 |
|
| 22 |
#include <memory> |
| 23 |
|
| 24 |
class SkDescriptor; |
| 25 |
class SkFontDescriptor; |
| 26 |
class SkGlyph; |
| 27 |
class SkPath; |
| 28 |
class SkScalerContext; |
| 29 |
class SkStreamAsset; |
| 30 |
class SkString; |
| 31 |
class SkTestFont; |
| 32 |
struct SkAdvancedTypefaceMetrics; |
| 33 |
struct SkScalerContextEffects; |
| 34 |
struct SkScalerContextRec; |
| 35 |
|
| 36 |
struct SkTestFontData { |
| 37 |
const SkScalar* fPoints; |
| 38 |
const unsigned char* fVerbs; |
| 39 |
const SkUnichar* fCharCodes; |
| 40 |
const size_t fCharCodesCount; |
| 41 |
const SkFixed* fWidths; |
| 42 |
const SkFontMetrics& fMetrics; |
| 43 |
const char* fName; |
| 44 |
SkFontStyle fStyle; |
| 45 |
}; |
| 46 |
|
| 47 |
class SkTestFont : public SkRefCnt { |
| 48 |
public: |
| 49 |
SkTestFont(const SkTestFontData&); |
| 50 |
~SkTestFont() override; |
| 51 |
SkGlyphID glyphForUnichar(SkUnichar charCode) const; |
| 52 |
void init(const SkScalar* pts, const unsigned char* verbs); |
| 53 |
|
| 54 |
private: |
| 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 |
|
| 65 |
class TestTypeface : public SkTypeface { |
| 66 |
public: |
| 67 |
struct List { |
| 68 |
struct Family { |
| 69 |
struct Face { |
| 70 |
sk_sp<SkTypeface> typeface; |
| 71 |
const char* name; |
| 72 |
bool isDefault; |
| 73 |
}; |
| 74 |
std::vector<Face> faces; |
| 75 |
const char* name; |
| 76 |
}; |
| 77 |
std::vector<Family> families; |
| 78 |
}; |
| 79 |
static const List& Typefaces(); |
| 80 |
|
| 81 |
SkVector getAdvance(SkGlyphID) const; |
| 82 |
void getFontMetrics(SkFontMetrics* metrics); |
| 83 |
SkPath getPath(SkGlyphID glyph); |
| 84 |
|
| 85 |
struct Register { Register(); }; |
| 86 |
protected: |
| 87 |
std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&, |
| 88 |
const SkDescriptor* desc) const override; |
| 89 |
void onFilterRec(SkScalerContextRec* rec) const override; |
| 90 |
void getGlyphToUnicodeMap(SkSpan<SkUnichar>) const override; |
| 91 |
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; |
| 92 |
|
| 93 |
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override; |
| 94 |
|
| 95 |
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override { |
| 96 |
return sk_ref_sp(this); |
| 97 |
} |
| 98 |
|
| 99 |
void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override; |
| 100 |
|
| 101 |
void onCharsToGlyphs(SkSpan<const SkUnichar>, SkSpan<SkGlyphID>) 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; |
| 111 |
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; |
| 112 |
|
| 113 |
bool onGlyphMaskNeedsCurrentColor() const override { return false; } |
| 114 |
|
| 115 |
int onGetVariationDesignPosition( |
| 116 |
SkSpan<SkFontArguments::VariationPosition::Coordinate>) const override { |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
int onGetVariationDesignParameters(SkSpan<SkFontParameters::Variation::Axis>) const override { |
| 121 |
return 0; |
| 122 |
} |
| 123 |
|
| 124 |
int onGetTableTags(SkSpan<SkFontTableTag>) const override { return 0; } |
| 125 |
|
| 126 |
size_t onGetTableData(SkFontTableTag tag, |
| 127 |
size_t offset, |
| 128 |
size_t length, |
| 129 |
void* data) const override { |
| 130 |
return 0; |
| 131 |
} |
| 132 |
|
| 133 |
private: |
| 134 |
static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('t','e','s','t'); |
| 135 |
static sk_sp<SkTypeface> MakeFromStream(std::unique_ptr<SkStreamAsset>, const SkFontArguments&); |
| 136 |
TestTypeface(sk_sp<SkTestFont>, const SkFontStyle& style); |
| 137 |
sk_sp<SkTestFont> fTestFont; |
| 138 |
friend class SkTestScalerContext; |
| 139 |
}; |
| 140 |
|
| 141 |
#endif |