blob: 4a29100e626d2dc01089522b51ee191211513707 [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
tfarina752e7eb2014-12-20 06:53:43 -080026 virtual SkString onShortName() SK_OVERRIDE {
reed@google.com63d73742012-01-10 15:33:12 +000027 return SkString("stroke-fill");
28 }
29
tfarina752e7eb2014-12-20 06:53:43 -080030 virtual SkISize onISize() SK_OVERRIDE {
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
tfarina752e7eb2014-12-20 06:53:43 -080042 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
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
Cary Clark992c7b02014-07-31 08:58:44 -040051 sk_tool_utils::set_portable_typeface(&paint, "Papyrus");
bungeman@google.comf8aa18c2012-03-19 21:04:52 +000052 show_bold(canvas, "Hello", 5, x, y, paint);
reed@google.com188bfcf2012-01-17 18:26:38 +000053
Cary Clark992c7b02014-07-31 08:58:44 -040054 sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
bungeman@google.comf8aa18c2012-03-19 21:04:52 +000055 const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC };
56 show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300), y, paint);
reed@google.com188bfcf2012-01-17 18:26:38 +000057
58 paint.setStyle(SkPaint::kStrokeAndFill_Style);
59
reed@google.comd1ab9322012-01-10 18:40:03 +000060 SkPath path;
61 path.setFillType(SkPath::kWinding_FillType);
reed@google.comb435bd72012-01-10 19:28:01 +000062 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
63 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000064 canvas->drawPath(path, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000065
reed@google.comd1ab9322012-01-10 18:40:03 +000066 SkPath path2;
67 path2.setFillType(SkPath::kWinding_FillType);
reed@google.comb435bd72012-01-10 19:28:01 +000068 path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
69 path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000070 canvas->drawPath(path2, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000071
reed@google.comd1ab9322012-01-10 18:40:03 +000072 path2.reset();
reed@google.comb435bd72012-01-10 19:28:01 +000073 path2.addCircle(x + SkIntToScalar(240), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000074 canvas->drawPath(path2, paint);
75 SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction));
rmistry@google.comae933ce2012-08-23 18:19:56 +000076
reed@google.comd1ab9322012-01-10 18:40:03 +000077 path2.reset();
78 SkASSERT(!path2.cheapComputeDirection(NULL));
reed@google.comb435bd72012-01-10 19:28:01 +000079 path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000080 SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction));
81 canvas->drawPath(path2, paint);
robertphillips4f662e62014-12-29 14:06:51 -080082
83 SkRect r = SkRect::MakeXYWH(x - SkIntToScalar(50), y + SkIntToScalar(280),
84 SkIntToScalar(100), SkIntToScalar(100));
85 SkPath path3;
86 path3.setFillType(SkPath::kWinding_FillType);
87 path3.addRect(r, SkPath::kCW_Direction);
88 r.inset(SkIntToScalar(10), SkIntToScalar(10));
89 path3.addRect(r, SkPath::kCCW_Direction);
90 canvas->drawPath(path3, paint);
91
92 r = SkRect::MakeXYWH(x + SkIntToScalar(70), y + SkIntToScalar(280),
93 SkIntToScalar(100), SkIntToScalar(100));
94 SkPath path4;
95 path4.setFillType(SkPath::kWinding_FillType);
96 path4.addRect(r, SkPath::kCCW_Direction);
97 r.inset(SkIntToScalar(10), SkIntToScalar(10));
98 path4.addRect(r, SkPath::kCW_Direction);
99 canvas->drawPath(path4, paint);
100
101 r = SkRect::MakeXYWH(x + SkIntToScalar(190), y + SkIntToScalar(280),
102 SkIntToScalar(100), SkIntToScalar(100));
103 path4.reset();
104 SkASSERT(!path4.cheapComputeDirection(NULL));
105 path4.addRect(r, SkPath::kCCW_Direction);
106 SkASSERT(path4.cheapIsDirection(SkPath::kCCW_Direction));
107 path4.moveTo(0, 0); // test for crbug.com/247770
108 canvas->drawPath(path4, paint);
109
110 r = SkRect::MakeXYWH(x + SkIntToScalar(310), y + SkIntToScalar(280),
111 SkIntToScalar(100), SkIntToScalar(100));
112 path4.reset();
113 SkASSERT(!path4.cheapComputeDirection(NULL));
114 path4.addRect(r, SkPath::kCW_Direction);
115 SkASSERT(path4.cheapIsDirection(SkPath::kCW_Direction));
116 path4.moveTo(0, 0); // test for crbug.com/247770
117 canvas->drawPath(path4, paint);
reed@google.com63d73742012-01-10 15:33:12 +0000118 }
119
120private:
121 typedef GM INHERITED;
122};
123
124//////////////////////////////////////////////////////////////////////////////
125
robertphillips4f662e62014-12-29 14:06:51 -0800126DEF_GM(return SkNEW(StrokeFillGM);)
reed@google.com63d73742012-01-10 15:33:12 +0000127
128}