blob: 445de811ec1e407750717a1017898cacc6eac377 [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:
22 virtual SkString onShortName() {
23 return SkString("stroke-fill");
24 }
25
26 virtual SkISize onISize() {
27 return make_isize(640, 480);
28 }
29
bungeman@google.comf8aa18c2012-03-19 21:04:52 +000030 static void show_bold(SkCanvas* canvas, const void* text, int len,
31 SkScalar x, SkScalar y, const SkPaint& paint) {
reed@google.com188bfcf2012-01-17 18:26:38 +000032 SkPaint p(paint);
33 canvas->drawText(text, len, x, y, p);
34 p.setFakeBoldText(true);
35 canvas->drawText(text, len, x, y + SkIntToScalar(120), p);
36 }
37
reed@google.com63d73742012-01-10 15:33:12 +000038 virtual void onDraw(SkCanvas* canvas) {
reed@google.com188bfcf2012-01-17 18:26:38 +000039 SkScalar x = SkIntToScalar(100);
40 SkScalar y = SkIntToScalar(88);
41
reed@google.comd1ab9322012-01-10 18:40:03 +000042 SkPaint paint;
reed@google.comd1ab9322012-01-10 18:40:03 +000043 paint.setAntiAlias(true);
44 paint.setTextSize(SkIntToScalar(100));
reed@google.comb435bd72012-01-10 19:28:01 +000045 paint.setStrokeWidth(SkIntToScalar(5));
rmistry@google.comae933ce2012-08-23 18:19:56 +000046
reed@google.com188bfcf2012-01-17 18:26:38 +000047 SkTypeface* face = SkTypeface::CreateFromName("Papyrus", SkTypeface::kNormal);
48 SkSafeUnref(paint.setTypeface(face));
bungeman@google.comf8aa18c2012-03-19 21:04:52 +000049 show_bold(canvas, "Hello", 5, x, y, paint);
reed@google.com188bfcf2012-01-17 18:26:38 +000050
51 face = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
52 SkSafeUnref(paint.setTypeface(face));
bungeman@google.comf8aa18c2012-03-19 21:04:52 +000053 const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC };
54 show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300), y, paint);
reed@google.com188bfcf2012-01-17 18:26:38 +000055
56 paint.setStyle(SkPaint::kStrokeAndFill_Style);
57
reed@google.comd1ab9322012-01-10 18:40:03 +000058 SkPath path;
59 path.setFillType(SkPath::kWinding_FillType);
reed@google.comb435bd72012-01-10 19:28:01 +000060 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
61 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000062 canvas->drawPath(path, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000063
reed@google.comd1ab9322012-01-10 18:40:03 +000064 SkPath path2;
65 path2.setFillType(SkPath::kWinding_FillType);
reed@google.comb435bd72012-01-10 19:28:01 +000066 path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
67 path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000068 canvas->drawPath(path2, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000069
reed@google.comd1ab9322012-01-10 18:40:03 +000070 path2.reset();
reed@google.comb435bd72012-01-10 19:28:01 +000071 path2.addCircle(x + SkIntToScalar(240), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000072 canvas->drawPath(path2, paint);
73 SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction));
rmistry@google.comae933ce2012-08-23 18:19:56 +000074
reed@google.comd1ab9322012-01-10 18:40:03 +000075 path2.reset();
76 SkASSERT(!path2.cheapComputeDirection(NULL));
reed@google.comb435bd72012-01-10 19:28:01 +000077 path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
reed@google.comd1ab9322012-01-10 18:40:03 +000078 SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction));
79 canvas->drawPath(path2, paint);
reed@google.com63d73742012-01-10 15:33:12 +000080 }
81
82private:
83 typedef GM INHERITED;
84};
85
86//////////////////////////////////////////////////////////////////////////////
87
88static GM* MyFactory(void*) { return new StrokeFillGM; }
89static GMRegistry reg(MyFactory);
90
91}