Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=888edd4c4a91ca62ceb01bce8ab675b2 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Path_addRRect_2, 256, 256, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | SkPaint paint; |
| 8 | paint.setAntiAlias(true); |
| 9 | SkRRect rrect; |
| 10 | rrect.setRectXY({40, 40, 215, 215}, 50, 50); |
| 11 | SkPath path; |
| 12 | path.addRRect(rrect); |
| 13 | canvas->drawPath(path, paint); |
| 14 | for (int start = 0; start < 8; ++start) { |
| 15 | SkPath textPath; |
| 16 | textPath.addRRect(rrect, SkPath::kCW_Direction, start); |
| 17 | SkPathMeasure pathMeasure(textPath, false); |
| 18 | SkPoint position; |
| 19 | SkVector tangent; |
| 20 | if (!pathMeasure.getPosTan(0, &position, &tangent)) { |
| 21 | continue; |
| 22 | } |
| 23 | SkRSXform rsxForm = SkRSXform::Make(tangent.fX, tangent.fY, |
| 24 | position.fX + tangent.fY * 5, position.fY - tangent.fX * 5); |
Hal Canary | 3d42a05 | 2019-03-15 16:43:29 -0400 | [diff] [blame] | 25 | SkFont font(nullptr, 12); |
| 26 | auto labels = SkTextBlob::MakeFromRSXform(&"01234567"[start], 1, &rsxForm, font); |
| 27 | canvas->drawTextBlob(labels, 0, 0, paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 28 | } |
| 29 | } |
| 30 | } // END FIDDLE |