blob: 5f943df6ce2caf89277afe6cfef0bf8c1150d2d8 [file] [log] [blame]
reed@google.com63d73742012-01-10 15:33:12 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkPath.h"
11#include "SkTypeface.h"
12
reed@google.com63d73742012-01-10 15:33:12 +000013namespace skiagm {
14
15class StrokeFillGM : public GM {
16public:
17 StrokeFillGM() {
18
19 }
20
21protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000022 virtual uint32_t onGetFlags() const SK_OVERRIDE {
23 return kSkipTiled_Flag;
24 }
25
reed@google.com63d73742012-01-10 15:33:12 +000026 virtual SkString onShortName() {
27 return SkString("stroke-fill");
28 }
29
30 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070031 return SkISize::Make(640, 480);
reed@google.com63d73742012-01-10 15:33:12 +000032 }
33
bungeman@google.comf8aa18c2012-03-19 21:04:52 +000034 static void show_bold(SkCanvas* canvas, const void* text, int len,
35 SkScalar x, SkScalar y, const SkPaint& paint) {
reed@google.com188bfcf2012-01-17 18:26:38 +000036 SkPaint p(paint);
37 canvas->drawText(text, len, x, y, p);
38 p.setFakeBoldText(true);
39 canvas->drawText(text, len, x, y + SkIntToScalar(120), p);
40 }
41
reed@google.com63d73742012-01-10 15:33:12 +000042 virtual void onDraw(SkCanvas* canvas) {
reed@google.com188bfcf2012-01-17 18:26:38 +000043 SkScalar x = SkIntToScalar(100);
44 SkScalar y = SkIntToScalar(88);
45
reed@google.comd1ab9322012-01-10 18:40:03 +000046 SkPaint paint;
reed@google.comd1ab9322012-01-10 18:40:03 +000047 paint.setAntiAlias(true);
48 paint.setTextSize(SkIntToScalar(100));
reed@google.comb435bd72012-01-10 19:28:01 +000049 paint.setStrokeWidth(SkIntToScalar(5));
rmistry@google.comae933ce2012-08-23 18:19:56 +000050
reed@google.com188bfcf2012-01-17 18:26:38 +000051 SkTypeface* face = SkTypeface::CreateFromName("Papyrus", SkTypeface::kNormal);
52 SkSafeUnref(paint.setTypeface(face));
bungeman@google.comf8aa18c2012-03-19 21:04:52 +000053 show_bold(canvas, "Hello", 5, x, y, paint);
reed@google.com188bfcf2012-01-17 18:26:38 +000054
55 face = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
56 SkSafeUnref(paint.setTypeface(face));
bungeman@google.comf8aa18c2012-03-19 21:04:52 +000057 const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC };
58 show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300), y, paint);
reed@google.com188bfcf2012-01-17 18:26:38 +000059
60 paint.setStyle(SkPaint::kStrokeAndFill_Style);
61
reed@google.comd1ab9322012-01-10 18:40:03 +000062 SkPath path;
63 path.setFillType(SkPath::kWinding_FillType);
reed@google.comb435bd72012-01-10 19:28:01 +000064 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
65 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000066 canvas->drawPath(path, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000067
reed@google.comd1ab9322012-01-10 18:40:03 +000068 SkPath path2;
69 path2.setFillType(SkPath::kWinding_FillType);
reed@google.comb435bd72012-01-10 19:28:01 +000070 path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
71 path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000072 canvas->drawPath(path2, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000073
reed@google.comd1ab9322012-01-10 18:40:03 +000074 path2.reset();
reed@google.comb435bd72012-01-10 19:28:01 +000075 path2.addCircle(x + SkIntToScalar(240), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000076 canvas->drawPath(path2, paint);
77 SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction));
rmistry@google.comae933ce2012-08-23 18:19:56 +000078
reed@google.comd1ab9322012-01-10 18:40:03 +000079 path2.reset();
80 SkASSERT(!path2.cheapComputeDirection(NULL));
reed@google.comb435bd72012-01-10 19:28:01 +000081 path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000082 SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction));
83 canvas->drawPath(path2, paint);
reed@google.com63d73742012-01-10 15:33:12 +000084 }
85
86private:
87 typedef GM INHERITED;
88};
89
90//////////////////////////////////////////////////////////////////////////////
91
92static GM* MyFactory(void*) { return new StrokeFillGM; }
93static GMRegistry reg(MyFactory);
94
95}