reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 1 | /* |
| 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" |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 10 | #include "SkPathPriv.h" |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 11 | #include "SkTypeface.h" |
| 12 | |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 13 | namespace skiagm { |
| 14 | |
| 15 | class StrokeFillGM : public GM { |
| 16 | public: |
| 17 | StrokeFillGM() { |
| 18 | |
| 19 | } |
| 20 | |
| 21 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 22 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | SkString onShortName() override { |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 24 | return SkString("stroke-fill"); |
| 25 | } |
| 26 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 27 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 28 | return SkISize::Make(640, 480); |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 29 | } |
| 30 | |
bungeman@google.com | f8aa18c | 2012-03-19 21:04:52 +0000 | [diff] [blame] | 31 | static void show_bold(SkCanvas* canvas, const void* text, int len, |
| 32 | SkScalar x, SkScalar y, const SkPaint& paint) { |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 33 | SkPaint p(paint); |
| 34 | canvas->drawText(text, len, x, y, p); |
| 35 | p.setFakeBoldText(true); |
| 36 | canvas->drawText(text, len, x, y + SkIntToScalar(120), p); |
| 37 | } |
| 38 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 39 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 40 | SkScalar x = SkIntToScalar(100); |
| 41 | SkScalar y = SkIntToScalar(88); |
| 42 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 43 | SkPaint paint; |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 44 | paint.setAntiAlias(true); |
| 45 | paint.setTextSize(SkIntToScalar(100)); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 46 | paint.setStrokeWidth(SkIntToScalar(5)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 47 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 48 | sk_tool_utils::set_portable_typeface(&paint, "Papyrus"); |
bungeman@google.com | f8aa18c | 2012-03-19 21:04:52 +0000 | [diff] [blame] | 49 | show_bold(canvas, "Hello", 5, x, y, paint); |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 50 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 51 | sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro"); |
bungeman@google.com | f8aa18c | 2012-03-19 21:04:52 +0000 | [diff] [blame] | 52 | const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC }; |
| 53 | show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300), y, paint); |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 54 | |
| 55 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 56 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 57 | SkPath path; |
| 58 | path.setFillType(SkPath::kWinding_FillType); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 59 | path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction); |
| 60 | path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction); |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 61 | canvas->drawPath(path, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 62 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 63 | SkPath path2; |
| 64 | path2.setFillType(SkPath::kWinding_FillType); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 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); |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 67 | canvas->drawPath(path2, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 68 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 69 | path2.reset(); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 70 | path2.addCircle(x + SkIntToScalar(240), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction); |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 71 | canvas->drawPath(path2, paint); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 72 | SkASSERT(SkPathPriv::CheapIsFirstDirection(path2, SkPathPriv::kCCW_FirstDirection)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 73 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 74 | path2.reset(); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 75 | SkASSERT(!SkPathPriv::CheapComputeFirstDirection(path2, NULL)); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 76 | path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 77 | SkASSERT(SkPathPriv::CheapIsFirstDirection(path2, SkPathPriv::kCW_FirstDirection)); |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 78 | canvas->drawPath(path2, paint); |
robertphillips | 4f662e6 | 2014-12-29 14:06:51 -0800 | [diff] [blame] | 79 | |
| 80 | SkRect r = SkRect::MakeXYWH(x - SkIntToScalar(50), y + SkIntToScalar(280), |
| 81 | SkIntToScalar(100), SkIntToScalar(100)); |
| 82 | SkPath path3; |
| 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); |
| 88 | |
| 89 | r = SkRect::MakeXYWH(x + SkIntToScalar(70), y + SkIntToScalar(280), |
| 90 | SkIntToScalar(100), SkIntToScalar(100)); |
| 91 | SkPath path4; |
| 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); |
| 97 | |
| 98 | r = SkRect::MakeXYWH(x + SkIntToScalar(190), y + SkIntToScalar(280), |
| 99 | SkIntToScalar(100), SkIntToScalar(100)); |
| 100 | path4.reset(); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 101 | SkASSERT(!SkPathPriv::CheapComputeFirstDirection(path4, NULL)); |
robertphillips | 4f662e6 | 2014-12-29 14:06:51 -0800 | [diff] [blame] | 102 | path4.addRect(r, SkPath::kCCW_Direction); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 103 | SkASSERT(SkPathPriv::CheapIsFirstDirection(path4, SkPathPriv::kCCW_FirstDirection)); |
robertphillips | 4f662e6 | 2014-12-29 14:06:51 -0800 | [diff] [blame] | 104 | path4.moveTo(0, 0); // test for crbug.com/247770 |
| 105 | canvas->drawPath(path4, paint); |
| 106 | |
| 107 | r = SkRect::MakeXYWH(x + SkIntToScalar(310), y + SkIntToScalar(280), |
| 108 | SkIntToScalar(100), SkIntToScalar(100)); |
| 109 | path4.reset(); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 110 | SkASSERT(!SkPathPriv::CheapComputeFirstDirection(path4, NULL)); |
robertphillips | 4f662e6 | 2014-12-29 14:06:51 -0800 | [diff] [blame] | 111 | path4.addRect(r, SkPath::kCW_Direction); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 112 | SkASSERT(SkPathPriv::CheapIsFirstDirection(path4, SkPathPriv::kCW_FirstDirection)); |
robertphillips | 4f662e6 | 2014-12-29 14:06:51 -0800 | [diff] [blame] | 113 | path4.moveTo(0, 0); // test for crbug.com/247770 |
| 114 | canvas->drawPath(path4, paint); |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | private: |
| 118 | typedef GM INHERITED; |
| 119 | }; |
| 120 | |
| 121 | ////////////////////////////////////////////////////////////////////////////// |
| 122 | |
robertphillips | 4f662e6 | 2014-12-29 14:06:51 -0800 | [diff] [blame] | 123 | DEF_GM(return SkNEW(StrokeFillGM);) |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 124 | |
| 125 | } |