de-Sk tools/font, and git clang-format

Change-Id: I0326eb9cc1e1e38b0fdc417567987a595f9021d2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/202310
Commit-Queue: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Mike Klein 2019-03-20 11:08:46 -05:00 committed by Skia Commit-Bot
parent cda31e164a
commit 0cffcbf97b
30 changed files with 874 additions and 886 deletions

View File

@ -1569,14 +1569,14 @@ if (skia_enable_tools) {
"tools/debugger/SkDebugCanvas.cpp",
"tools/debugger/SkDrawCommand.cpp",
"tools/debugger/SkJsonWriteBuffer.cpp",
"tools/fonts/SkRandomScalerContext.cpp",
"tools/fonts/SkTestEmptyTypeface.h",
"tools/fonts/SkTestFontMgr.cpp",
"tools/fonts/SkTestFontMgr.h",
"tools/fonts/SkTestSVGTypeface.cpp",
"tools/fonts/SkTestSVGTypeface.h",
"tools/fonts/SkTestTypeface.cpp",
"tools/fonts/SkTestTypeface.h",
"tools/fonts/RandomScalerContext.cpp",
"tools/fonts/TestEmptyTypeface.h",
"tools/fonts/TestFontMgr.cpp",
"tools/fonts/TestFontMgr.h",
"tools/fonts/TestSVGTypeface.cpp",
"tools/fonts/TestSVGTypeface.h",
"tools/fonts/TestTypeface.cpp",
"tools/fonts/TestTypeface.h",
"tools/fonts/sk_tool_utils_font.cpp",
"tools/random_parse_path.cpp",
"tools/sk_tool_utils.cpp",

View File

@ -37,9 +37,9 @@
#include "SkSpinlock.h"
#include "SkTHash.h"
#include "SkTaskGroup.h"
#include "SkTestFontMgr.h"
#include "SkTypeface_win.h"
#include "Test.h"
#include "TestFontMgr.h"
#include "ios_utils.h"
#include "sk_tool_utils.h"

View File

@ -12,7 +12,7 @@
#include "SkFontMgrPriv.h"
#include "SkImageFilter.h"
#include "SkPaint.h"
#include "SkTestFontMgr.h"
#include "TestFontMgr.h"
void FuzzImageFilterDeserialize(sk_sp<SkData> bytes) {
const int BitmapSize = 24;

View File

@ -6,8 +6,8 @@
*/
#include "../Fuzz.h"
#include "SkTestFontMgr.h"
#include "SkFontMgrPriv.h"
#include "TestFontMgr.h"
void fuzz_MockGPUCanvas(Fuzz* f);

View File

@ -6,8 +6,8 @@
*/
#include "../Fuzz.h"
#include "SkTestFontMgr.h"
#include "SkFontMgrPriv.h"
#include "TestFontMgr.h"
void fuzz_NullCanvas(Fuzz* f);

View File

@ -6,8 +6,8 @@
*/
#include "../Fuzz.h"
#include "SkTestFontMgr.h"
#include "SkFontMgrPriv.h"
#include "TestFontMgr.h"
void fuzz_RasterN32Canvas(Fuzz* f);

View File

@ -10,8 +10,8 @@
#include "SkPaint.h"
#include "SkReadBuffer.h"
#include "SkSurface.h"
#include "SkTestFontMgr.h"
#include "SkTextBlobPriv.h"
#include "TestFontMgr.h"
void FuzzTextBlobDeserialize(SkReadBuffer& buf) {
auto tb = SkTextBlobPriv::MakeFromBuffer(buf);

View File

@ -8,10 +8,10 @@
#include "gm.h"
#include "sk_tool_utils.h"
#include "RandomScalerContext.h"
#include "Resources.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkRandomScalerContext.h"
#include "SkStream.h"
#include "SkSurface.h"
#include "SkTextBlob.h"

View File

@ -87,9 +87,9 @@ if (defined(is_skia_standalone)) {
]
sources = [
"../../tools/Resources.cpp",
"../../tools/fonts/SkTestFontMgr.cpp",
"../../tools/fonts/SkTestSVGTypeface.cpp",
"../../tools/fonts/SkTestTypeface.cpp",
"../../tools/fonts/TestFontMgr.cpp",
"../../tools/fonts/TestSVGTypeface.cpp",
"../../tools/fonts/TestTypeface.cpp",
"fuzz/FuzzSkottieJSON.cpp",
]

View File

@ -8,8 +8,8 @@
#include "SkData.h"
#include "SkFontMgrPriv.h"
#include "SkStream.h"
#include "SkTestFontMgr.h"
#include "Skottie.h"
#include "TestFontMgr.h"
void FuzzSkottieJSON(sk_sp<SkData> bytes) {
SkMemoryStream stream(bytes);

View File

@ -456,14 +456,14 @@ DM_SRCS_ALL = struct(
"tools/debugger/*.h",
"tools/flags/*.cpp",
"tools/flags/*.h",
"tools/fonts/SkRandomScalerContext.cpp",
"tools/fonts/SkRandomScalerContext.h",
"tools/fonts/SkTestFontMgr.cpp",
"tools/fonts/SkTestFontMgr.h",
"tools/fonts/SkTestSVGTypeface.cpp",
"tools/fonts/SkTestSVGTypeface.h",
"tools/fonts/SkTestTypeface.cpp",
"tools/fonts/SkTestTypeface.h",
"tools/fonts/RandomScalerContext.cpp",
"tools/fonts/RandomScalerContext.h",
"tools/fonts/TestFontMgr.cpp",
"tools/fonts/TestFontMgr.h",
"tools/fonts/TestSVGTypeface.cpp",
"tools/fonts/TestSVGTypeface.h",
"tools/fonts/TestTypeface.cpp",
"tools/fonts/TestTypeface.h",
"tools/fonts/sk_tool_utils_font.cpp",
"tools/fonts/test_font_monospace.inc",
"tools/fonts/test_font_sans_serif.inc",

View File

@ -396,7 +396,7 @@ protected:
void forceOffGenerateImageFromPath() { fGenerateImageFromPath = false; }
private:
friend class SkRandomScalerContext; // For debug purposes
friend class RandomScalerContext; // For debug purposes
static SkScalerContextRec PreprocessRec(const SkTypeface& typeface,
const SkScalerContextEffects& effects,

View File

@ -15,10 +15,10 @@
#include "SkStrikeCache.h"
#include "SkSurface.h"
#include "SkSurfacePriv.h"
#include "SkTestEmptyTypeface.h"
#include "SkTextBlob.h"
#include "SkTypeface_remote.h"
#include "Test.h"
#include "TestEmptyTypeface.h"
#include "text/GrTextContext.h"
@ -240,7 +240,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_ReleaseTypeFace, reporter,
SkStrikeClient client(discardableManager, false);
// Server.
auto serverTf = SkTestEmptyTypeface::Make();
auto serverTf = TestEmptyTypeface::Make();
auto serverTfData = server.serializeTypeface(serverTf.get());
REPORTER_ASSERT(reporter, serverTf->unique());

View File

@ -7,13 +7,13 @@
#include "sk_tool_utils.h"
#include "RandomScalerContext.h"
#include "SkCanvas.h"
#include "SkFontMgr.h"
#include "SkGlyphRun.h"
#include "SkGraphics.h"
#include "SkPaint.h"
#include "SkPoint.h"
#include "SkRandomScalerContext.h"
#include "SkSurface.h"
#include "SkTextBlob.h"
#include "SkTypeface.h"

View File

@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
#include "Resources.h"
#include "SkAdvancedTypefaceMetrics.h"
#include "SkData.h"
#include "SkFixed.h"
@ -12,14 +13,13 @@
#include "SkFontMgr.h"
#include "SkMakeUnique.h"
#include "SkOTTable_OS_2.h"
#include "SkRefCnt.h"
#include "SkSFNTHeader.h"
#include "SkStream.h"
#include "SkRefCnt.h"
#include "SkTestEmptyTypeface.h"
#include "SkTypeface.h"
#include "SkTypefaceCache.h"
#include "Resources.h"
#include "Test.h"
#include "TestEmptyTypeface.h"
#include <memory>
@ -277,12 +277,12 @@ static int count(skiatest::Reporter* reporter, const SkTypefaceCache& cache) {
}
DEF_TEST(TypefaceCache, reporter) {
sk_sp<SkTypeface> t1(SkTestEmptyTypeface::Make());
sk_sp<SkTypeface> t1(TestEmptyTypeface::Make());
{
SkTypefaceCache cache;
REPORTER_ASSERT(reporter, count(reporter, cache) == 0);
{
sk_sp<SkTypeface> t0(SkTestEmptyTypeface::Make());
sk_sp<SkTypeface> t0(TestEmptyTypeface::Make());
cache.add(t0);
REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
cache.add(t1);

View File

@ -5,63 +5,60 @@
* found in the LICENSE file.
*/
#include "RandomScalerContext.h"
#include "SkAdvancedTypefaceMetrics.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkGlyph.h"
#include "SkMakeUnique.h"
#include "SkPath.h"
#include "SkRandomScalerContext.h"
#include "SkRectPriv.h"
class SkDescriptor;
class SkRandomScalerContext : public SkScalerContext {
class RandomScalerContext : public SkScalerContext {
public:
SkRandomScalerContext(sk_sp<SkRandomTypeface>, const SkScalerContextEffects&,
const SkDescriptor*, bool fFakeIt);
RandomScalerContext(sk_sp<SkRandomTypeface>,
const SkScalerContextEffects&,
const SkDescriptor*,
bool fFakeIt);
protected:
unsigned generateGlyphCount() override;
uint16_t generateCharToGlyph(SkUnichar) override;
bool generateAdvance(SkGlyph*) override;
void generateMetrics(SkGlyph*) override;
void generateImage(const SkGlyph&) override;
bool generatePath(SkGlyphID, SkPath*) override;
void generateFontMetrics(SkFontMetrics*) override;
bool generateAdvance(SkGlyph*) override;
void generateMetrics(SkGlyph*) override;
void generateImage(const SkGlyph&) override;
bool generatePath(SkGlyphID, SkPath*) override;
void generateFontMetrics(SkFontMetrics*) override;
private:
SkRandomTypeface* getRandomTypeface() const {
return static_cast<SkRandomTypeface*>(this->getTypeface());
}
std::unique_ptr<SkScalerContext> fProxy;
bool fFakeIt;
bool fFakeIt;
};
SkRandomScalerContext::SkRandomScalerContext(sk_sp<SkRandomTypeface> face,
const SkScalerContextEffects& effects,
const SkDescriptor* desc,
bool fakeIt)
RandomScalerContext::RandomScalerContext(sk_sp<SkRandomTypeface> face,
const SkScalerContextEffects& effects,
const SkDescriptor* desc,
bool fakeIt)
: SkScalerContext(std::move(face), effects, desc)
, fProxy(getRandomTypeface()->proxy()->createScalerContext(SkScalerContextEffects(), desc))
, fFakeIt(fakeIt)
{
, fFakeIt(fakeIt) {
fProxy->forceGenerateImageFromPath();
}
unsigned SkRandomScalerContext::generateGlyphCount() {
return fProxy->getGlyphCount();
}
unsigned RandomScalerContext::generateGlyphCount() { return fProxy->getGlyphCount(); }
uint16_t SkRandomScalerContext::generateCharToGlyph(SkUnichar uni) {
uint16_t RandomScalerContext::generateCharToGlyph(SkUnichar uni) {
return fProxy->charToGlyphID(uni);
}
bool SkRandomScalerContext::generateAdvance(SkGlyph* glyph) {
return fProxy->generateAdvance(glyph);
}
bool RandomScalerContext::generateAdvance(SkGlyph* glyph) { return fProxy->generateAdvance(glyph); }
void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
void RandomScalerContext::generateMetrics(SkGlyph* glyph) {
// Here we will change the mask format of the glyph
// NOTE: this may be overridden by the base class (e.g. if a mask filter is applied).
switch (glyph->getGlyphID() % 4) {
@ -83,20 +80,19 @@ void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
}
glyph->fMaskFormat = SkMask::kARGB32_Format;
SkRect storage;
SkRect storage;
const SkPaint& paint = this->getRandomTypeface()->paint();
const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
&storage,
SkPaint::kFill_Style);
const SkRect& newBounds =
paint.doComputeFastBounds(path.getBounds(), &storage, SkPaint::kFill_Style);
SkIRect ibounds;
newBounds.roundOut(&ibounds);
glyph->fLeft = ibounds.fLeft;
glyph->fTop = ibounds.fTop;
glyph->fWidth = ibounds.width();
glyph->fLeft = ibounds.fLeft;
glyph->fTop = ibounds.fTop;
glyph->fWidth = ibounds.width();
glyph->fHeight = ibounds.height();
}
void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
void RandomScalerContext::generateImage(const SkGlyph& glyph) {
// TODO: can force down but not up
/*
SkMask::Format format = (SkMask::Format)glyph.fMaskFormat;
@ -128,7 +124,8 @@ void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
SkBitmap bm;
bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight),
glyph.fImage, glyph.rowBytes());
glyph.fImage,
glyph.rowBytes());
bm.eraseColor(0);
SkCanvas canvas(bm);
@ -136,26 +133,26 @@ void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
canvas.drawPath(path, this->getRandomTypeface()->paint());
}
bool SkRandomScalerContext::generatePath(SkGlyphID glyph, SkPath* path) {
bool RandomScalerContext::generatePath(SkGlyphID glyph, SkPath* path) {
return fProxy->generatePath(glyph, path);
}
void SkRandomScalerContext::generateFontMetrics(SkFontMetrics* metrics) {
void RandomScalerContext::generateFontMetrics(SkFontMetrics* metrics) {
fProxy->getFontMetrics(metrics);
}
///////////////////////////////////////////////////////////////////////////////
SkRandomTypeface::SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint, bool fakeIt)
: SkTypeface(proxy->fontStyle(), false)
, fProxy(std::move(proxy))
, fPaint(paint)
, fFakeIt(fakeIt) {}
: SkTypeface(proxy->fontStyle(), false)
, fProxy(std::move(proxy))
, fPaint(paint)
, fFakeIt(fakeIt) {}
SkScalerContext* SkRandomTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const {
return new SkRandomScalerContext(sk_ref_sp(const_cast<SkRandomTypeface*>(this)),
effects, desc, fFakeIt);
const SkDescriptor* desc) const {
return new RandomScalerContext(
sk_ref_sp(const_cast<SkRandomTypeface*>(this)), effects, desc, fFakeIt);
}
void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {
@ -190,18 +187,16 @@ void SkRandomTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal
fProxy->getFontDescriptor(desc, isLocal);
}
int SkRandomTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const {
int SkRandomTypeface::onCharsToGlyphs(const void* chars,
Encoding encoding,
uint16_t glyphs[],
int glyphCount) const {
return fProxy->charsToGlyphs(chars, encoding, glyphs, glyphCount);
}
int SkRandomTypeface::onCountGlyphs() const {
return fProxy->countGlyphs();
}
int SkRandomTypeface::onCountGlyphs() const { return fProxy->countGlyphs(); }
int SkRandomTypeface::onGetUPEM() const {
return fProxy->getUnitsPerEm();
}
int SkRandomTypeface::onGetUPEM() const { return fProxy->getUnitsPerEm(); }
void SkRandomTypeface::onGetFamilyName(SkString* familyName) const {
fProxy->getFamilyName(familyName);
@ -212,14 +207,13 @@ SkTypeface::LocalizedStrings* SkRandomTypeface::onCreateFamilyNameIterator() con
}
int SkRandomTypeface::onGetVariationDesignPosition(
SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const
{
SkFontArguments::VariationPosition::Coordinate coordinates[],
int coordinateCount) const {
return fProxy->onGetVariationDesignPosition(coordinates, coordinateCount);
}
int SkRandomTypeface::onGetVariationDesignParameters(
SkFontParameters::Variation::Axis parameters[], int parameterCount) const
{
int SkRandomTypeface::onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
int parameterCount) const {
return fProxy->onGetVariationDesignParameters(parameters, parameterCount);
}
@ -227,8 +221,9 @@ int SkRandomTypeface::onGetTableTags(SkFontTableTag tags[]) const {
return fProxy->getTableTags(tags);
}
size_t SkRandomTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
size_t length, void* data) const {
size_t SkRandomTypeface::onGetTableData(SkFontTableTag tag,
size_t offset,
size_t length,
void* data) const {
return fProxy->getTableData(tag, offset, length, data);
}

View File

@ -5,8 +5,8 @@
* found in the LICENSE file.
*/
#ifndef SkRandomScalerContext_DEFINED
#define SkRandomScalerContext_DEFINED
#ifndef RandomScalerContext_DEFINED
#define RandomScalerContext_DEFINED
#include "SkScalerContext.h"
#include "SkTypeface.h"
@ -20,25 +20,27 @@ class SkRandomTypeface : public SkTypeface {
public:
SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint&, bool fakeit);
SkTypeface* proxy() const { return fProxy.get(); }
SkTypeface* proxy() const { return fProxy.get(); }
const SkPaint& paint() const { return fPaint; }
protected:
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
void getGlyphToUnicodeMap(SkUnichar*) const override;
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
void getGlyphToUnicodeMap(SkUnichar*) const override;
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const override;
int onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const override;
int onCharsToGlyphs(const void* chars,
Encoding encoding,
uint16_t glyphs[],
int glyphCount) const override;
int onCountGlyphs() const override;
int onGetUPEM() const override;
void onGetFamilyName(SkString* familyName) const override;
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
@ -46,13 +48,12 @@ protected:
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
int parameterCount) const override;
int onGetTableTags(SkFontTableTag tags[]) const override;
size_t onGetTableData(SkFontTableTag, size_t offset,
size_t length, void* data) const override;
size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override;
private:
sk_sp<SkTypeface> fProxy;
SkPaint fPaint;
bool fFakeIt;
sk_sp<SkTypeface> fProxy;
SkPaint fPaint;
bool fFakeIt;
};
#endif

View File

@ -1,150 +0,0 @@
/*
* 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 SkTestSVGTypeface_DEFINED
#define SkTestSVGTypeface_DEFINED
#include "SkFontArguments.h"
#include "SkFontMetrics.h"
#include "SkMutex.h"
#include "SkPaint.h"
#include "SkPathOps.h"
#include "SkPoint.h"
#include "SkRect.h"
#include "SkRefCnt.h"
#include "SkScalar.h"
#include "SkSpan.h"
#include "SkStream.h"
#include "SkString.h"
#include "SkTArray.h"
#include "SkTHash.h"
#include "SkTypeface.h"
#include "SkTypes.h"
#include <memory>
class SkDescriptor;
class SkFontDescriptor;
class SkFontStyle;
class SkGlyph;
class SkPath;
class SkScalerContext;
class SkSVGDOM;
class SkWStream;
struct SkAdvancedTypefaceMetrics;
struct SkScalerContextEffects;
struct SkScalerContextRec;
struct SkSVGTestTypefaceGlyphData {
const char* fSvgResourcePath;
SkPoint fOrigin; // y-down
SkScalar fAdvance;
SkUnichar fUnicode; //TODO: this limits to 1:1
};
class SkTestSVGTypeface : public SkTypeface {
public:
SkTestSVGTypeface(const char* name,
int upem,
const SkFontMetrics& metrics,
SkSpan<const SkSVGTestTypefaceGlyphData> data,
const SkFontStyle& style);
~SkTestSVGTypeface() override;
void getAdvance(SkGlyph* glyph) const;
void getFontMetrics(SkFontMetrics* metrics) const;
static sk_sp<SkTestSVGTypeface> Default();
static sk_sp<SkTestSVGTypeface> Planets();
void exportTtxCbdt(SkWStream*, SkSpan<unsigned> strikeSizes) const;
void exportTtxSbix(SkWStream*, SkSpan<unsigned> strikeSizes) const;
void exportTtxColr(SkWStream*) const;
virtual bool getPathOp(SkColor, SkPathOp*) const = 0;
struct GlyfLayerInfo {
GlyfLayerInfo(int layerColorIndex, SkIRect bounds)
: fLayerColorIndex(layerColorIndex)
, fBounds(bounds) {}
int fLayerColorIndex;
SkIRect fBounds;
};
struct GlyfInfo {
GlyfInfo() : fBounds(SkIRect::MakeEmpty()) {}
SkIRect fBounds;
SkTArray<GlyfLayerInfo> fLayers;
};
protected:
void exportTtxCommon(SkWStream*, const char* type, const SkTArray<GlyfInfo>* = nullptr) const;
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
void getGlyphToUnicodeMap(SkUnichar*) const override;
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override {
return nullptr;
}
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
return sk_ref_sp(this);
}
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 fGlyphCount;
}
int onGetUPEM() const override {
return fUpem;
}
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
int coordinateCount) const override
{
return 0;
}
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
int parameterCount) 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:
struct Glyph {
Glyph();
~Glyph();
sk_sp<SkSVGDOM> fSvg;
SkMutex fSvgMutex;
SkPoint fOrigin;
SkScalar fAdvance;
};
SkString fName;
int fUpem;
const SkFontMetrics fFontMetrics;
std::unique_ptr<Glyph[]> fGlyphs;
int fGlyphCount;
SkTHashMap<SkUnichar, SkGlyphID> fCMap;
friend class SkTestSVGScalerContext;
};
#endif

View File

@ -5,32 +5,35 @@
* found in the LICENSE file.
*/
#ifndef SkTestEmptyTypeface_DEFINED
#define SkTestEmptyTypeface_DEFINED
#ifndef TestEmptyTypeface_DEFINED
#define TestEmptyTypeface_DEFINED
#include "SkTypeface.h"
class SkTestEmptyTypeface : public SkTypeface {
class TestEmptyTypeface : public SkTypeface {
public:
static sk_sp<SkTypeface> Make() { return sk_sp<SkTypeface>(new SkTestEmptyTypeface); }
static sk_sp<SkTypeface> Make() { return sk_sp<SkTypeface>(new TestEmptyTypeface); }
protected:
SkTestEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
TestEmptyTypeface() : SkTypeface(SkFontStyle(), true) {}
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
return sk_ref_sp(this);
}
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const override {
return nullptr;
}
void onFilterRec(SkScalerContextRec*) const override { }
void onFilterRec(SkScalerContextRec*) const override {}
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
return nullptr;
}
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const override {
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override {}
virtual int onCharsToGlyphs(const void* chars,
Encoding encoding,
uint16_t glyphs[],
int glyphCount) const override {
if (glyphs && glyphCount > 0) {
sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
}
@ -42,27 +45,20 @@ protected:
public:
bool next(SkTypeface::LocalizedString*) override { return false; }
};
void onGetFamilyName(SkString* familyName) const override {
familyName->reset();
}
void onGetFamilyName(SkString* familyName) const override { familyName->reset(); }
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
return new EmptyLocalizedStrings;
}
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
int coordinateCount) const override
{
int coordinateCount) const override {
return 0;
}
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
int parameterCount) const override
{
return 0;
}
int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
int parameterCount) const override {
return 0;
}
int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { return 0; }
};
#endif // SkTestEmptyTypeface_DEFINED
#endif // TestEmptyTypeface_DEFINED

View File

@ -5,13 +5,13 @@
* found in the LICENSE file.
*/
#include "TestFontMgr.h"
#include "SkFontDescriptor.h"
#include "SkTestFontMgr.h"
#include "SkTestTypeface.h"
#include "TestTypeface.h"
#include "sk_tool_utils.h"
#ifdef SK_XML
#include "SkTestSVGTypeface.h"
#include "TestSVGTypeface.h"
#endif
#include <vector>
@ -21,27 +21,29 @@ namespace {
#include "test_font_monospace.inc"
#include "test_font_sans_serif.inc"
#include "test_font_serif.inc"
#include "test_font_index.inc"
class FontStyleSet final : public SkFontStyleSet {
public:
FontStyleSet(const char* familyName) : fFamilyName(familyName) { }
FontStyleSet(const char* familyName) : fFamilyName(familyName) {}
struct TypefaceEntry {
TypefaceEntry(sk_sp<SkTypeface> typeface, SkFontStyle style, const char* styleName)
: fTypeface(std::move(typeface))
, fStyle(style)
, fStyleName(styleName)
{}
: fTypeface(std::move(typeface)), fStyle(style), fStyleName(styleName) {}
sk_sp<SkTypeface> fTypeface;
SkFontStyle fStyle;
const char* fStyleName;
SkFontStyle fStyle;
const char* fStyleName;
};
int count() override { return fTypefaces.size(); }
void getStyle(int index, SkFontStyle* style, SkString* name) override {
if (style) { *style = fTypefaces[index].fStyle; }
if (name) { *name = fTypefaces[index].fStyleName; }
if (style) {
*style = fTypefaces[index].fStyle;
}
if (name) {
*name = fTypefaces[index].fStyleName;
}
}
SkTypeface* createTypeface(int index) override {
@ -55,24 +57,25 @@ public:
SkString getFamilyName() { return fFamilyName; }
std::vector<TypefaceEntry> fTypefaces;
SkString fFamilyName;
SkString fFamilyName;
};
class FontMgr final : public SkFontMgr {
public:
FontMgr() {
for (const auto& sub : gSubFonts) {
sk_sp<SkTestTypeface> typeface =
sk_make_sp<SkTestTypeface>(sk_make_sp<SkTestFont>(sub.fFont), sub.fStyle);
sk_sp<TestTypeface> typeface =
sk_make_sp<TestTypeface>(sk_make_sp<SkTestFont>(sub.fFont), sub.fStyle);
bool defaultFamily = false;
if (&sub - gSubFonts == gDefaultFontIndex) {
defaultFamily = true;
defaultFamily = true;
fDefaultTypeface = typeface;
}
bool found = false;
for (const auto& family : fFamilies) {
if (family->getFamilyName().equals(sub.fFamilyName)) {
family->fTypefaces.emplace_back(std::move(typeface), sub.fStyle, sub.fStyleName);
family->fTypefaces.emplace_back(
std::move(typeface), sub.fStyle, sub.fStyleName);
found = true;
if (defaultFamily) {
fDefaultFamily = family;
@ -82,22 +85,25 @@ public:
}
if (!found) {
fFamilies.emplace_back(sk_make_sp<FontStyleSet>(sub.fFamilyName));
// NOLINTNEXTLINE(bugprone-use-after-move)
fFamilies.back()->fTypefaces.emplace_back(std::move(typeface), sub.fStyle, sub.fStyleName);
fFamilies.back()->fTypefaces.emplace_back(
// NOLINTNEXTLINE(bugprone-use-after-move)
std::move(typeface),
sub.fStyle,
sub.fStyleName);
if (defaultFamily) {
fDefaultFamily = fFamilies.back();
}
}
}
#ifdef SK_XML
#ifdef SK_XML
fFamilies.emplace_back(sk_make_sp<FontStyleSet>("Emoji"));
fFamilies.back()->fTypefaces.emplace_back(SkTestSVGTypeface::Default(),
SkFontStyle::Normal(), "Normal");
fFamilies.back()->fTypefaces.emplace_back(
TestSVGTypeface::Default(), SkFontStyle::Normal(), "Normal");
fFamilies.emplace_back(sk_make_sp<FontStyleSet>("Planet"));
fFamilies.back()->fTypefaces.emplace_back(SkTestSVGTypeface::Planets(),
SkFontStyle::Normal(), "Normal");
#endif
fFamilies.back()->fTypefaces.emplace_back(
TestSVGTypeface::Planets(), SkFontStyle::Normal(), "Normal");
#endif
}
int onCountFamilies() const override { return fFamilies.size(); }
@ -113,44 +119,51 @@ public:
SkFontStyleSet* onMatchFamily(const char familyName[]) const override {
if (familyName) {
if (strstr(familyName, "ono" )) { return this->createStyleSet(0); }
if (strstr(familyName, "ans" )) { return this->createStyleSet(1); }
if (strstr(familyName, "erif" )) { return this->createStyleSet(2); }
#ifdef SK_XML
if (strstr(familyName, "oji" )) { return this->createStyleSet(6); }
if (strstr(familyName, "Planet")) { return this->createStyleSet(7); }
#endif
if (strstr(familyName, "ono")) {
return this->createStyleSet(0);
}
if (strstr(familyName, "ans")) {
return this->createStyleSet(1);
}
if (strstr(familyName, "erif")) {
return this->createStyleSet(2);
}
#ifdef SK_XML
if (strstr(familyName, "oji")) {
return this->createStyleSet(6);
}
if (strstr(familyName, "Planet")) {
return this->createStyleSet(7);
}
#endif
}
return nullptr;
}
SkTypeface* onMatchFamilyStyle(const char familyName[],
SkTypeface* onMatchFamilyStyle(const char familyName[],
const SkFontStyle& style) const override {
sk_sp<SkFontStyleSet> styleSet(this->matchFamily(familyName));
return styleSet->matchStyle(style);
}
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle& style,
const char* bcp47[], int bcp47Count,
SkUnichar character) const override {
const char* bcp47[],
int bcp47Count,
SkUnichar character) const override {
(void)bcp47;
(void)bcp47Count;
(void)character;
return this->matchFamilyStyle(familyName, style);
}
SkTypeface* onMatchFaceStyle(const SkTypeface* tf,
const SkFontStyle& style) const override {
SkTypeface* onMatchFaceStyle(const SkTypeface* tf, const SkFontStyle& style) const override {
SkString familyName;
tf->getFamilyName(&familyName);
return this->matchFamilyStyle(familyName.c_str(), style);
}
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override {
return nullptr;
}
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override { return nullptr; }
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
int ttcIndex) const override {
return nullptr;
@ -166,7 +179,7 @@ public:
return nullptr;
}
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[],
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[],
SkFontStyle style) const override {
if (familyName == nullptr) {
return sk_sp<SkTypeface>(fDefaultFamily->matchStyle(style));
@ -180,11 +193,11 @@ public:
private:
std::vector<sk_sp<FontStyleSet>> fFamilies;
sk_sp<FontStyleSet> fDefaultFamily;
sk_sp<SkTypeface> fDefaultTypeface;
sk_sp<FontStyleSet> fDefaultFamily;
sk_sp<SkTypeface> fDefaultTypeface;
};
}
} // namespace
namespace sk_tool_utils {
sk_sp<SkFontMgr> MakePortableFontMgr() { return sk_make_sp<FontMgr>(); }
} // namespace sk_tool_utils
} // namespace sk_tool_utils

View File

@ -5,15 +5,15 @@
* found in the LICENSE file.
*/
#ifndef SkTestFontMgr_DEFINED
#define SkTestFontMgr_DEFINED
#ifndef TestFontMgr_DEFINED
#define TestFontMgr_DEFINED
#include "SkFontMgr.h"
// An SkFontMgr that always uses sk_tool_utils::create_portable_typeface().
namespace sk_tool_utils {
sk_sp<SkFontMgr> MakePortableFontMgr();
sk_sp<SkFontMgr> MakePortableFontMgr();
} // namespace sk_tool_utils
#endif //SkTestFontMgr_DEFINED
#endif // TestFontMgr_DEFINED

View File

@ -0,0 +1,145 @@
/*
* 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 TestSVGTypeface_DEFINED
#define TestSVGTypeface_DEFINED
#include "SkFontArguments.h"
#include "SkFontMetrics.h"
#include "SkMutex.h"
#include "SkPaint.h"
#include "SkPathOps.h"
#include "SkPoint.h"
#include "SkRect.h"
#include "SkRefCnt.h"
#include "SkScalar.h"
#include "SkSpan.h"
#include "SkStream.h"
#include "SkString.h"
#include "SkTArray.h"
#include "SkTHash.h"
#include "SkTypeface.h"
#include "SkTypes.h"
#include <memory>
class SkDescriptor;
class SkFontDescriptor;
class SkFontStyle;
class SkGlyph;
class SkPath;
class SkScalerContext;
class SkSVGDOM;
class SkWStream;
struct SkAdvancedTypefaceMetrics;
struct SkScalerContextEffects;
struct SkScalerContextRec;
struct SkSVGTestTypefaceGlyphData {
const char* fSvgResourcePath;
SkPoint fOrigin; // y-down
SkScalar fAdvance;
SkUnichar fUnicode; // TODO: this limits to 1:1
};
class TestSVGTypeface : public SkTypeface {
public:
TestSVGTypeface(const char* name,
int upem,
const SkFontMetrics& metrics,
SkSpan<const SkSVGTestTypefaceGlyphData> data,
const SkFontStyle& style);
~TestSVGTypeface() override;
void getAdvance(SkGlyph* glyph) const;
void getFontMetrics(SkFontMetrics* metrics) const;
static sk_sp<TestSVGTypeface> Default();
static sk_sp<TestSVGTypeface> Planets();
void exportTtxCbdt(SkWStream*, SkSpan<unsigned> strikeSizes) const;
void exportTtxSbix(SkWStream*, SkSpan<unsigned> strikeSizes) const;
void exportTtxColr(SkWStream*) const;
virtual bool getPathOp(SkColor, SkPathOp*) const = 0;
struct GlyfLayerInfo {
GlyfLayerInfo(int layerColorIndex, SkIRect bounds)
: fLayerColorIndex(layerColorIndex), fBounds(bounds) {}
int fLayerColorIndex;
SkIRect fBounds;
};
struct GlyfInfo {
GlyfInfo() : fBounds(SkIRect::MakeEmpty()) {}
SkIRect fBounds;
SkTArray<GlyfLayerInfo> fLayers;
};
protected:
void exportTtxCommon(SkWStream*, const char* type, const SkTArray<GlyfInfo>* = nullptr) const;
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
void getGlyphToUnicodeMap(SkUnichar*) const override;
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
return sk_ref_sp(this);
}
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 fGlyphCount; }
int onGetUPEM() const override { return fUpem; }
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
int coordinateCount) const override {
return 0;
}
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
int parameterCount) 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:
struct Glyph {
Glyph();
~Glyph();
sk_sp<SkSVGDOM> fSvg;
SkMutex fSvgMutex;
SkPoint fOrigin;
SkScalar fAdvance;
};
SkString fName;
int fUpem;
const SkFontMetrics fFontMetrics;
std::unique_ptr<Glyph[]> fGlyphs;
int fGlyphCount;
SkTHashMap<SkUnichar, SkGlyphID> fCMap;
friend class SkTestSVGScalerContext;
};
#endif

View File

@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
#include "TestTypeface.h"
#include "SkAdvancedTypefaceMetrics.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
@ -22,7 +23,6 @@
#include "SkScalerContext.h"
#include "SkString.h"
#include "SkTDArray.h"
#include "SkTestTypeface.h"
#include "SkTo.h"
#include "SkUtils.h"
@ -31,14 +31,13 @@
class SkDescriptor;
SkTestFont::SkTestFont(const SkTestFontData& fontData)
: INHERITED()
, fCharCodes(fontData.fCharCodes)
, fCharCodesCount(fontData.fCharCodes ? fontData.fCharCodesCount : 0)
, fWidths(fontData.fWidths)
, fMetrics(fontData.fMetrics)
, fName(fontData.fName)
, fPaths(nullptr)
{
: INHERITED()
, fCharCodes(fontData.fCharCodes)
, fCharCodesCount(fontData.fCharCodes ? fontData.fCharCodesCount : 0)
, fWidths(fontData.fWidths)
, fMetrics(fontData.fMetrics)
, fName(fontData.fName)
, fPaths(nullptr) {
init(fontData.fPoints, fontData.fVerbs);
}
@ -59,11 +58,11 @@ SkGlyphID SkTestFont::glyphForUnichar(SkUnichar charCode) const {
}
void SkTestFont::init(const SkScalar* pts, const unsigned char* verbs) {
fPaths = new SkPath* [fCharCodesCount];
fPaths = new SkPath*[fCharCodesCount];
for (unsigned index = 0; index < fCharCodesCount; ++index) {
SkPath* path = new SkPath;
SkPath* path = new SkPath;
SkPath::Verb verb;
while ((verb = (SkPath::Verb) *verbs++) != SkPath::kDone_Verb) {
while ((verb = (SkPath::Verb)*verbs++) != SkPath::kDone_Verb) {
switch (verb) {
case SkPath::kMove_Verb:
path->moveTo(pts[0], pts[1]);
@ -81,12 +80,8 @@ void SkTestFont::init(const SkScalar* pts, const unsigned char* verbs) {
path->cubicTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
pts += 6;
break;
case SkPath::kClose_Verb:
path->close();
break;
default:
SkDEBUGFAIL("bad verb");
return;
case SkPath::kClose_Verb: path->close(); break;
default: SkDEBUGFAIL("bad verb"); return;
}
}
// This should make SkPath::getBounds() queries threadsafe.
@ -95,64 +90,62 @@ void SkTestFont::init(const SkScalar* pts, const unsigned char* verbs) {
}
}
SkTestTypeface::SkTestTypeface(sk_sp<SkTestFont> testFont, const SkFontStyle& style)
: SkTypeface(style, false)
, fTestFont(std::move(testFont)) {
}
TestTypeface::TestTypeface(sk_sp<SkTestFont> testFont, const SkFontStyle& style)
: SkTypeface(style, false), fTestFont(std::move(testFont)) {}
void SkTestTypeface::getAdvance(SkGlyph* glyph) {
void TestTypeface::getAdvance(SkGlyph* glyph) {
SkGlyphID glyphID = glyph->getGlyphID();
glyphID = glyphID < fTestFont->fCharCodesCount ? glyphID : 0;
glyphID = glyphID < fTestFont->fCharCodesCount ? glyphID : 0;
// TODO(benjaminwagner): Update users to use floats.
glyph->fAdvanceX = SkFixedToFloat(fTestFont->fWidths[glyphID]);
glyph->fAdvanceY = 0;
}
void SkTestTypeface::getFontMetrics(SkFontMetrics* metrics) {
*metrics = fTestFont->fMetrics;
}
void TestTypeface::getFontMetrics(SkFontMetrics* metrics) { *metrics = fTestFont->fMetrics; }
void SkTestTypeface::getPath(SkGlyphID glyphID, SkPath* path) {
void TestTypeface::getPath(SkGlyphID glyphID, SkPath* path) {
glyphID = glyphID < fTestFont->fCharCodesCount ? glyphID : 0;
*path = *fTestFont->fPaths[glyphID];
*path = *fTestFont->fPaths[glyphID];
}
void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const {
void TestTypeface::onFilterRec(SkScalerContextRec* rec) const {
rec->setHinting(kNo_SkFontHinting);
}
void SkTestTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const {
void TestTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const {
unsigned glyphCount = fTestFont->fCharCodesCount;
for (unsigned gid = 0; gid < glyphCount; ++gid) {
glyphToUnicode[gid] = SkTo<SkUnichar>(fTestFont->fCharCodes[gid]);
}
}
std::unique_ptr<SkAdvancedTypefaceMetrics> SkTestTypeface::onGetAdvancedMetrics() const { // pdf only
std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics);
std::unique_ptr<SkAdvancedTypefaceMetrics> TestTypeface::onGetAdvancedMetrics() const { // pdf only
std::unique_ptr<SkAdvancedTypefaceMetrics>info(new SkAdvancedTypefaceMetrics);
info->fFontName.set(fTestFont->fName);
return info;
}
void SkTestTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const {
void TestTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const {
desc->setFamilyName(fTestFont->fName);
desc->setStyle(this->fontStyle());
*isLocal = false;
}
int SkTestTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
SkGlyphID glyphs[], int glyphCount) const {
auto utf8 = (const char*)chars;
auto utf16 = (const uint16_t*)chars;
int TestTypeface::onCharsToGlyphs(const void* chars,
Encoding encoding,
SkGlyphID glyphs[],
int glyphCount) const {
auto utf8 = (const char*)chars;
auto utf16 = (const uint16_t*)chars;
auto utf32 = (const SkUnichar*)chars;
for (int i = 0; i < glyphCount; ++i) {
SkUnichar ch;
switch (encoding) {
case kUTF8_Encoding: ch = SkUTF8_NextUnichar(&utf8 ); break;
case kUTF8_Encoding: ch = SkUTF8_NextUnichar(&utf8); break;
case kUTF16_Encoding: ch = SkUTF16_NextUnichar(&utf16); break;
case kUTF32_Encoding: ch = *utf32++; break;
case kUTF32_Encoding: ch = *utf32++; break;
}
if (glyphs) {
glyphs[i] = fTestFont->glyphForUnichar(ch);
@ -161,47 +154,43 @@ int SkTestTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
return glyphCount;
}
void SkTestTypeface::onGetFamilyName(SkString* familyName) const {
*familyName = fTestFont->fName;
}
void TestTypeface::onGetFamilyName(SkString* familyName) const { *familyName = fTestFont->fName; }
SkTypeface::LocalizedStrings* SkTestTypeface::onCreateFamilyNameIterator() const {
SkTypeface::LocalizedStrings* TestTypeface::onCreateFamilyNameIterator() const {
SkString familyName(fTestFont->fName);
SkString language("und"); //undetermined
SkString language("und"); // undetermined
return new SkOTUtils::LocalizedStrings_SingleName(familyName, language);
}
class SkTestScalerContext : public SkScalerContext {
public:
SkTestScalerContext(sk_sp<SkTestTypeface> face, const SkScalerContextEffects& effects,
const SkDescriptor* desc)
: SkScalerContext(std::move(face), effects, desc)
{
SkTestScalerContext(sk_sp<TestTypeface> face,
const SkScalerContextEffects& effects,
const SkDescriptor* desc)
: SkScalerContext(std::move(face), effects, desc) {
fRec.getSingleMatrix(&fMatrix);
this->forceGenerateImageFromPath();
}
protected:
SkTestTypeface* getTestTypeface() const {
return static_cast<SkTestTypeface*>(this->getTypeface());
TestTypeface* getTestTypeface() const {
return static_cast<TestTypeface*>(this->getTypeface());
}
unsigned generateGlyphCount() override {
return this->getTestTypeface()->onCountGlyphs();
}
unsigned generateGlyphCount() override { return this->getTestTypeface()->onCountGlyphs(); }
uint16_t generateCharToGlyph(SkUnichar uni) override {
uint16_t glyph;
(void) this->getTestTypeface()->onCharsToGlyphs((const void *) &uni,
SkTypeface::kUTF32_Encoding, &glyph, 1);
(void)this->getTestTypeface()->onCharsToGlyphs(
(const void*)&uni, SkTypeface::kUTF32_Encoding, &glyph, 1);
return glyph;
}
bool generateAdvance(SkGlyph* glyph) override {
this->getTestTypeface()->getAdvance(glyph);
const SkVector advance = fMatrix.mapXY(SkFloatToScalar(glyph->fAdvanceX),
SkFloatToScalar(glyph->fAdvanceY));
const SkVector advance =
fMatrix.mapXY(SkFloatToScalar(glyph->fAdvanceX), SkFloatToScalar(glyph->fAdvanceY));
glyph->fAdvanceX = SkScalarToFloat(advance.fX);
glyph->fAdvanceY = SkScalarToFloat(advance.fY);
return true;
@ -213,9 +202,7 @@ protected:
// Always generates from paths, so SkScalerContext::getMetrics will figure the bounds.
}
void generateImage(const SkGlyph&) override {
SK_ABORT("Should have generated from path.");
}
void generateImage(const SkGlyph&) override { SK_ABORT("Should have generated from path."); }
bool generatePath(SkGlyphID glyph, SkPath* path) override {
this->getTestTypeface()->getPath(glyph, path);
@ -229,11 +216,10 @@ protected:
}
private:
SkMatrix fMatrix;
SkMatrix fMatrix;
};
SkScalerContext* SkTestTypeface::onCreateScalerContext(
const SkScalerContextEffects& effects, const SkDescriptor* desc) const
{
return new SkTestScalerContext(sk_ref_sp(const_cast<SkTestTypeface*>(this)), effects, desc);
SkScalerContext* TestTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const {
return new SkTestScalerContext(sk_ref_sp(const_cast<TestTypeface*>(this)), effects, desc);
}

View File

@ -5,8 +5,8 @@
* found in the LICENSE file.
*/
#ifndef SkTestTypeface_DEFINED
#define SkTestTypeface_DEFINED
#ifndef TestTypeface_DEFINED
#define TestTypeface_DEFINED
#include "SkFixed.h"
#include "SkFontArguments.h"
@ -33,50 +33,49 @@ struct SkScalerContextEffects;
struct SkScalerContextRec;
struct SkTestFontData {
const SkScalar* fPoints;
const SkScalar* fPoints;
const unsigned char* fVerbs;
const SkUnichar* fCharCodes;
const size_t fCharCodesCount;
const SkFixed* fWidths;
const SkUnichar* fCharCodes;
const size_t fCharCodesCount;
const SkFixed* fWidths;
const SkFontMetrics& fMetrics;
const char* fName;
SkFontStyle fStyle;
const char* fName;
SkFontStyle fStyle;
};
class SkTestFont : public SkRefCnt {
public:
SkTestFont(const SkTestFontData& );
SkTestFont(const SkTestFontData&);
virtual ~SkTestFont();
SkGlyphID glyphForUnichar(SkUnichar charCode) const;
void init(const SkScalar* pts, const unsigned char* verbs);
void init(const SkScalar* pts, const unsigned char* verbs);
private:
const SkUnichar* fCharCodes;
const size_t fCharCodesCount;
const SkFixed* fWidths;
const SkUnichar* fCharCodes;
const size_t fCharCodesCount;
const SkFixed* fWidths;
const SkFontMetrics& fMetrics;
const char* fName;
SkPath** fPaths;
friend class SkTestTypeface;
const char* fName;
SkPath** fPaths;
friend class TestTypeface;
typedef SkRefCnt INHERITED;
};
class SkTestTypeface : public SkTypeface {
class TestTypeface : public SkTypeface {
public:
SkTestTypeface(sk_sp<SkTestFont>, const SkFontStyle& style);
TestTypeface(sk_sp<SkTestFont>, const SkFontStyle& style);
void getAdvance(SkGlyph* glyph);
void getFontMetrics(SkFontMetrics* metrics);
void getPath(SkGlyphID glyph, SkPath* path);
protected:
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
void getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
void getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const override;
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override {
return nullptr;
}
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
return sk_ref_sp(this);
@ -84,40 +83,37 @@ protected:
void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override;
int onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) 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 onCountGlyphs() const override { return (int)fTestFont->fCharCodesCount; }
int onGetUPEM() const override {
return 2048;
}
int onGetUPEM() const override { return 2048; }
void onGetFamilyName(SkString* familyName) const override;
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
int coordinateCount) const override
{
int coordinateCount) const override {
return 0;
}
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
int parameterCount) const override
{
int parameterCount) const override {
return 0;
}
int onGetTableTags(SkFontTableTag tags[]) const override {
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;
}
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;

View File

@ -7,7 +7,7 @@
// Running create_test_font generates ./tools/fonts/test_font_index.inc
// and ./tools/fonts/test_font_<generic name>.inc which are read by
// ./tools/fonts/SkTestFontMgr.cpp
// ./tools/fonts/TestFontMgr.cpp
#include "SkFont.h"
#include "SkFontMetrics.h"

View File

@ -12,11 +12,12 @@
#include "SkRefCnt.h"
#include "SkStream.h"
#include "SkString.h"
#include "SkTestSVGTypeface.h"
#include "TestSVGTypeface.h"
static void export_ttx(sk_sp<SkTestSVGTypeface> typeface, SkString prefix,
SkSpan<unsigned> cbdtStrikeSizes, SkSpan<unsigned> sbixStrikeSizes)
{
static void export_ttx(sk_sp<TestSVGTypeface> typeface,
SkString prefix,
SkSpan<unsigned> cbdtStrikeSizes,
SkSpan<unsigned> sbixStrikeSizes) {
SkFILEWStream cbdt((SkString(prefix) += "cbdt.ttx").c_str());
typeface->exportTtxCbdt(&cbdt, cbdtStrikeSizes);
cbdt.flush();
@ -42,8 +43,8 @@ int main(int argc, char** argv) {
// But the planet font cannot get very big in the size limited cbdt format.
unsigned small[] = { 8, 16 };
export_ttx(SkTestSVGTypeface::Default(), SkString( ), usual, usual);
export_ttx(SkTestSVGTypeface::Planets(), SkString("planet"), small, usual);
export_ttx(TestSVGTypeface::Default(), SkString(), usual, usual);
export_ttx(TestSVGTypeface::Planets(), SkString("planet"), small, usual);
return 0;
}

View File

@ -13,9 +13,9 @@
#include "SkFontStyle.h"
#include "SkMutex.h"
#include "SkOSFile.h"
#include "SkTestFontMgr.h"
#include "SkTypeface.h"
#include "SkUTF.h"
#include "TestFontMgr.h"
namespace sk_tool_utils {

View File

@ -8,7 +8,7 @@
#include "skqp.h"
#include "../../../src/core/SkStreamPriv.h"
#include "../../tools/fonts/SkTestFontMgr.h"
#include "../../tools/fonts/TestFontMgr.h"
#include "GrContext.h"
#include "GrContextOptions.h"
#include "GrContextPriv.h"

View File

@ -34,10 +34,10 @@
#include "SkStream.h"
#include "SkSurface.h"
#include "SkTaskGroup.h"
#include "SkTestFontMgr.h"
#include "SkTo.h"
#include "SlideDir.h"
#include "SvgSlide.h"
#include "TestFontMgr.h"
#include "ccpr/GrCoverageCountingPathRenderer.h"
#include <stdlib.h>