reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +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 | |
| 13 | static void test_path(SkCanvas* canvas, const SkPath& path) { |
| 14 | SkPaint paint; |
| 15 | paint.setAntiAlias(true); |
| 16 | canvas->drawPath(path, paint); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 17 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 18 | paint.setStyle(SkPaint::kStroke_Style); |
| 19 | paint.setColor(SK_ColorRED); |
| 20 | canvas->drawPath(path, paint); |
| 21 | } |
| 22 | |
| 23 | static void test_rev(SkCanvas* canvas, const SkPath& path) { |
| 24 | test_path(canvas, path); |
| 25 | |
| 26 | SkPath rev; |
| 27 | rev.reverseAddPath(path); |
| 28 | canvas->save(); |
| 29 | canvas->translate(150, 0); |
| 30 | test_path(canvas, rev); |
| 31 | canvas->restore(); |
| 32 | } |
| 33 | |
| 34 | static void test_rev(SkCanvas* canvas) { |
| 35 | SkRect r = { 10, 10, 100, 60 }; |
| 36 | |
| 37 | SkPath path; |
| 38 | |
| 39 | path.addRect(r); test_rev(canvas, path); |
| 40 | |
| 41 | canvas->translate(0, 100); |
| 42 | path.offset(20, 20); |
| 43 | path.addRect(r); test_rev(canvas, path); |
| 44 | |
| 45 | canvas->translate(0, 100); |
| 46 | path.reset(); |
| 47 | path.moveTo(10, 10); path.lineTo(30, 30); |
| 48 | path.addOval(r); |
| 49 | r.offset(50, 20); |
| 50 | path.addOval(r); |
| 51 | test_rev(canvas, path); |
| 52 | |
| 53 | SkPaint paint; |
| 54 | paint.setTextSize(SkIntToScalar(100)); |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 55 | sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro"); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 56 | path.reset(); |
| 57 | paint.getTextPath("e", 1, 50, 50, &path); |
| 58 | canvas->translate(0, 100); |
| 59 | test_rev(canvas, path); |
| 60 | } |
| 61 | |
| 62 | namespace skiagm { |
| 63 | |
| 64 | class PathReverseGM : public GM { |
| 65 | public: |
| 66 | PathReverseGM() { |
| 67 | |
| 68 | } |
| 69 | |
| 70 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 71 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 72 | SkString onShortName() override { |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 73 | return SkString("path-reverse"); |
| 74 | } |
| 75 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 76 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 77 | return SkISize::Make(640, 480); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 78 | } |
| 79 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 80 | void onDraw(SkCanvas* canvas) override { |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 81 | if (false) test_rev(canvas); // avoid bit rot, suppress warning |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 82 | SkRect r = { 10, 10, 100, 60 }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 83 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 84 | SkPath path; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 85 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 86 | path.addRect(r); test_rev(canvas, path); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 87 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 88 | canvas->translate(0, 100); |
| 89 | path.offset(20, 20); |
| 90 | path.addRect(r); test_rev(canvas, path); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 91 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 92 | canvas->translate(0, 100); |
| 93 | path.reset(); |
| 94 | path.moveTo(10, 10); path.lineTo(30, 30); |
| 95 | path.addOval(r); |
| 96 | r.offset(50, 20); |
| 97 | path.addOval(r); |
| 98 | test_rev(canvas, path); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 99 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 100 | SkPaint paint; |
| 101 | paint.setTextSize(SkIntToScalar(100)); |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 102 | sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro"); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 103 | path.reset(); |
| 104 | paint.getTextPath("e", 1, 50, 50, &path); |
| 105 | canvas->translate(0, 100); |
| 106 | test_rev(canvas, path); |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | typedef GM INHERITED; |
| 111 | }; |
| 112 | |
| 113 | ////////////////////////////////////////////////////////////////////////////// |
| 114 | |
| 115 | static GM* MyFactory(void*) { return new PathReverseGM; } |
| 116 | static GMRegistry reg(MyFactory); |
| 117 | |
| 118 | } |