I have some code that looks like this:
cairo_surface_t * surface = cairo_svg_surface_create("0.svg", 512, 512);
cairo_t * context = cairo_create(surface);
int * data = new int[512*512];
// fill the data...
cairo_surface_t * image_surface =
cairo_image_surface_for_data(data, 512, 512, 512*4);
cairo_set_source_surface(context, image_surface, 0, 0);
cairo_paint(context);
// do some other drawing ...
cairo_surface_flush(surface);
cairo_surface_finish(surface);
cairo_surface_destroy(surface);
cairo_destroy(context);
However, the svg always appears corrupted. The image is not properly written, and all drawing commands following do not work. Changing the surface type to PS, ie:
cairo_surface_t * surface = cairo_ps_surface_create("0.ps", 512, 512);
produces a perfectly correct PS document. Any help fixing the SVG would be appreciated.
EDIT: Forgot to provide version info. Cairo 1.10.2 as given by cairo_version_string(). g++ 4.52 Running on Ubuntu 11.04
EDIT(2): Ok, I have traced this down to PNG problems with cairo and discovered that cairo_surface_write_to_png does not behave as expected either. Both this function and attempting to embed an image in an SVG cause "out of memory errors", and I still don't know why.
CAIRO_SVG_VERSION_1_1
. On the PNG issue, can youcairo_image_surface_create_from_png()
and then write the surface back to a new PNG and have the file be corrupt? Or does this work properly? – Onstad