[cairo] Drawing points?

Carl Worth cworth at cworth.org
Fri Jun 19 09:51:17 PDT 2009

On Thu, 2009-06-18 at 14:07 -0300, Ian Britten wrote:
> Hi all,
> Is there a recommended way of drawing points with Cairo?


> I'm interfacing with traditional pen/pixmap drawing techniques, and
> am trying to find an optimal match to how some toolkits expect to
> be able to draw points.  Specifically:
> - The cap style controls whether the point is a dot or square.
> - The lineweight controls the radius/size of the point.
> - The resulting box/circle is centred over the given point.
> I can probably kludge something together with combinations of
> cairo_arc()/cairo_rectangle()/etc, but I'm not sure if that'd be
> optimal - Both in terms of performance, and for what the various
> backends could support natively for drawing points.

Here's an easier approach:

	cairo_move_to (cr, x, y);
	cairo_close_path (cr);
	/* repeat for each point */

	cairo_stroke (cr);

If that idiom seems odd, here's another:

	cairo_move_to (cr, x, y);
	cairo_line_to (cr, x, y);
	/* repeat for each point */

	cairo_stroke (cr);

Within the implementation (and test suite) we call these "degenerate"
paths and we explicitly support drawing round caps for such degenerate
paths. So this should work perfectly for the case of
CAIRO_LINE_CAP_ROUND and you'll get the diameter controlled by
cairo_set_line_width just like you want.

However, I believe that we have specified that degenerate paths do not
draw anything in the case of CAIRO_LINE_CAP_SQUARE. The problem their is
that there's ambiguity as to what direction the square caps should be
drawn in. (Contrast this with the case of stroking a dashed line with
square caps and a dash pattern with a zero-length "on" section. In that
case, we do have direction information and we do draw the caps.)

It might be desirable to draw axis-aligned squares in the case of
stroking degenerate paths with square caps, and one could argue that
this is what cairo should do. But so far we've opted not to do that.

I'd definitely be open for more opinions on this. It's good for us to
strengthen our rationale for various decisions. And obviously we need to
document some of these idioms more completely.

Have fun with cairo,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.cairographics.org/archives/cairo/attachments/20090619/ed5ed95a/attachment-0001.pgp 

More information about the cairo mailing list