2015-05-20 16:21:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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 "Resources.h"
|
|
|
|
#include "SkFixed.h"
|
|
|
|
#include "SkFontDescriptor.h"
|
|
|
|
#include "SkFontMgr.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class FontScalerDistortableGM : public GM {
|
|
|
|
public:
|
|
|
|
FontScalerDistortableGM() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("fontscalerdistortable");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(550, 700);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setLCDRenderText(true);
|
2016-11-04 20:26:16 +00:00
|
|
|
sk_sp<SkFontMgr> fontMgr(SkFontMgr::RefDefault());
|
2015-05-20 16:21:04 +00:00
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Distortable.ttf"));
|
2015-05-20 16:21:04 +00:00
|
|
|
if (!distortable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const char* text = "abc";
|
|
|
|
const size_t textLen = strlen(text);
|
|
|
|
|
|
|
|
for (int j = 0; j < 2; ++j) {
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
SkScalar x = SkIntToScalar(10);
|
|
|
|
SkScalar y = SkIntToScalar(20);
|
|
|
|
|
2016-01-21 22:17:47 +00:00
|
|
|
SkFourByteTag tag = SkSetFourByteTag('w','g','h','t');
|
|
|
|
SkScalar styleValue = SkDoubleToScalar(0.5 + (5*j + i) * ((2.0 - 0.5) / (2 * 5)));
|
2017-02-24 16:15:26 +00:00
|
|
|
SkFontArguments::VariationPosition::Coordinate coordinates[] = {{tag, styleValue}};
|
|
|
|
SkFontArguments::VariationPosition position =
|
|
|
|
{ coordinates, SK_ARRAY_COUNT(coordinates) };
|
2016-05-12 17:09:30 +00:00
|
|
|
paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream(
|
2017-02-24 16:15:26 +00:00
|
|
|
distortable->duplicate(),
|
|
|
|
SkFontArguments().setVariationDesignPosition(position))));
|
2015-05-20 16:21:04 +00:00
|
|
|
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->translate(SkIntToScalar(30 + i * 100), SkIntToScalar(20));
|
2016-07-12 22:01:19 +00:00
|
|
|
canvas->rotate(SkIntToScalar(i * 5), x, y * 10);
|
2015-05-20 16:21:04 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
SkRect r;
|
|
|
|
r.set(x - SkIntToScalar(3), SkIntToScalar(15),
|
|
|
|
x - SkIntToScalar(1), SkIntToScalar(280));
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int ps = 6; ps <= 22; ps++) {
|
|
|
|
paint.setTextSize(SkIntToScalar(ps));
|
|
|
|
canvas->drawText(text, textLen, x, y, paint);
|
2015-08-27 14:41:13 +00:00
|
|
|
y += paint.getFontMetrics(nullptr);
|
2015-05-20 16:21:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->translate(0, SkIntToScalar(360));
|
|
|
|
paint.setSubpixelText(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new FontScalerDistortableGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|