[cairo] Adding polygons

cairouser at yahoo.com cairouser at yahoo.com
Wed May 30 17:05:54 UTC 2018


Hi,

We implemented a similar approach earlier using clip areas - the resulting image did not look too great.
Following your suggestion and drawing the outlines, then filling works much better.
It's a bit counter-intuitive, as we do need to double the line width and slightly reduce the object size.

But it works, so all good!
Cheers!

On 5/30/18 1:30 AM, Uli Schlachter wrote:
> 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



More information about the cairo mailing list