Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Path_addRRect_2.cpp
Go to the documentation of this file.
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.
4// HASH=888edd4c4a91ca62ceb01bce8ab675b2
5REG_FIDDLE(Path_addRRect_2, 256, 256, false, 0) {
6void draw(SkCanvas* canvas) {
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, SkPathDirection::kCW, 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);
25 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 12);
26 auto labels = SkTextBlob::MakeFromRSXform(&"01234567"[start], 1, &rsxForm, font);
27 canvas->drawTextBlob(labels, 0, 0, paint);
28 }
29}
30} // END FIDDLE
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
void drawPath(const SkPath &path, const SkPaint &paint)
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
bool getPosTan(SkScalar distance, SkPoint *position, SkVector *tangent)
SkPath & addRRect(const SkRRect &rrect, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:990
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.cpp:52
static sk_sp< SkTextBlob > MakeFromRSXform(const void *text, size_t byteLength, const SkRSXform xform[], const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
const Paint & paint
sk_sp< SkFontMgr > fontMgr
Definition examples.cpp:32
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
float fX
x-axis value
float fY
y-axis value
static SkRSXform Make(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty)
Definition SkRSXform.h:24