[Sugar-devel] TA cairo conversion

Benjamin Berg benzea at sugarlabs.org
Sat Nov 5 09:15:19 EDT 2011


Hello,

On Sat, 2011-11-05 at 08:56 -0400, Walter Bender wrote:
> I pushed a few more patches last night [1]. I have just two blockers
> right now to releasing the Cairo version:
> 
> (1) I cannot seem to figure out how to convert my surface to a pixbuf
> or png for saving to a file;
>         surface = canvas.canvas.get_target()  # get the surface used
> by the canvas
>         surface.cairo_surface_write_to_png(file_name)  <--- fails
> because XlibSurface doesn't have a cairo_surface_write_to_png
> attribute

What you can do is the following:
 1. x_surface = canvas.canvas.get_target()
 2. Create an image surface:
    img_surface = cairo.ImageSurface(...)
 3. Create a context:
    cr = cairo.Context(img_surface)
 4. cr.set_source_surface(x_surface)
 5. cr.paint()
 6. img_surface.write_to_png(file_name)

This way you can download the image data from the X server, and store it
inside the applications memory. After this it can be written out to a
file.

> (2) I cannot seem to create the proper surface from a Pixbuf to use in
> non-interactive mode in replacement of the canvas surface. I have
> unsuccessfully tried to create a pixbuf and use it to source a cairo
> context.

The pixel format that cairo uses, and the one that Gdk.Pixbuf uses is
differs.  If I understand correctly, what you want to do is to create an
cairo.ImageSurface instead of the create_similar call.

> The only non-blockers are:
> (1) I am struggling with the erratic behavior of rotate on bitmaps. It
> is disabled at the moment.
> (2) There must be some way to cache the surfaces used by the sprites
> instead of re-rendering them from pixbufs each time, but using
> get_target() gives X errors.

Hm, I can't say anything about these of the top of my head.

Benjamin



More information about the Sugar-devel mailing list