2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-06-21 15:11:40 +00:00
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2015-07-28 17:37:53 +00:00
|
|
|
#include "Resources.h"
|
2019-01-22 20:17:59 +00:00
|
|
|
#include "SkFontMetrics.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2018-10-25 20:12:39 +00:00
|
|
|
#include "SkTextUtils.h"
|
2015-07-28 17:37:53 +00:00
|
|
|
#include "SkTypeface.h"
|
2011-02-17 14:21:01 +00:00
|
|
|
|
2013-06-21 15:11:40 +00:00
|
|
|
class Poly2PolyGM : public skiagm::GM {
|
2011-02-17 14:21:01 +00:00
|
|
|
public:
|
2012-08-23 18:14:13 +00:00
|
|
|
Poly2PolyGM() {}
|
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2011-02-17 14:21:01 +00:00
|
|
|
return SkString("poly2poly");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2013-06-21 15:11:40 +00:00
|
|
|
return SkISize::Make(835, 840);
|
2011-02-17 14:21:01 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2018-12-24 04:19:14 +00:00
|
|
|
static void doDraw(SkCanvas* canvas, const SkFont& font, SkPaint* paint, const int isrc[],
|
2011-02-17 14:21:01 +00:00
|
|
|
const int idst[], int count) {
|
|
|
|
SkMatrix matrix;
|
|
|
|
SkPoint src[4], dst[4];
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
src[i].set(SkIntToScalar(isrc[2*i+0]), SkIntToScalar(isrc[2*i+1]));
|
|
|
|
dst[i].set(SkIntToScalar(idst[2*i+0]), SkIntToScalar(idst[2*i+1]));
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->save();
|
|
|
|
matrix.setPolyToPoly(src, dst, count);
|
|
|
|
canvas->concat(matrix);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2018-08-16 14:17:03 +00:00
|
|
|
paint->setColor(SK_ColorGRAY);
|
2011-02-17 14:21:01 +00:00
|
|
|
paint->setStyle(SkPaint::kStroke_Style);
|
2017-02-22 18:21:42 +00:00
|
|
|
const SkScalar D = 64;
|
|
|
|
canvas->drawRect(SkRect::MakeWH(D, D), *paint);
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->drawLine(0, 0, D, D, *paint);
|
|
|
|
canvas->drawLine(0, D, D, 0, *paint);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2018-11-12 14:35:15 +00:00
|
|
|
SkFontMetrics fm;
|
2018-12-24 04:19:14 +00:00
|
|
|
font.getMetrics(&fm);
|
2011-02-17 14:21:01 +00:00
|
|
|
paint->setColor(SK_ColorRED);
|
|
|
|
paint->setStyle(SkPaint::kFill_Style);
|
|
|
|
SkScalar x = D/2;
|
2011-10-27 21:47:03 +00:00
|
|
|
SkScalar y = D/2 - (fm.fAscent + fm.fDescent)/2;
|
2015-07-28 17:37:53 +00:00
|
|
|
uint16_t glyphID = 3; // X
|
2018-12-24 04:19:14 +00:00
|
|
|
SkTextUtils::Draw(canvas, &glyphID, sizeof(glyphID), kGlyphID_SkTextEncoding, x, y,
|
|
|
|
font, *paint, SkTextUtils::kCenter_Align);
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2015-07-28 17:37:53 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2017-12-08 19:25:14 +00:00
|
|
|
fEmFace = MakeResourceAsTypeface("fonts/Em.ttf");
|
2015-07-28 17:37:53 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2011-02-17 14:21:01 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(4));
|
2018-12-24 04:19:14 +00:00
|
|
|
SkFont font(fEmFace, 40);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
// translate (1 point)
|
|
|
|
const int src1[] = { 0, 0 };
|
|
|
|
const int dst1[] = { 5, 5 };
|
2018-12-24 04:19:14 +00:00
|
|
|
doDraw(canvas, font, &paint, src1, dst1, 1);
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->restore();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(160), SkIntToScalar(10));
|
|
|
|
// rotate/uniform-scale (2 points)
|
|
|
|
const int src2[] = { 32, 32, 64, 32 };
|
|
|
|
const int dst2[] = { 32, 32, 64, 48 };
|
2018-12-24 04:19:14 +00:00
|
|
|
doDraw(canvas, font, &paint, src2, dst2, 2);
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->restore();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(110));
|
|
|
|
// rotate/skew (3 points)
|
|
|
|
const int src3[] = { 0, 0, 64, 0, 0, 64 };
|
|
|
|
const int dst3[] = { 0, 0, 96, 0, 24, 64 };
|
2018-12-24 04:19:14 +00:00
|
|
|
doDraw(canvas, font, &paint, src3, dst3, 3);
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->restore();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(160), SkIntToScalar(110));
|
|
|
|
// perspective (4 points)
|
|
|
|
const int src4[] = { 0, 0, 64, 0, 64, 64, 0, 64 };
|
|
|
|
const int dst4[] = { 0, 0, 96, 0, 64, 96, 0, 64 };
|
2018-12-24 04:19:14 +00:00
|
|
|
doDraw(canvas, font, &paint, src4, dst4, 4);
|
2011-02-17 14:21:01 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-02-17 14:21:01 +00:00
|
|
|
private:
|
2013-06-21 15:11:40 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> fEmFace;
|
2011-02-17 14:21:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-06-21 15:11:40 +00:00
|
|
|
DEF_GM( return new Poly2PolyGM; )
|