[cairo] Adding polygons
Uli Schlachter
psychon at znc.in
Wed May 30 05:30:28 UTC 2018
Hi,
On 29.05.2018 03:53, cairouser at yahoo.com wrote:
> I've encountered what seems like a simple use case, that for some reason I am unable to solve within my knowledge of Cairo.
>
> I am trying to "add" (in polygon terms) two shapes. Each shape is drawn using a thick outline and a fill color. What should be drawn is a polygon that is a sum of both provided polygons.
> In the attached sample the shapes are - a rectangle, and a pointed arrow with origin at rectangle center.
So you do want to "actually draw the path", but only its outline?
> The sample is created using external polygon clipper. That's an acceptable solution for a simpler shape, but for shapes that include arcs, for example, external clipper is not very helpful
> Is there a way to achieve the same effect using only Cairo functionality?
How about first stroking the two paths (which means that also internal
lines are drawn) and then filling them, overwriting the internal lines?
Without alpha and the OVER operator, the default would "just work".
With alpha you can use a group to do this:
cairo_push_group(cr);
cairo_rectangle(cr, whatever);
do_the_arrow(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_stroke_preserve(cr);
cairo_fill(cr);
cairo_pop_group_to_source(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_paint();
(Note that this effectively halves the line width, because the inner
part of the line is overwritten by the latter fill).
Does this do what you want?
Cheers,
Uli
--
“Some people are worth melting for.” - Olaf
More information about the cairo
mailing list