| 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) { |
| 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 = SkPath::RRect(rrect); |
| 11 |
canvas->drawPath(path, paint); |
| 12 |
for (int start = 0; start < 8; ++start) { |
| 13 |
SkPath textPath = SkPath::RRect(rrect, SkPathDirection::kCW, start); |
| 14 |
SkPathMeasure pathMeasure(textPath, false); |
| 15 |
SkPoint position; |
| 16 |
SkVector tangent; |
| 17 |
if (!pathMeasure.getPosTan(0, &position, &tangent)) { |
| 18 |
continue; |
| 19 |
} |
| 20 |
SkRSXform rsxForm = SkRSXform::Make(tangent.fX, tangent.fY, |
| 21 |
position.fX + tangent.fY * 5, position.fY - tangent.fX * 5); |
| 22 |
SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 12); |
| 23 |
auto labels = SkTextBlob::MakeFromRSXform(&"01234567"[start], 1, {&rsxForm, 1}, font); |
| 24 |
canvas->drawTextBlob(labels, 0, 0, paint); |
| 25 |
} |
| 26 |
} |
| 27 |
} // END FIDDLE |