Delete SkGTypeface and SkGScalerContext

Bug: skia:
Change-Id: I6a513d0cb3600678bc3b9c2bdfa8e04d692e9acf
Reviewed-on: https://skia-review.googlesource.com/14191
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
This commit is contained in:
Matt Sarett 2017-04-25 11:09:16 -04:00 committed by Skia Commit-Bot
parent 20b82524e7
commit ee7cb5d974
7 changed files with 19 additions and 384 deletions

View File

@ -9,17 +9,17 @@
#include "SkBitmap.h"
#include "SkGradientShader.h"
#include "SkShader.h"
#include "../src/fonts/SkGScalerContext.h"
#include "SkUtils.h"
namespace skiagm {
static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
class ColorTypeXfermodeGM : public GM {
class ColorEmojiBlendModesGM : public GM {
public:
const static int W = 64;
const static int H = 64;
ColorTypeXfermodeGM() {}
ColorEmojiBlendModesGM() {}
protected:
void onOnceBeforeDraw() override {
@ -39,14 +39,16 @@ protected:
if (nullptr == orig) {
orig = SkTypeface::MakeDefault();
}
fColorType = sk_make_sp<SkGTypeface>(orig, paint);
fColorType = sk_tool_utils::emoji_typeface();
fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
kOpaque_SkAlphaType), gData, 4);
}
virtual SkString onShortName() override {
return SkString("colortype_xfermodes");
SkString name("coloremoji_blendmodes");
name.append(sk_tool_utils::platform_os_emoji());
return name;
}
virtual SkISize onISize() override {
@ -125,12 +127,18 @@ protected:
p.setShader(nullptr);
canvas->drawRect(r, p);
textP.setBlendMode(gModes[i]);
canvas->drawText("H", 1, x+ w/10.f, y + 7.f*h/8.f, textP);
{
SkAutoCanvasRestore arc(canvas, true);
canvas->clipRect(r);
textP.setBlendMode(gModes[i]);
textP.setTextEncoding(SkPaint::kUTF32_TextEncoding);
const char* text = sk_tool_utils::emoji_sample_text();
SkUnichar unichar = SkUTF8_ToUnichar(text);
canvas->drawText(&unichar, 4, x+ w/10.f, y + 7.f*h/8.f, textP);
}
#if 1
const char* label = SkBlendMode_Name(gModes[i]);
canvas->drawText(label, strlen(label),
x + w/2, y - labelP.getTextSize()/2, labelP);
canvas->drawText(label, strlen(label), x + w/2, y - labelP.getTextSize()/2, labelP);
#endif
x += w + SkIntToScalar(10);
if ((i % W) == W - 1) {
@ -149,7 +157,7 @@ private:
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new ColorTypeXfermodeGM; }
static GM* MyFactory(void*) { return new ColorEmojiBlendModesGM; }
static GMRegistry reg(MyFactory);
}

View File

@ -1,65 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "sk_tool_utils.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "../src/fonts/SkGScalerContext.h"
class ColorTypeGM : public skiagm::GM {
public:
ColorTypeGM() {}
protected:
void onOnceBeforeDraw() override {
const SkColor colors[] = {
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW
};
SkMatrix local;
local.setRotate(180);
SkPaint paint;
paint.setAntiAlias(true);
paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
0, &local));
sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface(
"serif", SkFontStyle::FromOldStyle(SkTypeface::kBold)));
if (nullptr == orig) {
orig = SkTypeface::MakeDefault();
}
fColorType = sk_make_sp<SkGTypeface>(std::move(orig), paint);
}
SkString onShortName() override {
return SkString("colortype");
}
SkISize onISize() override {
return SkISize::Make(640, 480);
}
void onDraw(SkCanvas* canvas) override {
SkPaint paint;
paint.setAntiAlias(true);
paint.setTypeface(fColorType);
for (SkScalar size = 10; size <= 100; size += 10) {
paint.setTextSize(size);
canvas->translate(0, paint.getFontMetrics(nullptr));
canvas->drawText("Hamburgefons", 12, 10, 10, paint);
}
}
private:
sk_sp<SkTypeface> fColorType;
typedef skiagm::GM INHERITED;
};
DEF_GM(return new ColorTypeGM;)

View File

@ -61,13 +61,12 @@ gm_sources = [
"$_gm/clippedbitmapshaders.cpp",
"$_gm/color4f.cpp",
"$_gm/coloremoji.cpp",
"$_gm/coloremoji_blendmodes.cpp",
"$_gm/colorfilteralpha8.cpp",
"$_gm/colorfilterimagefilter.cpp",
"$_gm/colorfilters.cpp",
"$_gm/colormatrix.cpp",
"$_gm/colorspacexform.cpp",
"$_gm/colortype.cpp",
"$_gm/colortypexfermode.cpp",
"$_gm/colorwheel.cpp",
"$_gm/complexclip.cpp",
"$_gm/complexclip_blur_tiled.cpp",

View File

@ -95,8 +95,6 @@ skia_utils_sources = [
"$_src/utils/win/SkWGL_win.cpp",
#testing
"$_src/fonts/SkGScalerContext.cpp",
"$_src/fonts/SkGScalerContext.h",
"$_src/fonts/SkRandomScalerContext.cpp",
"$_src/fonts/SkRandomScalerContext.h",
"$_src/fonts/SkTestScalerContext.cpp",

View File

@ -385,7 +385,6 @@ protected:
virtual bool onComputeBounds(SkRect*) const;
private:
friend class SkGTypeface;
friend class SkRandomTypeface;
friend class SkPDFFont;
friend class GrPathRendering;

View File

@ -1,253 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkCanvas.h"
#include "SkDescriptor.h"
#include "SkGScalerContext.h"
#include "SkGlyph.h"
#include "SkPaintPriv.h"
#include "SkPath.h"
#include "SkMakeUnique.h"
#define STD_SIZE 1
class SkGScalerContext : public SkScalerContext {
public:
SkGScalerContext(sk_sp<SkGTypeface> face, const SkScalerContextEffects& effects,
const SkDescriptor* desc)
: SkScalerContext(std::move(face), effects, desc)
{
size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext::Rec);
SkAutoDescriptor ad(descSize);
SkDescriptor* newDesc = ad.getDesc();
newDesc->init();
void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
sizeof(SkScalerContext::Rec), &fRec);
{
SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
rec->fTextSize = STD_SIZE;
rec->fPreScaleX = SK_Scalar1;
rec->fPreSkewX = 0;
rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
}
SkASSERT(descSize == newDesc->getLength());
newDesc->computeChecksum();
fProxy = this->getGTypeface()->proxy()->createScalerContext(effects, newDesc);
fRec.getSingleMatrix(&fMatrix);
fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
}
protected:
SkGTypeface* getGTypeface() { return static_cast<SkGTypeface*>(this->getTypeface()); }
unsigned generateGlyphCount() override;
uint16_t generateCharToGlyph(SkUnichar) override;
void generateAdvance(SkGlyph*) override;
void generateMetrics(SkGlyph*) override;
void generateImage(const SkGlyph&) override;
void generatePath(SkGlyphID, SkPath*) override;
void generateFontMetrics(SkPaint::FontMetrics*) override;
private:
std::unique_ptr<SkScalerContext> fProxy;
SkMatrix fMatrix;
};
unsigned SkGScalerContext::generateGlyphCount() {
return fProxy->getGlyphCount();
}
uint16_t SkGScalerContext::generateCharToGlyph(SkUnichar uni) {
return fProxy->charToGlyphID(uni);
}
void SkGScalerContext::generateAdvance(SkGlyph* glyph) {
fProxy->getAdvance(glyph);
SkVector advance;
fMatrix.mapXY(SkFloatToScalar(glyph->fAdvanceX),
SkFloatToScalar(glyph->fAdvanceY), &advance);
glyph->fAdvanceX = SkScalarToFloat(advance.fX);
glyph->fAdvanceY = SkScalarToFloat(advance.fY);
}
void SkGScalerContext::generateMetrics(SkGlyph* glyph) {
fProxy->getMetrics(glyph);
SkVector advance;
fMatrix.mapXY(SkFloatToScalar(glyph->fAdvanceX),
SkFloatToScalar(glyph->fAdvanceY), &advance);
glyph->fAdvanceX = SkScalarToFloat(advance.fX);
glyph->fAdvanceY = SkScalarToFloat(advance.fY);
SkPath path;
fProxy->getPath(glyph->getPackedID(), &path);
path.transform(fMatrix);
SkRect storage;
const SkPaint& paint = this->getGTypeface()->paint();
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->fHeight = ibounds.height();
glyph->fMaskFormat = SkMask::kARGB32_Format;
}
void SkGScalerContext::generateImage(const SkGlyph& glyph) {
if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
SkPath path;
fProxy->getPath(glyph.getPackedID(), &path);
SkBitmap bm;
bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight),
glyph.fImage, glyph.rowBytes());
bm.eraseColor(0);
SkCanvas canvas(bm);
canvas.translate(-SkIntToScalar(glyph.fLeft),
-SkIntToScalar(glyph.fTop));
canvas.concat(fMatrix);
canvas.drawPath(path, this->getGTypeface()->paint());
} else {
fProxy->getImage(glyph);
}
}
void SkGScalerContext::generatePath(SkGlyphID glyph, SkPath* path) {
fProxy->getPath(SkPackedGlyphID(glyph), path);
path->transform(fMatrix);
}
void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
fProxy->getFontMetrics(metrics);
SkPaintPriv::ScaleFontMetrics(metrics, fMatrix.getScaleY());
}
///////////////////////////////////////////////////////////////////////////////
#include "SkTypefaceCache.h"
SkGTypeface::SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint)
: SkTypeface(proxy->fontStyle(), false)
, fProxy(std::move(proxy))
, fPaint(paint)
{}
SkScalerContext* SkGTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const {
return new SkGScalerContext(sk_ref_sp(const_cast<SkGTypeface*>(this)), effects, desc);
}
void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const {
fProxy->filterRec(rec);
rec->setHinting(SkPaint::kNo_Hinting);
rec->fMaskFormat = SkMask::kARGB32_Format;
}
SkAdvancedTypefaceMetrics* SkGTypeface::onGetAdvancedTypefaceMetrics(
PerGlyphInfo info,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
}
SkStreamAsset* SkGTypeface::onOpenStream(int* ttcIndex) const {
return fProxy->openStream(ttcIndex);
}
void SkGTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
bool* isLocal) const {
fProxy->getFontDescriptor(desc, isLocal);
}
int SkGTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const {
return fProxy->charsToGlyphs(chars, encoding, glyphs, glyphCount);
}
int SkGTypeface::onCountGlyphs() const {
return fProxy->countGlyphs();
}
int SkGTypeface::onGetUPEM() const {
return fProxy->getUnitsPerEm();
}
void SkGTypeface::onGetFamilyName(SkString* familyName) const {
fProxy->getFamilyName(familyName);
}
SkTypeface::LocalizedStrings* SkGTypeface::onCreateFamilyNameIterator() const {
return fProxy->createFamilyNameIterator();
}
int SkGTypeface::onGetVariationDesignPosition(
SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const
{
return fProxy->onGetVariationDesignPosition(coordinates, coordinateCount);
}
int SkGTypeface::onGetTableTags(SkFontTableTag tags[]) const {
return fProxy->getTableTags(tags);
}
size_t SkGTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
size_t length, void* data) const {
return fProxy->getTableData(tag, offset, length, data);
}
///////////////////////////////////////////////////////////////////////////////
#if 0
// under construction -- defining a font purely in terms of skia primitives
// ala an SVG-font.
class SkGFont : public SkRefCnt {
public:
virtual ~SkGFont();
int unicharToGlyph(SkUnichar) const;
int countGlyphs() const { return fCount; }
float getAdvance(int index) const {
SkASSERT((unsigned)index < (unsigned)fCount);
return fGlyphs[index].fAdvance;
}
const SkPath& getPath(int index) const {
SkASSERT((unsigned)index < (unsigned)fCount);
return fGlyphs[index].fPath;
}
private:
struct Glyph {
SkUnichar fUni;
float fAdvance;
SkPath fPath;
};
int fCount;
Glyph* fGlyphs;
friend class SkGFontBuilder;
SkGFont(int count, Glyph* array);
};
class SkGFontBuilder {
public:
};
#endif

View File

@ -1,51 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkGScalerContext_DEFINED
#define SkGScalerContext_DEFINED
#include "SkScalerContext.h"
#include "SkTypeface.h"
class SkGTypeface : public SkTypeface {
public:
SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint&);
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;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const override;
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) 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;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
int coordinateCount) const override;
int onGetTableTags(SkFontTableTag tags[]) const override;
size_t onGetTableData(SkFontTableTag, size_t offset,
size_t length, void* data) const override;
private:
sk_sp<SkTypeface> fProxy;
SkPaint fPaint;
};
#endif