Stephen White | e7a364d | 2017-01-11 16:19:26 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Stephen White | e7a364d | 2017-01-11 16:19:26 -0500 | [diff] [blame] | 12 | namespace { |
| 13 | // Test thin stroked rect (stroked "by hand", not by stroking). |
| 14 | void draw_thin_stroked_rect(SkCanvas* canvas, const SkPaint& paint, SkScalar width) { |
| 15 | SkPath path; |
| 16 | path.moveTo(10 + width, 10 + width); |
| 17 | path.lineTo(40, 10 + width); |
| 18 | path.lineTo(40, 20); |
| 19 | path.lineTo(10 + width, 20); |
| 20 | path.moveTo(10, 10); |
| 21 | path.lineTo(10, 20 + width); |
| 22 | path.lineTo(40 + width, 20 + width); |
| 23 | path.lineTo(40 + width, 10); |
| 24 | canvas->drawPath(path, paint); |
| 25 | } |
| 26 | |
Stephen White | eaf0079 | 2017-01-16 11:47:21 -0500 | [diff] [blame] | 27 | void draw_thin_right_angle(SkCanvas* canvas, const SkPaint& paint, SkScalar width) { |
| 28 | SkPath path; |
| 29 | path.moveTo(10 + width, 10 + width); |
| 30 | path.lineTo(40, 10 + width); |
| 31 | path.lineTo(40, 20); |
| 32 | path.lineTo(40 + width, 20 + width); |
| 33 | path.lineTo(40 + width, 10); |
| 34 | path.lineTo(10, 10); |
| 35 | canvas->drawPath(path, paint); |
| 36 | } |
| 37 | |
Stephen White | e7a364d | 2017-01-11 16:19:26 -0500 | [diff] [blame] | 38 | }; |
| 39 | |
Stephen White | 930f69e | 2017-01-12 17:15:50 -0500 | [diff] [blame] | 40 | DEF_SIMPLE_GM(thinconcavepaths, canvas, 400, 400) { |
| 41 | SkPaint paint; |
Stephen White | e7a364d | 2017-01-11 16:19:26 -0500 | [diff] [blame] | 42 | |
Stephen White | 930f69e | 2017-01-12 17:15:50 -0500 | [diff] [blame] | 43 | paint.setAntiAlias(true); |
| 44 | paint.setStyle(SkPaint::kFill_Style); |
| 45 | |
| 46 | canvas->save(); |
| 47 | for (SkScalar width = 1.0; width < 2.05; width += 0.25) { |
| 48 | draw_thin_stroked_rect(canvas, paint, width); |
| 49 | canvas->translate(0, 25); |
Stephen White | e7a364d | 2017-01-11 16:19:26 -0500 | [diff] [blame] | 50 | } |
Stephen White | 930f69e | 2017-01-12 17:15:50 -0500 | [diff] [blame] | 51 | canvas->restore(); |
Stephen White | eaf0079 | 2017-01-16 11:47:21 -0500 | [diff] [blame] | 52 | canvas->translate(50, 0); |
| 53 | canvas->save(); |
| 54 | for (SkScalar width = 0.5; width < 2.05; width += 0.25) { |
| 55 | draw_thin_right_angle(canvas, paint, width); |
| 56 | canvas->translate(0, 25); |
| 57 | } |
| 58 | canvas->restore(); |
| 59 | canvas->translate(100, 0); |
Stephen White | 930f69e | 2017-01-12 17:15:50 -0500 | [diff] [blame] | 60 | } |