[cairo] Re: cairo_image_surface_create_for_data() args

Owen Taylor otaylor at redhat.com
Sun May 15 08:21:57 PDT 2005


On Fri, 2005-05-13 at 13:19 +0800, Steve Chaplin wrote:

> 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.

Do you think the other pairs there actually map to Python? While you
certainly could implement:

 def set_source (self, pattern_or_surface, dx=0, dy=0):
    if [pattern_or_surface is a pattern]: 
       if (dx != 0 or dy != 0):
           raise SomeError

It doesn't strike me as being natural Python or a particularly good
idea. The overloading pairs are designed more for a strongly typed
languages with overloads ... C++/Java/C#, say. My expectations would
probably be that the Python API would match the C API in this area.

Regards,
						Owen

P.S. - while the name of the section is "overloading and optional
       arguments", there is nothing about optional arguments in there
       I meant to say something, but didn't really common up with 
       any compelling use cases ... maybe cr.rel_move_to (dy=20)

-------------- 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.freedesktop.org/archives/cairo/attachments/20050515/5d0ac12f/attachment.pgp


More information about the cairo mailing list