[cairo] Negative clipping: solution for even-numbered overlaps of clipping regions?

Benjamin Redelings I benjamin_redelings at ncsu.edu
Wed May 27 07:18:28 PDT 2009


    Thanks for the cairo library!  It makes it fairly easy, in general,to generate SVG, PDF and other vector formats.

    My problem: I am trying to draw a collection of lines such that each thin line is clipped not to over-write a series of other very thick lines with round end caps.  It would be nice to just draw all the thin lines before all the thick lines that should not be over-written. However, it is unclear if such a total ordering exists -- I am not sure that there is such an ordering that matches my constraints.  Does that make sense?

    So instead of drawing thick lines on top of some of the thin lines, I am trying to do negative clipping: draw a thin line, except for the area where it would overlap with a collection of thick lines.   I am trying to do this using the often-recommended "make-a-donut" way: first make a *counter-clockwise* rectangle sub-path representing the device clipping extents, and then draw the regions that I want clipped as *clockwise* regions.

    Except that the different clipped regions overlap - and clipping a region an even number of times seems to UNclip it!  Therefore, I am
reduced to trying to approximate the overlap regions and trace them an additional time to make the overlaps even.  But, I don't have a general method of doing this, and so my approximation sometimes fails.  (I am drawing pictures based on input files, so I can't just hack a one-time solution, since I don't have one fixed picture.)

    So ... Can anyone recommend another way of doing negative clipping?  :-) 

    Thanks for listening!


P.S. I have attached some examples of the kind of drawing that I'm trying to make.  Some black lines ("thin lines") are supposed to attach to colored "clouds" (the "thick lines") and so I am trying to clip the black lines not to draw over the colored "cloud" to which they attach.

More information about the cairo mailing list