| 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" |
| 10 | #include "SkPath.h" |
| 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: |
| 22 | virtual SkString onShortName() { |
| 23 | return SkString("stroke-fill"); |
| 24 | } |
| 25 | |
| 26 | virtual SkISize onISize() { |
| 27 | return make_isize(640, 480); |
| 28 | } |
| 29 | |
| 30 | virtual void onDraw(SkCanvas* canvas) { |
| reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 31 | SkPaint paint; |
| 32 | const char text[] = "Hello"; // "Hello"; |
| 33 | const size_t len = sizeof(text) - 1; |
| 34 | paint.setAntiAlias(true); |
| 35 | paint.setTextSize(SkIntToScalar(100)); |
| reed@google.com | 3d19c38 | 2012-01-11 18:16:39 +0000 | [diff] [blame] | 36 | // SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal); |
| 37 | SkTypeface* hira = SkTypeface::CreateFromName("Papyrus", SkTypeface::kNormal); |
| reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 38 | paint.setTypeface(hira); |
| reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 39 | SkScalar x = SkIntToScalar(180); |
| 40 | SkScalar y = SkIntToScalar(88); |
| reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 41 | |
| 42 | canvas->drawText(text, len, x, y, paint); |
| 43 | paint.setFakeBoldText(true); |
| reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 44 | canvas->drawText(text, len, x, y + SkIntToScalar(100), paint); |
| reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 45 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 46 | paint.setStrokeWidth(SkIntToScalar(5)); |
| reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 47 | |
| 48 | SkPath path; |
| 49 | path.setFillType(SkPath::kWinding_FillType); |
| reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 50 | path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction); |
| 51 | path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction); |
| reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 52 | canvas->drawPath(path, paint); |
| 53 | |
| 54 | SkPath path2; |
| 55 | path2.setFillType(SkPath::kWinding_FillType); |
| reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 56 | path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction); |
| 57 | 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] | 58 | canvas->drawPath(path2, paint); |
| 59 | |
| 60 | path2.reset(); |
| reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 61 | 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] | 62 | canvas->drawPath(path2, paint); |
| 63 | SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction)); |
| 64 | |
| 65 | path2.reset(); |
| 66 | SkASSERT(!path2.cheapComputeDirection(NULL)); |
| reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 67 | path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction); |
| reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 68 | SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction)); |
| 69 | canvas->drawPath(path2, paint); |
| reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | private: |
| 73 | typedef GM INHERITED; |
| 74 | }; |
| 75 | |
| 76 | ////////////////////////////////////////////////////////////////////////////// |
| 77 | |
| 78 | static GM* MyFactory(void*) { return new StrokeFillGM; } |
| 79 | static GMRegistry reg(MyFactory); |
| 80 | |
| 81 | } |