[cairo] Drawing to multiple surfaces, "cairo_recorder", zoom (was: Some newbie question)

Dirk Schönberger dirk.schoenberger at sz-online.de
Fri Dec 14 14:22:31 PST 2007


> - Say an application draws to a window and optionally, if a user would
like to, it exports the drawing to PDF. How? If I understood Carl's
> recommendation correctly -- to use "data structures [which] know how to
'draw themselves' given a cairo context -- I probably could write
> some dummy drawing functions (lineto, circle, stroke, ...) which would
just record [1] the drawing operations (and serialize to disk, e.g. in a
> text file). Later, I could parse that file and execute the real drawing
function of a given surface. Does it make sense to you?

Yes. Basically this is a metafile.
The only difference between a real metafile and Carls recommendation is that
a cairo metafile would have all cairo operations as data structures, while
the other attempt would use application specific data structures, say,
vector path definitions, transformation matrizes, fill patterns (solid
colours, gradients etc)

> - And a bit off topic, how does a zoom work? I mean, say there's a GTK
window and I draw to it. Since it is raster now I can't really scale it,
> right? So I have to redraw it at the new scale, right? How, because all
the drawing operations are lost now since I draw a raster image in the >
first place? Could a recording from the previous question be of some help?

Yes, the recording could be of some help. Basically you could do something
like

cairo_save()
caito_scale(cr, 2.0, 2.0); // set the scale factor
// replay the recorded sequence
cairo_restore();

Possibly the calls should be something like cairo_push_group and
cairo_pop_group, because cairo_save and cairo_restore don't save/restore the
full context.

Regards
Dirk









More information about the cairo mailing list