#include #include #include static cairo_status_t _cairo_write_func (void *closure, const unsigned char *data, unsigned int length) { size_t result; FILE *file = (FILE*) closure; result = fwrite (data, 1, length, file); return (result == length) ? CAIRO_STATUS_SUCCESS : CAIRO_STATUS_WRITE_ERROR; } void main () { int i; FILE *f = fopen ("test.svg", "w"); cairo_surface_t *svg = cairo_svg_surface_create_for_stream (_cairo_write_func, f, 20., 50.); cairo_surface_t *buf = cairo_surface_create_similar (svg, CAIRO_CONTENT_COLOR_ALPHA, 10., 10.); cairo_t *cr = cairo_create (buf); cairo_move_to (cr, 1., 1.); cairo_line_to (cr, 9., 9.); cairo_stroke (cr); cairo_destroy (cr); cr = cairo_create (svg); for (i = 0; i < 4; i++) { cairo_set_source_surface (cr, buf, 5., 5. + i * 10.); cairo_paint (cr); } cairo_destroy (cr); cairo_surface_destroy (buf); cairo_surface_destroy (svg); fclose (f); }