[cairo] Switching dashes on and then off

Chris Wilson chris at chris-wilson.co.uk
Thu Apr 22 15:20:39 PDT 2010

On Thu, 22 Apr 2010 21:37:27 +0100, Alan Battersby <alan.battersby at ntlworld.com> wrote:
> I am using mono and Cairo in c# to draw some paths (my terminology not
> Cairo paths) which are a list of vertices. I want visible vertices to be
> connected by solid lines and hidden vertices to be connected by dashed
> lines. Thus the path will switch between solid and dashed as the path
> becomes hidden behind something and then reappears. The states ENTER and
> XIT are where the path meets and leaves the area hiding it. I use these
> values to colour the nodes if that option is chosen.
> I cannot seem to get the type of behavior I want using the code below.
> Can someone please tell me what I am doing wrong.
> Thanks
> Alan
> double[] empty = new double[]{};
> double[] dash  = new double[]{2,2};
> void switchDashOn(bool on,Cairo.Context ct)
> {
> 	ct.StrokePreserve();

I would say this is the cause. Try ct.Stroke(); instead.
The Preserve is causing the path not to be flushed on state change, so you
continue to append to the existing path and so stroke the full path up to
this point with the current dash state.

Also experiment, with iterating over the path twice, once for dashed
vectors and the other for undashed. It is not immediately obvious which
will be faster - both methods have circumstances in which they will
outperform the other.

Chris Wilson, Intel Open Source Technology Centre

More information about the cairo mailing list