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.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Path_addRRect_2, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 SkPaint paint;
7 paint.setAntiAlias(true);
8 SkRRect rrect;
9 rrect.setRectXY({40, 40, 215, 215}, 50, 50);
10 SkPath path;
11 path.addRRect(rrect);
12 canvas->drawPath(path, paint);
13 for (int start = 0; start < 8; ++start) {
14 SkPath textPath;
15 textPath.addRRect(rrect, SkPathDirection::kCW, start);
16 SkPathMeasure pathMeasure(textPath, false);
17 SkPoint position;
18 SkVector tangent;
19 if (!pathMeasure.getPosTan(0, &position, &tangent)) {
20 continue;
21 }
22 SkRSXform rsxForm = SkRSXform::Make(tangent.fX, tangent.fY,
23 position.fX + tangent.fY * 5, position.fY - tangent.fX * 5);
24 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 12);
25 auto labels = SkTextBlob::MakeFromRSXform(&"01234567"[start], 1, &rsxForm, font);
26 canvas->drawTextBlob(labels, 0, 0, paint);
27 }
28 }
29 } // END FIDDLE
30