[cairo] RFC: duplicating, storing and serializing drawing operations

Bill Spitzak spitzak at d2.com
Wed Dec 27 10:47:37 PST 2006


I think the original request can be satisfied with a new cairo backend. 
I'm not sure if this is possible with the current cairo implementation, 
if not I recommend cairo should be fixed so this *is* possible, whether 
or not such a backend is added to it.

I'll call it a "cairo_recorder". The api would be something like this:

cairo_t = cairo_recorder_create();
     creates a new recorder, with nothing in it

cairo_recorder_clear(cairo_t)
     restores it to the empty state

cairo_recorder_playback(cairo_t recorder, cairo_t destination)
     acts exactly as though all the calls send to the recorder since it
     was last cleared are sent to the destination.

cairo_recorder_save(filename)
cairo_recorder_load(filename)
     write/read a stream format. loading from a saved file will make the
     recorder have exactly the same contents as were in the saved one.
     (obviously there is also an api to allow different stream functions
     and not just filenames).

I don't think much else is needed. Notice that you can "save as pdf" by 
playing it back to a pdf cairo backend. I recommend the stream format be 
text, but highly compressed (ie not xml, and numbers printed with %g 
with leading zeros stripped). I suspect this can also be used to cut & 
paste graphics between Linux programs.

This is a tiny bit more difficult than what the original poster wanted, 
as they will have to watch for exposure events and cause the playback 
when they happen. But this is far easier than making his own structure 
to record the data, or using a canvas style object.

One annoyance is that due to all the calls to get data from Cairo, this 
can't be a simple recorder. It will have to emulate the path building 
and the fonts. Just ignore any problems with fonts not matching between 
the recorder and playback.


More information about the cairo mailing list