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 | |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 30 | static void show_bold(SkCanvas* canvas, const char text[], SkScalar x, |
| 31 | SkScalar y, const SkPaint& paint) { |
| 32 | size_t len = strlen(text); |
| 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 | |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 39 | virtual void onDraw(SkCanvas* canvas) { |
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)); |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 47 | |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 48 | SkTypeface* face = SkTypeface::CreateFromName("Papyrus", SkTypeface::kNormal); |
| 49 | SkSafeUnref(paint.setTypeface(face)); |
| 50 | show_bold(canvas, "Hello", x, y, paint); |
| 51 | |
| 52 | face = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal); |
| 53 | SkSafeUnref(paint.setTypeface(face)); |
| 54 | const char hyphen[] = { 0xE3, 0x83, 0xBC, 0 }; |
| 55 | show_bold(canvas, hyphen, x + SkIntToScalar(300), y, paint); |
| 56 | |
| 57 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 58 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 59 | SkPath path; |
| 60 | path.setFillType(SkPath::kWinding_FillType); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 61 | path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction); |
| 62 | path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction); |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 63 | canvas->drawPath(path, paint); |
| 64 | |
| 65 | SkPath path2; |
| 66 | path2.setFillType(SkPath::kWinding_FillType); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 67 | path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction); |
| 68 | 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] | 69 | canvas->drawPath(path2, paint); |
| 70 | |
| 71 | path2.reset(); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 72 | 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] | 73 | canvas->drawPath(path2, paint); |
| 74 | SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction)); |
| 75 | |
| 76 | path2.reset(); |
| 77 | SkASSERT(!path2.cheapComputeDirection(NULL)); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 78 | 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] | 79 | SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction)); |
| 80 | canvas->drawPath(path2, paint); |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | private: |
| 84 | typedef GM INHERITED; |
| 85 | }; |
| 86 | |
| 87 | ////////////////////////////////////////////////////////////////////////////// |
| 88 | |
| 89 | static GM* MyFactory(void*) { return new StrokeFillGM; } |
| 90 | static GMRegistry reg(MyFactory); |
| 91 | |
| 92 | } |