skia2/tools/fonts/SkTestScalerContext.h
Ben Wagner 483c772cfd Add nativeFonts flag to Viewer.
This moves DMFontMgr and several related files which are tightly related
to fonts into tools/fonts, moves some flags around to prevent
duplication, and adds the nativeFonts handling to Viewer.

Change-Id: Id1bdad708a6b74319ac5ac9adfe21025db4ca0b2
Reviewed-on: https://skia-review.googlesource.com/108904
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
2018-02-21 03:31:14 +00:00

103 lines
2.9 KiB
C++

/*
* 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 "SkFixed.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkRefCnt.h"
#include "SkTDArray.h"
#include "SkTypeface.h"
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;
SkFontStyle fStyle;
sk_sp<SkTestFont> fCachedFont;
};
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:
SkTestTypeface(sk_sp<SkTestFont>, const SkFontStyle& style);
void getAdvance(SkGlyph* glyph);
void getFontMetrics(SkPaint::FontMetrics* metrics);
void getMetrics(SkGlyph* glyph);
void getPath(SkGlyphID glyph, SkPath* path);
protected:
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
return nullptr;
}
void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override;
int onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const override;
int onCountGlyphs() const override {
return (int) fTestFont->fCharCodesCount;
}
int onGetUPEM() const override {
return 2048;
}
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
int coordinateCount) const override
{
return 0;
}
int onGetTableTags(SkFontTableTag tags[]) const override {
return 0;
}
size_t onGetTableData(SkFontTableTag tag, size_t offset,
size_t length, void* data) const override {
return 0;
}
private:
sk_sp<SkTestFont> fTestFont;
friend class SkTestScalerContext;
};
#endif