46 for (
const auto& sub : gSubFonts) {
47 List::Family* existingFamily =
nullptr;
49 if (strcmp(family.name, sub.fFamilyName) == 0) {
50 existingFamily = &family;
54 if (!existingFamily) {
55 existingFamily = &list.
families.emplace_back();
56 existingFamily->name = sub.fFamilyName;
59 auto font = sk_make_sp<SkTestFont>(sub.fFont);
61 bool isDefault = (&sub - gSubFonts == gDefaultFontIndex);
62 existingFamily->faces.emplace_back(
63 List::Family::Face{std::move(typeface), sub.fStyleName, isDefault});
72 , fCharCodes(fontData.fCharCodes)
73 , fCharCodesCount(fontData.fCharCodes ? fontData.fCharCodesCount : 0)
74 , fWidths(fontData.fWidths)
75 , fMetrics(fontData.fMetrics)
86 for (
size_t index = 0; index < fCharCodesCount; ++index) {
87 if (fCharCodes[index] == charCode) {
88 return SkTo<SkGlyphID>(index);
95 fPaths =
new SkPath[fCharCodesCount];
96 for (
unsigned index = 0; index < fCharCodesCount; ++index) {
110 b.
quadTo(pts[0], pts[1], pts[2], pts[3]);
114 b.
cubicTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
129 :
SkTypeface(style, false), fTestFont(
std::move(testFont)) {}
132 glyphID = glyphID < fTestFont->fCharCodesCount ? glyphID : 0;
141 glyphID = glyphID < fTestFont->fCharCodesCount ? glyphID : 0;
142 return fTestFont->fPaths[glyphID];
150 unsigned glyphCount = fTestFont->fCharCodesCount;
151 for (
unsigned gid = 0; gid < glyphCount; ++gid) {
152 glyphToUnicode[gid] = SkTo<SkUnichar>(fTestFont->fCharCodes[gid]);
158 info->fPostScriptName.set(fTestFont->fName);
183sk_sp<SkTypeface> TestTypeface::MakeFromStream(std::unique_ptr<SkStreamAsset> stream,
192 size_t familyNameSize;
194 if (!
stream->readPackedUInt(&familyNameSize)) {
return nullptr; }
195 familyName.
resize(familyNameSize);
196 if (!
stream->read(familyName.
data(), familyNameSize)) {
return nullptr; }
201 if (!
stream->readScalar(&weight)) {
return nullptr; }
202 if (!
stream->readScalar(&
width)) {
return nullptr; }
203 if (!
stream->readPackedUInt(&slant)) {
return nullptr; }
207 for (
auto&& family : list.families) {
208 if (familyName.
equals(family.name)) {
209 for (
auto&& face : family.
faces) {
210 if (face.typeface->fontStyle() == style) {
211 return face.typeface;
220 desc->setFamilyName(fTestFont->fName);
232 for (
int i = 0; i <
count; ++i) {
242 SkString familyName(fTestFont->fName);
253 fRec.getSingleMatrix(&fMatrix);
254 this->forceGenerateImageFromPath();
265 auto advance = this->getTestTypeface()->getAdvance(glyph.
getGlyphID());
274 SK_ABORT(
"Should have generated from path.");
278 *path = this->getTestTypeface()->getPath(glyph.
getGlyphID()).makeTransform(fMatrix);
283 this->getTestTypeface()->getFontMetrics(metrics);
294 return std::make_unique<SkTestScalerContext>(
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SK_ABORT(message,...)
static const char gHeaderString[]
static constexpr size_t kHeaderSize
#define SkFixedToFloat(x)
@ kNone
glyph outlines unchanged
sk_sp< T > sk_ref_sp(T *obj)
static TestTypeface::Register registerer
static constexpr const char gHeaderString[]
static constexpr const size_t kHeaderSize
std::unique_ptr< SkStreamAsset > detachAsStream()
bool write(const void *buffer, size_t size) override
void setFactoryId(SkTypeface::FactoryId factoryId)
static void ScaleFontMetrics(SkFontMetrics *, SkScalar)
SkGlyphID getGlyphID() const
SkMask::Format maskFormat() const
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
SkScalar getScaleY() const
SkPathBuilder & lineTo(SkPoint pt)
SkPathBuilder & cubicTo(SkPoint pt1, SkPoint pt2, SkPoint pt3)
SkPathBuilder & moveTo(SkPoint pt)
SkPathBuilder & quadTo(SkPoint pt1, SkPoint pt2)
const char * data() const
bool equals(const SkString &) const
void init(const SkScalar *pts, const unsigned char *verbs)
SkTestFont(const SkTestFontData &)
SkGlyphID glyphForUnichar(SkUnichar charCode) const
void generateImage(const SkGlyph &, void *) override
bool generatePath(const SkGlyph &glyph, SkPath *path) override
TestTypeface * getTestTypeface() const
SkTestScalerContext(sk_sp< TestTypeface > face, const SkScalerContextEffects &effects, const SkDescriptor *desc)
GlyphMetrics generateMetrics(const SkGlyph &glyph, SkArenaAlloc *) override
void generateFontMetrics(SkFontMetrics *metrics) override
void getFamilyName(SkString *name) const
SkFontStyle fontStyle() const
void serialize(SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
static void Register(FactoryId id, sk_sp< SkTypeface >(*make)(std::unique_ptr< SkStreamAsset >, const SkFontArguments &))
bool writePackedUInt(size_t)
bool writeScalar(SkScalar)
void getGlyphToUnicodeMap(SkUnichar *glyphToUnicode) const override
SkVector getAdvance(SkGlyphID) const
void onCharsToGlyphs(const SkUnichar *chars, int count, SkGlyphID glyphs[]) const override
SkTypeface::LocalizedStrings * onCreateFamilyNameIterator() const override
bool onGetPostScriptName(SkString *) const override
std::unique_ptr< SkAdvancedTypefaceMetrics > onGetAdvancedMetrics() const override
void onGetFamilyName(SkString *familyName) const override
SkPath getPath(SkGlyphID glyph)
static const List & Typefaces()
std::unique_ptr< SkStreamAsset > onOpenStream(int *ttcIndex) const override
std::unique_ptr< SkScalerContext > onCreateScalerContext(const SkScalerContextEffects &, const SkDescriptor *desc) const override
void getFontMetrics(SkFontMetrics *metrics)
void onFilterRec(SkScalerContextRec *rec) const override
void onGetFontDescriptor(SkFontDescriptor *desc, bool *serialize) const override
static const char header[]
void setHinting(SkFontHinting)
const unsigned char * fVerbs
std::vector< Family > families