15fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark/*
25fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark * Copyright 2014 Google Inc.
35fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark *
45fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark * Use of this source code is governed by a BSD-style license that can be
55fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark * found in the LICENSE file.
65fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark */
75fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark
85fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark#ifndef SkTestScalerContext_DEFINED
95fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark#define SkTestScalerContext_DEFINED
105fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark
116c71e0a065c2eb32139682bb1ca1cbbeb02ebcb9benjaminwagner#include "SkFixed.h"
125fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark#include "SkPaint.h"
135fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark#include "SkPath.h"
14992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark#include "SkRefCnt.h"
155fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark#include "SkTDArray.h"
165fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark#include "SkTypeface.h"
175fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark
18992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkclass SkTestFont;
19992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
20992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkstruct SkTestFontData {
21992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const SkScalar* fPoints;
22992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const unsigned char* fVerbs;
23992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const unsigned* fCharCodes;
24992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const size_t fCharCodesCount;
25992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const SkFixed* fWidths;
26992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const SkPaint::FontMetrics& fMetrics;
27992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const char* fName;
28992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    SkTypeface::Style fStyle;
297cfd46aebda7b7d2b88e73621ed0d1be7244c2cabungeman    sk_sp<SkTestFont> fCachedFont;
30992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark};
31992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
32992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkclass SkTestFont : public SkRefCnt {
33992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkpublic:
34992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    SkTestFont(const SkTestFontData& );
35992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    virtual ~SkTestFont();
36992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    int codeToIndex(SkUnichar charCode) const;
37992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    void init(const SkScalar* pts, const unsigned char* verbs);
38992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark#ifdef SK_DEBUG  // detect missing test font data
39992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    mutable unsigned char fDebugBits[16];
40992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    mutable SkUnichar fDebugOverage[8];
41992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const char* fDebugName;
42ee6a9919a362e16c1d84a870ce867d1ad7b8a141mboc    SkFontStyle fDebugStyle;
43992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const char* debugFontName() const { return fName; }
44992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark#endif
45992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkprivate:
46992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const unsigned* fCharCodes;
47992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const size_t fCharCodesCount;
48992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const SkFixed* fWidths;
49992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const SkPaint::FontMetrics& fMetrics;
50992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    const char* fName;
51992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    SkPath** fPaths;
52992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    friend class SkTestTypeface;
53992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    typedef SkRefCnt INHERITED;
54992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark};
55992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
56992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
57992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkclass SkTestTypeface : public SkTypeface {
58992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkpublic:
597cfd46aebda7b7d2b88e73621ed0d1be7244c2cabungeman    SkTestTypeface(sk_sp<SkTestFont>, const SkFontStyle& style);
60992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    void getAdvance(SkGlyph* glyph);
61992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    void getFontMetrics(SkPaint::FontMetrics* metrics);
62992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    void getMetrics(SkGlyph* glyph);
636e9ac12495f3b64b6ea8860bb9f99c43cd33aa08Ben Wagner    void getPath(SkGlyphID glyph, SkPath* path);
64992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkprotected:
65a9322c2d86aaef1085c267dfc43cf0747f170a86reed    SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
66a9322c2d86aaef1085c267dfc43cf0747f170a86reed                                           const SkDescriptor* desc) const override;
6736352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onFilterRec(SkScalerContextRec* rec) const override;
6837a92b44373a6ace53d7f446206e9dc544fff288tfarina    SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
6939a9a5069b25aa8b9529118cfd0ece5f412fb56breed        PerGlyphInfo,
7037a92b44373a6ace53d7f446206e9dc544fff288tfarina        const uint32_t* glyphIDs,
7137a92b44373a6ace53d7f446206e9dc544fff288tfarina        uint32_t glyphIDsCount) const override;
72992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
7336352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkStreamAsset* onOpenStream(int* ttcIndex) const override {
7496fcdcc219d2a0d3579719b84b28bede76efba64halcanary        return nullptr;
75992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    }
76992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
7736352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override;
78992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
7937a92b44373a6ace53d7f446206e9dc544fff288tfarina    int onCharsToGlyphs(const void* chars, Encoding encoding,
8037a92b44373a6ace53d7f446206e9dc544fff288tfarina                        uint16_t glyphs[], int glyphCount) const override;
81992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
8236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    int onCountGlyphs() const override {
83992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark        return (int) fTestFont->fCharCodesCount;
84992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    }
85992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
8636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    int onGetUPEM() const override {
87aa3af7b4692932c4fab4109b2d9f29ae40e49ad5Hal Canary        return 2048;
88992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    }
89992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
9036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onGetFamilyName(SkString* familyName) const override;
9136352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
92992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
93fc497343cbcbd526f77da913ae2feca0e1b1b866Ben Wagner    int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
94fc497343cbcbd526f77da913ae2feca0e1b1b866Ben Wagner                                     int coordinateCount) const override
95fc497343cbcbd526f77da913ae2feca0e1b1b866Ben Wagner    {
96fc497343cbcbd526f77da913ae2feca0e1b1b866Ben Wagner        return 0;
97fc497343cbcbd526f77da913ae2feca0e1b1b866Ben Wagner    }
98fc497343cbcbd526f77da913ae2feca0e1b1b866Ben Wagner
9936352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    int onGetTableTags(SkFontTableTag tags[]) const override {
100992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark        return 0;
101992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    }
102992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
10337a92b44373a6ace53d7f446206e9dc544fff288tfarina    size_t onGetTableData(SkFontTableTag tag, size_t offset,
10437a92b44373a6ace53d7f446206e9dc544fff288tfarina                          size_t length, void* data) const override {
105992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark        return 0;
106992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    }
107992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clarkprivate:
1087cfd46aebda7b7d2b88e73621ed0d1be7244c2cabungeman    sk_sp<SkTestFont> fTestFont;
109992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark    friend class SkTestScalerContext;
110992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark};
111992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary Clark
112992c7b03ef7914a18bfd78e965b0b4c99a5f5672Cary ClarkSkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style);
1135fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark
1145fb6bd4b7e8d00b7f2543ca10ec9022b32632f29caryclark#endif
115