2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
11 #include "SkTypeface.h"
15 class StrokeFillGM : public GM {
23 SkString onShortName() SK_OVERRIDE {
24 return SkString("stroke-fill");
27 SkISize onISize() SK_OVERRIDE {
28 return SkISize::Make(640, 480);
31 static void show_bold(SkCanvas* canvas, const void* text, int len,
32 SkScalar x, SkScalar y, const SkPaint& paint) {
34 canvas->drawText(text, len, x, y, p);
35 p.setFakeBoldText(true);
36 canvas->drawText(text, len, x, y + SkIntToScalar(120), p);
39 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
40 SkScalar x = SkIntToScalar(100);
41 SkScalar y = SkIntToScalar(88);
44 paint.setAntiAlias(true);
45 paint.setTextSize(SkIntToScalar(100));
46 paint.setStrokeWidth(SkIntToScalar(5));
48 sk_tool_utils::set_portable_typeface(&paint, "Papyrus");
49 show_bold(canvas, "Hello", 5, x, y, paint);
51 sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro");
52 const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC };
53 show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300), y, paint);
55 paint.setStyle(SkPaint::kStrokeAndFill_Style);
58 path.setFillType(SkPath::kWinding_FillType);
59 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
60 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction);
61 canvas->drawPath(path, paint);
64 path2.setFillType(SkPath::kWinding_FillType);
65 path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
66 path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCW_Direction);
67 canvas->drawPath(path2, paint);
70 path2.addCircle(x + SkIntToScalar(240), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction);
71 canvas->drawPath(path2, paint);
72 SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction));
75 SkASSERT(!path2.cheapComputeDirection(NULL));
76 path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction);
77 SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction));
78 canvas->drawPath(path2, paint);
80 SkRect r = SkRect::MakeXYWH(x - SkIntToScalar(50), y + SkIntToScalar(280),
81 SkIntToScalar(100), SkIntToScalar(100));
83 path3.setFillType(SkPath::kWinding_FillType);
84 path3.addRect(r, SkPath::kCW_Direction);
85 r.inset(SkIntToScalar(10), SkIntToScalar(10));
86 path3.addRect(r, SkPath::kCCW_Direction);
87 canvas->drawPath(path3, paint);
89 r = SkRect::MakeXYWH(x + SkIntToScalar(70), y + SkIntToScalar(280),
90 SkIntToScalar(100), SkIntToScalar(100));
92 path4.setFillType(SkPath::kWinding_FillType);
93 path4.addRect(r, SkPath::kCCW_Direction);
94 r.inset(SkIntToScalar(10), SkIntToScalar(10));
95 path4.addRect(r, SkPath::kCW_Direction);
96 canvas->drawPath(path4, paint);
98 r = SkRect::MakeXYWH(x + SkIntToScalar(190), y + SkIntToScalar(280),
99 SkIntToScalar(100), SkIntToScalar(100));
101 SkASSERT(!path4.cheapComputeDirection(NULL));
102 path4.addRect(r, SkPath::kCCW_Direction);
103 SkASSERT(path4.cheapIsDirection(SkPath::kCCW_Direction));
104 path4.moveTo(0, 0); // test for crbug.com/247770
105 canvas->drawPath(path4, paint);
107 r = SkRect::MakeXYWH(x + SkIntToScalar(310), y + SkIntToScalar(280),
108 SkIntToScalar(100), SkIntToScalar(100));
110 SkASSERT(!path4.cheapComputeDirection(NULL));
111 path4.addRect(r, SkPath::kCW_Direction);
112 SkASSERT(path4.cheapIsDirection(SkPath::kCW_Direction));
113 path4.moveTo(0, 0); // test for crbug.com/247770
114 canvas->drawPath(path4, paint);
118 typedef GM INHERITED;
121 //////////////////////////////////////////////////////////////////////////////
123 DEF_GM(return SkNEW(StrokeFillGM);)