2012-01-10 15:33:12 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
2015-06-10 21:23:15 +00:00
|
|
|
#include "SkPathPriv.h"
|
2012-01-10 15:33:12 +00:00
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class StrokeFillGM : public GM {
|
|
|
|
public:
|
|
|
|
StrokeFillGM() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2012-01-10 15:33:12 +00:00
|
|
|
return SkString("stroke-fill");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(640, 480);
|
2012-01-10 15:33:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:04:52 +00:00
|
|
|
static void show_bold(SkCanvas* canvas, const void* text, int len,
|
|
|
|
SkScalar x, SkScalar y, const SkPaint& paint) {
|
2012-01-17 18:26:38 +00:00
|
|
|
SkPaint p(paint);
|
|
|
|
canvas->drawText(text, len, x, y, p);
|
|
|
|
p.setFakeBoldText(true);
|
|
|
|
canvas->drawText(text, len, x, y + SkIntToScalar(120), p);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-01-17 18:26:38 +00:00
|
|
|
SkScalar x = SkIntToScalar(100);
|
|
|
|
SkScalar y = SkIntToScalar(88);
|
|
|
|
|
2012-01-10 18:40:03 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setTextSize(SkIntToScalar(100));
|
2012-01-10 19:28:01 +00:00
|
|
|
paint.setStrokeWidth(SkIntToScalar(5));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint, "Papyrus");
|
2012-03-19 21:04:52 +00:00
|
|
|
show_bold(canvas, "Hello", 5, x, y, paint);
|
2012-01-17 18:26:38 +00:00
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
|
2012-03-19 21:04:52 +00:00
|
|
|
const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC };
|
|
|
|
show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300), y, paint);
|
2012-01-17 18:26:38 +00:00
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
|
2012-01-10 18:40:03 +00:00
|
|
|
SkPath path;
|
|
|
|
path.setFillType(SkPath::kWinding_FillType);
|
2012-01-10 19:28:01 +00:00
|
|
|
path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
|
|
|
|
path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction);
|
2012-01-10 18:40:03 +00:00
|
|
|
canvas->drawPath(path, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-01-10 18:40:03 +00:00
|
|
|
SkPath path2;
|
|
|
|
path2.setFillType(SkPath::kWinding_FillType);
|
2012-01-10 19:28:01 +00:00
|
|
|
path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
|
|
|
|
path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCW_Direction);
|
2012-01-10 18:40:03 +00:00
|
|
|
canvas->drawPath(path2, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-01-10 18:40:03 +00:00
|
|
|
path2.reset();
|
2012-01-10 19:28:01 +00:00
|
|
|
path2.addCircle(x + SkIntToScalar(240), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
|
2012-01-10 18:40:03 +00:00
|
|
|
canvas->drawPath(path2, paint);
|
2015-06-10 21:23:15 +00:00
|
|
|
SkASSERT(SkPathPriv::CheapIsFirstDirection(path2, SkPathPriv::kCCW_FirstDirection));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-01-10 18:40:03 +00:00
|
|
|
path2.reset();
|
2015-06-10 21:23:15 +00:00
|
|
|
SkASSERT(!SkPathPriv::CheapComputeFirstDirection(path2, NULL));
|
2012-01-10 19:28:01 +00:00
|
|
|
path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
|
2015-06-10 21:23:15 +00:00
|
|
|
SkASSERT(SkPathPriv::CheapIsFirstDirection(path2, SkPathPriv::kCW_FirstDirection));
|
2012-01-10 18:40:03 +00:00
|
|
|
canvas->drawPath(path2, paint);
|
2014-12-29 22:06:51 +00:00
|
|
|
|
|
|
|
SkRect r = SkRect::MakeXYWH(x - SkIntToScalar(50), y + SkIntToScalar(280),
|
|
|
|
SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
SkPath path3;
|
|
|
|
path3.setFillType(SkPath::kWinding_FillType);
|
|
|
|
path3.addRect(r, SkPath::kCW_Direction);
|
|
|
|
r.inset(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
path3.addRect(r, SkPath::kCCW_Direction);
|
|
|
|
canvas->drawPath(path3, paint);
|
|
|
|
|
|
|
|
r = SkRect::MakeXYWH(x + SkIntToScalar(70), y + SkIntToScalar(280),
|
|
|
|
SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
SkPath path4;
|
|
|
|
path4.setFillType(SkPath::kWinding_FillType);
|
|
|
|
path4.addRect(r, SkPath::kCCW_Direction);
|
|
|
|
r.inset(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
path4.addRect(r, SkPath::kCW_Direction);
|
|
|
|
canvas->drawPath(path4, paint);
|
|
|
|
|
|
|
|
r = SkRect::MakeXYWH(x + SkIntToScalar(190), y + SkIntToScalar(280),
|
|
|
|
SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
path4.reset();
|
2015-06-10 21:23:15 +00:00
|
|
|
SkASSERT(!SkPathPriv::CheapComputeFirstDirection(path4, NULL));
|
2014-12-29 22:06:51 +00:00
|
|
|
path4.addRect(r, SkPath::kCCW_Direction);
|
2015-06-10 21:23:15 +00:00
|
|
|
SkASSERT(SkPathPriv::CheapIsFirstDirection(path4, SkPathPriv::kCCW_FirstDirection));
|
2014-12-29 22:06:51 +00:00
|
|
|
path4.moveTo(0, 0); // test for crbug.com/247770
|
|
|
|
canvas->drawPath(path4, paint);
|
|
|
|
|
|
|
|
r = SkRect::MakeXYWH(x + SkIntToScalar(310), y + SkIntToScalar(280),
|
|
|
|
SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
path4.reset();
|
2015-06-10 21:23:15 +00:00
|
|
|
SkASSERT(!SkPathPriv::CheapComputeFirstDirection(path4, NULL));
|
2014-12-29 22:06:51 +00:00
|
|
|
path4.addRect(r, SkPath::kCW_Direction);
|
2015-06-10 21:23:15 +00:00
|
|
|
SkASSERT(SkPathPriv::CheapIsFirstDirection(path4, SkPathPriv::kCW_FirstDirection));
|
2014-12-29 22:06:51 +00:00
|
|
|
path4.moveTo(0, 0); // test for crbug.com/247770
|
|
|
|
canvas->drawPath(path4, paint);
|
2012-01-10 15:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-29 22:06:51 +00:00
|
|
|
DEF_GM(return SkNEW(StrokeFillGM);)
|
2012-01-10 15:33:12 +00:00
|
|
|
|
|
|
|
}
|