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: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 22 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 23 | return kSkipTiled_Flag; |
| 24 | } |
| 25 | |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 26 | virtual SkString onShortName() { |
| 27 | return SkString("stroke-fill"); |
| 28 | } |
| 29 | |
| 30 | virtual SkISize onISize() { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 31 | return SkISize::Make(640, 480); |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 32 | } |
| 33 | |
bungeman@google.com | f8aa18c | 2012-03-19 21:04:52 +0000 | [diff] [blame] | 34 | static void show_bold(SkCanvas* canvas, const void* text, int len, |
| 35 | SkScalar x, SkScalar y, const SkPaint& paint) { |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 36 | SkPaint p(paint); |
| 37 | canvas->drawText(text, len, x, y, p); |
| 38 | p.setFakeBoldText(true); |
| 39 | canvas->drawText(text, len, x, y + SkIntToScalar(120), p); |
| 40 | } |
| 41 | |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 42 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 43 | SkScalar x = SkIntToScalar(100); |
| 44 | SkScalar y = SkIntToScalar(88); |
| 45 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 46 | SkPaint paint; |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 47 | paint.setAntiAlias(true); |
| 48 | paint.setTextSize(SkIntToScalar(100)); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 49 | paint.setStrokeWidth(SkIntToScalar(5)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 50 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 51 | sk_tool_utils::set_portable_typeface(&paint, "Papyrus"); |
bungeman@google.com | f8aa18c | 2012-03-19 21:04:52 +0000 | [diff] [blame] | 52 | show_bold(canvas, "Hello", 5, x, y, paint); |
reed@google.com | 188bfcf | 2012-01-17 18:26:38 +0000 | [diff] [blame] | 53 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 54 | sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro"); |
bungeman@google.com | f8aa18c | 2012-03-19 21:04:52 +0000 | [diff] [blame] | 55 | const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC }; |
| 56 | 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] | 57 | |
| 58 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 59 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 60 | SkPath path; |
| 61 | path.setFillType(SkPath::kWinding_FillType); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 62 | path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction); |
| 63 | path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCCW_Direction); |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 64 | canvas->drawPath(path, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 65 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 66 | SkPath path2; |
| 67 | path2.setFillType(SkPath::kWinding_FillType); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 68 | path2.addCircle(x + SkIntToScalar(120), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCCW_Direction); |
| 69 | 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] | 70 | canvas->drawPath(path2, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 71 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 72 | path2.reset(); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 73 | 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] | 74 | canvas->drawPath(path2, paint); |
| 75 | SkASSERT(path2.cheapIsDirection(SkPath::kCCW_Direction)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 76 | |
reed@google.com | d1ab932 | 2012-01-10 18:40:03 +0000 | [diff] [blame] | 77 | path2.reset(); |
| 78 | SkASSERT(!path2.cheapComputeDirection(NULL)); |
reed@google.com | b435bd7 | 2012-01-10 19:28:01 +0000 | [diff] [blame] | 79 | 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] | 80 | SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction)); |
| 81 | canvas->drawPath(path2, paint); |
reed@google.com | 63d7374 | 2012-01-10 15:33:12 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | private: |
| 85 | typedef GM INHERITED; |
| 86 | }; |
| 87 | |
| 88 | ////////////////////////////////////////////////////////////////////////////// |
| 89 | |
| 90 | static GM* MyFactory(void*) { return new StrokeFillGM; } |
| 91 | static GMRegistry reg(MyFactory); |
| 92 | |
| 93 | } |