[cairo] API Shakeup: cairo_output_stream_t and cairo_surface_finish()

Kristian Høgsberg krh at bitplanet.net
Thu Feb 24 14:56:37 PST 2005


Jost Boekemeier wrote:
>>This assumes that the code that creates the surface
>>will also call 
>>finish on it, like this:
>>
>>	data = malloc (sizeof Stuff);
>>	cr = cairo_pdf_surface_create (write, destroy,
>>data);
>>	draw_stuff (cr);
>>	cairo_surface_finish (cairo_get_target_surface
>>(cr));
>>	cairo_destroy (cr);
>>	free (data);
> 
> 
> I am probably missing the context, but the way I
> understood your proposal is that you want to change
> the FILE* into a cairo type.  This is something I need
> too, because I can't pass a FILE.

OK, here's what I'm thinking: Suppose your languange binding (say, 
Python) takes a python file object in the constructor.  Your wrapper 
code needs to add a reference to the file object and drop the reference 
once it's done writing to the file, that is, when cairo_surface_finish() 
is called.

This can also be done by setting the python file object as user data on 
the surface and retrieving that user data in the write callback.  The 
user data destroy callback would then unref the python file object. It's 
a bit awkward but it would work.  The difference is that in this case 
the python file object isn't unreffed until the surface is destroyed.  I 
think it's a nice property that the write function closure is actually 
freed when you call cairo_surface_finish().

cheers,
Kristian



More information about the cairo mailing list