[cairo] Re: Language binding appendix

Steve Chaplin stevech1097 at yahoo.com.au
Mon May 9 02:52:26 PDT 2005


On Sun, 2005-05-08 at 13:35 -0700, cairo-request at cairographics.org
wrote:
>  - The suggested cairo_path_t API is perhaps an uncomfortable
>    compromise between specifying it and leaving it up to the 
>    language binding. It might be better to nail down a a fixed
>    iterator API rather than saying "make it match the language
>    binding's iterators".

I implemented path iterators for Pycairo today.

For Python, Appendix A recommended

for element in cr.copy_path():
    if element.getType == cairo.PATH_ELEMENT_MOVE_TO:
        (x, y) = element.getPoint(0)
        doMoveTo (x, y)

1) Instead of element.getPoint(0), element.getPoint(1), element.getPoint(2)
   I think its simpler to use element.getpoints() to return all a tuple of 
   points relevant to the element type - (), (x,y) or (x1,y1,x2,y2,x3,y3)

2) Instead of returning an element object, with a getType attribute and 
   a getPoint() method, I'd prefer to return element as a (type, points) 
   tuple. Its makes it easier to write the python extension since you
   don't need to create an custom element object, and I think its gives
   a simpler interface.
   
The hypothetical Python loop would then be:

for type, points in cr.copy_path():
    if type == cairo.PATH_ELEMENT_MOVE_TO:
        x, y = points
        doMoveTo (x, y)

This is the way it currently works in cvs.

Steve





More information about the cairo mailing list