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"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class StrokeFillGM : public GM {
|
|
|
|
public:
|
|
|
|
StrokeFillGM() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
return kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
2012-01-10 15:33:12 +00:00
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("stroke-fill");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() {
|
|
|
|
return make_isize(640, 480);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-10 15:33:12 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
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
|
|
|
|
2012-01-17 18:26:38 +00:00
|
|
|
SkTypeface* face = SkTypeface::CreateFromName("Papyrus", SkTypeface::kNormal);
|
|
|
|
SkSafeUnref(paint.setTypeface(face));
|
2012-03-19 21:04:52 +00:00
|
|
|
show_bold(canvas, "Hello", 5, x, y, paint);
|
2012-01-17 18:26:38 +00:00
|
|
|
|
|
|
|
face = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
|
|
|
|
SkSafeUnref(paint.setTypeface(face));
|
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);
|
|
|
|
SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-01-10 18:40:03 +00:00
|
|
|
path2.reset();
|
|
|
|
SkASSERT(!path2.cheapComputeDirection(NULL));
|
2012-01-10 19:28:01 +00:00
|
|
|
path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
|
2012-01-10 18:40:03 +00:00
|
|
|
SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction));
|
|
|
|
canvas->drawPath(path2, paint);
|
2012-01-10 15:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new StrokeFillGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|