[cairo] Re: cairo_image_surface_create_for_data() args

Steve Chaplin stevech1097 at yahoo.com.au
Tue May 17 06:52:27 PDT 2005


On Sun, 2005-05-15 at 11:21 -0400, Owen Taylor wrote:
> 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.

It doesn't look like very natural Python so it may be best not to do any
of the overloading.
If cairo_image_surface_create() and cairo_image_surface_create_for_data
() had the same argument order then it could be treated as a case of
optional arguments, and should work.

cairo.ImageSurface(format, width, height, data=None, stride=None)

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

Optional arguments is something that Python can support.
How about cr.set_source_rgba(r,g,b,a=1.0)
Then cr.set_source_rgb(r,g,b) is not even needed is it?

Other possibilities?
cr.Matrix(xx=1.0,yx=0.0,xy=0.0,yy=1.0,x0=0.0,y0=0.0)

cr.paint(alpha=1.0)

cr.select_font_face(family, slant=cairo.FONT_SLANT_NORMAL,
                    weight=FONT_WEIGHT_NORMAL)

cr.set_dash(dash_list, offset=0.0)

Steve





More information about the cairo mailing list