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
|
|
|
|
|
|
|
|
#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;
|
|
|
|
SkTypeface::Style fStyle;
|
|
|
|
SkTestFont* fFontCache;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkTestFont : public SkRefCnt {
|
|
|
|
public:
|
2015-06-26 18:45:03 +00:00
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
|
|
|
|
SkTestFont(const SkTestFontData& );
|
|
|
|
virtual ~SkTestFont();
|
|
|
|
int codeToIndex(SkUnichar charCode) const;
|
|
|
|
void init(const SkScalar* pts, const unsigned char* verbs);
|
|
|
|
#ifdef SK_DEBUG // detect missing test font data
|
|
|
|
mutable unsigned char fDebugBits[16];
|
|
|
|
mutable SkUnichar fDebugOverage[8];
|
|
|
|
const char* fDebugName;
|
|
|
|
SkTypeface::Style fDebugStyle;
|
|
|
|
const char* debugFontName() const { return fName; }
|
|
|
|
#endif
|
|
|
|
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:
|
2014-10-20 20:33:19 +00:00
|
|
|
SkTestTypeface(SkTestFont*, const SkFontStyle& style);
|
2014-07-31 12:58:44 +00:00
|
|
|
virtual ~SkTestTypeface() {
|
|
|
|
SkSafeUnref(fTestFont);
|
|
|
|
}
|
|
|
|
void getAdvance(SkGlyph* glyph);
|
|
|
|
void getFontMetrics(SkPaint::FontMetrics* metrics);
|
|
|
|
void getMetrics(SkGlyph* glyph);
|
|
|
|
void getPath(const SkGlyph& glyph, SkPath* path);
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkScalerContext* onCreateScalerContext(const SkDescriptor* desc) const override;
|
|
|
|
void onFilterRec(SkScalerContextRec* rec) const override;
|
2015-04-24 21:25:33 +00:00
|
|
|
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
|
2015-05-12 16:50:04 +00:00
|
|
|
PerGlyphInfo,
|
2015-04-24 21:25:33 +00:00
|
|
|
const uint32_t* glyphIDs,
|
|
|
|
uint32_t glyphIDsCount) 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 {
|
2014-07-31 12:58:44 +00:00
|
|
|
SkASSERT(0); // don't expect to get here
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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:
|
|
|
|
SkTestFont* fTestFont;
|
|
|
|
friend class SkTestScalerContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
SkTypeface* CreateTestTypeface(const char* name, SkTypeface::Style style);
|
2014-06-23 18:25:00 +00:00
|
|
|
|
|
|
|
#endif
|