skia path offsetting

190 views
Skip to first unread message

Martin

unread,
Sep 10, 2021, 8:46:20 AM9/10/21
to skia-discuss
Hi,
I want to draw a path with dashed, rounded outline - like in the screenshot.
Is there path-offsetting functionality built into skia, is this functionality planned?
This is image created in photoshop.
example.PNG
I've read around the web an found this is a tough problem to solve. But you're google so I dare to ask here once.

paul....@gmail.com

unread,
Sep 11, 2021, 10:36:42 AM9/11/21
to skia-discuss
It is possible to do this in Skia.

The technique is as follows:

Assuming B is the blue path, and R is the red path.

1. Make a paint with stroke width set to R's stroke width.
2. Use SkPaint getFillPath() method on B to get a path (S) equivalent to a stroked B
3. Use Path Ops to create R: a union of B and S.

R should contain the desired red path.

I can't guarantee that it will work well for every possible path.  But here's a fiddle demonstrating the technique in action.


Hope this helps.
Paul
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages