[cairo] Re: cairo_image_surface_create_for_data() args

Steve Chaplin stevech1097 at yahoo.com.au
Thu May 12 22:19:20 PDT 2005


On Thu, 2005-05-12 at 12:00 -0700, cairo-request at cairographics.org
wrote:
> [ https://bugs.freedesktop.org/show_bug.cgi?id=3277 ]
> 
> This is something that has been bothering me recently:
> 
> cairo_surface_t *
> cairo_image_surface_create (cairo_format_t      format,
>                             int                 width,
>                             int                 height);
> 
> cairo_surface_t *
> cairo_image_surface_create_for_data (unsigned char             *data,
>                                      cairo_format_t             format,
>                                      int                        width,
>                                      int                        height,
>                                      int                        stride);
> 
> While I can see why you'd order the create_for_data() args in that
> order if it was an independent function, as a variant of _create(),
> adding one arg before and one after is just really peculiar.
> 
> If both args were after, then it would fit well into a 
> "optional arguments" pattern.
> 
> Worth an incompatible API change? I don't know.
> 
>   				                    Owen

This relates to the Appendix "Creating a language binding for cairo" that 
Owen wrote recently. 
Carl have you had a chance to read the section "Overloading and optional 
arguments", and do you agree with the list given?

cairo_image_surface_create() and cairo_image_surface_create_for_data()
are given as recommended candidates for overloading.

A language binding could create an overloaded constructor:
	surface = cairo.ImageSurface(format, width, height)
	surface = cairo.ImageSurface(format, width, height, data, stride)

Overloading the constructor is much easier (at least in Python) if the 
argument orders match.
I think cairo.ImageSurface is a good candidate for overloading, but mainly
I'd like cairo to be self-consistent, so I'd prefer:

1) If the pair are recommended for overloading then make it easier to
do so by reordering the arguments to cairo_image_surface_create_for_data().
or
2) If the pair are not recommended for overloading then remove them
from the "Overloading and optional arguments" page.

Steve





More information about the cairo mailing list