2014-06-23 18:25:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkTestScalerContext_DEFINED
|
|
|
|
#define SkTestScalerContext_DEFINED
|
|
|
|
|
2016-04-07 15:49:31 +00:00
|
|
|
#include "SkFixed.h"
|
2014-06-23 18:25:00 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPath.h"
|
2014-07-31 12:58:44 +00:00
|
|
|
#include "SkRefCnt.h"
|
2014-06-23 18:25:00 +00:00
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
class SkTestFont;
|
|
|
|
|
|
|
|
struct SkTestFontData {
|
|
|
|
const SkScalar* fPoints;
|
|
|
|
const unsigned char* fVerbs;
|
|
|
|
const unsigned* fCharCodes;
|
|
|
|
const size_t fCharCodesCount;
|
|
|
|
const SkFixed* fWidths;
|
|
|
|
const SkPaint::FontMetrics& fMetrics;
|
|
|
|
const char* fName;
|
2017-07-17 19:32:25 +00:00
|
|
|
SkFontStyle fStyle;
|
2016-10-20 20:06:52 +00:00
|
|
|
sk_sp<SkTestFont> fCachedFont;
|
2014-07-31 12:58:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SkTestFont : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
SkTestFont(const SkTestFontData& );
|
|
|
|
virtual ~SkTestFont();
|
|
|
|
int codeToIndex(SkUnichar charCode) const;
|
|
|
|
void init(const SkScalar* pts, const unsigned char* verbs);
|
|
|
|
private:
|
|
|
|
const unsigned* fCharCodes;
|
|
|
|
const size_t fCharCodesCount;
|
|
|
|
const SkFixed* fWidths;
|
|
|
|
const SkPaint::FontMetrics& fMetrics;
|
|
|
|
const char* fName;
|
|
|
|
SkPath** fPaths;
|
|
|
|
friend class SkTestTypeface;
|
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SkTestTypeface : public SkTypeface {
|
|
|
|
public:
|
2016-10-20 20:06:52 +00:00
|
|
|
SkTestTypeface(sk_sp<SkTestFont>, const SkFontStyle& style);
|
2014-07-31 12:58:44 +00:00
|
|
|
void getAdvance(SkGlyph* glyph);
|
|
|
|
void getFontMetrics(SkPaint::FontMetrics* metrics);
|
|
|
|
void getMetrics(SkGlyph* glyph);
|
2016-11-11 19:31:06 +00:00
|
|
|
void getPath(SkGlyphID glyph, SkPath* path);
|
2014-07-31 12:58:44 +00:00
|
|
|
protected:
|
2016-04-12 13:47:05 +00:00
|
|
|
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
|
|
|
const SkDescriptor* desc) const override;
|
2015-03-26 01:17:31 +00:00
|
|
|
void onFilterRec(SkScalerContextRec* rec) const override;
|
2017-05-04 18:23:55 +00:00
|
|
|
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override;
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2015-04-24 21:25:33 +00:00
|
|
|
int onCharsToGlyphs(const void* chars, Encoding encoding,
|
|
|
|
uint16_t glyphs[], int glyphCount) const override;
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
int onCountGlyphs() const override {
|
2014-07-31 12:58:44 +00:00
|
|
|
return (int) fTestFont->fCharCodesCount;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
int onGetUPEM() const override {
|
2017-03-06 21:18:49 +00:00
|
|
|
return 2048;
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onGetFamilyName(SkString* familyName) const override;
|
|
|
|
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2017-02-24 16:15:26 +00:00
|
|
|
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
|
|
|
|
int coordinateCount) const override
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
int onGetTableTags(SkFontTableTag tags[]) const override {
|
2014-07-31 12:58:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-24 21:25:33 +00:00
|
|
|
size_t onGetTableData(SkFontTableTag tag, size_t offset,
|
|
|
|
size_t length, void* data) const override {
|
2014-07-31 12:58:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
private:
|
2016-10-20 20:06:52 +00:00
|
|
|
sk_sp<SkTestFont> fTestFont;
|
2014-07-31 12:58:44 +00:00
|
|
|
friend class SkTestScalerContext;
|
|
|
|
};
|
|
|
|
|
2014-06-23 18:25:00 +00:00
|
|
|
#endif
|