[cairo] Stroke to path

Andrea Canciani ranma42 at gmail.com
Thu Oct 7 23:04:28 PDT 2010


On Fri, Oct 8, 2010 at 12:18 AM, Mindaugas Kavaliauskas
<dbtopas at dbtopas.lt> wrote:
> Hi,
>
>
> how can I obtain a egde of current stroke as a path. It's something that can
> be done using Inkscape Menu->Path->"Stroke to path".

stroke-to-path is a feature that has been requested multiple times,
but it is quite
hard to get it right (mainly because of numerical stability issues).
There is a mostly-working implementation, but it will probably need some more
testing/fixing before it will get into cairo.

>
> It's very useful, f.e., if I need to draw a road (on a map) using a brown
> line with a black edge. I would expect something like:
>  ...
>  cairo_set_source_rgb(ctx, 0.5, 0.25, 0);
>  cairo_set_line_width(ctx, 1);
>  cairo_stroke_preserve(ctx);
>  cairo_stroke_to_path(ctx);
>  cairo_set_source_rgb(ctx, 0, 0, 0);
>  cairo_set_line_width(ctx, 0.2);
>  cairo_stroke(ctx);

You can cheat (because you're using opaque colors) and get the same results
using the following code:
cairo_set_source_rgb(ctx, 0, 0, 0);
cairo_set_line_width(ctx, 1 + 0.2);
cairo_stroke_preserve(ctx);
cairo_set_source_rgb(ctx, 0.5, 0.25, 0);
cairo_set_line_width(ctx, 1 - 0.2);
cairo_stroke(ctx);

I hope this workaround will be sufficient for your needs.
Andrea


More information about the cairo mailing list