[cairo] API Shakeup: cairo_current_matrix

Carl Worth cworth at redhat.com
Tue Feb 15 15:09:26 PST 2005


On Thu, 04 Nov 2004 14:39:13 -0500, Owen Taylor wrote:
> I'm not sure this is a problem. The rule is basically that if
> you call a function that returns a pointer to a non-copied object,
> string, etc, that pointer can't be saved, just used immediately.
> 
>  old_matrix = cairo_current_matrix (cr);
>  cairo_set_matrix (cr, new_matrix);
>  do_something_with (old_matrix);

We discussed some aspects of this last night. The convention we
decided on for cairo is that any "getters" that return pointers will
not copy, nor will they take a reference to the object. This makes
these functions easy to use, (no freeing necessary).

As far as fixing the problem above, an easy thing to do is to just
expose a transparent data type for cairo_matrix_t.

We didn't discuss last night what the datatype would actually look
like, but I propose that a struct will be easier to use than an
array. And as for naming the members of the struct, I like the names
used by pango, (which also match the names in the 4-element matrix
definitions of fontconfig and freetype). This give us:

	/*
	x_device = x_user * matrix.xx + y_user * matrix.xy + matrix.x0;
	y_device = x_user * matrix.yx + y_user * matrix.yy + matrix.y0;
	*/

	typedef struct _cairo_matrix {
	    double xx;
	    double xy;
	    double yx;
	    double yy;
	    double x0;
	    double y0;
	};

The order of the members of the struct is a little funny, but I think
other possibilities are worse. The right answer is probably to just
initialize with the member names and ignore the order within the
struct.

-Carl



-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050215/c25cfb4f/attachment.pgp


More information about the cairo mailing list