[cairo] svg rendering problem: svg_cairo_render() returns SVG_STATUS_NO_MEMORY

ml.user at op.pl ml.user at op.pl
Sun Nov 13 23:03:03 PST 2005


Hi,

I'm using Cairo 1.0.2 with libsvg 0.1.4, libsvg-cairo 0.1.6 on Linux, Debian Woody. I have problem with rendering some svg. When I try render svg, which is saved in attached file 1.svg, render fail. When I render svg saved in attached file 2.svg, rendering ends succesfully. 

I use to render this code (code with no meaning for Cairo was removed
for clarity):

    int imageWidth = 1600;
    int imageHeight = 1200;
    
    //...
    
    size_t newArraySize = 4 * imageWidth * imageHeight; //format RGBA
    unsigned char* imageArray = new unsigned char[newArraySize];

    if(!imageArray) {
      imageArraySize = 0;
      return false;
    }
    
    //...
    
    cairo_status_t cairo_operation_status;
  
    //create new surface
    cairo_surface =  cairo_image_surface_create_for_data(imageArray, 
      CAIRO_FORMAT_ARGB32, imageWidth, imageHeight, imageWidth * 4);
      
    cairo_operation_status = cairo_surface_status(cairo_surface);
    if(cairo_operation_status != CAIRO_STATUS_SUCCESS) {
      cerr << "cairo_image_surface_create_for_data() failed: "
         << cairo_status_to_string(cairo_operation_status) << "\n"
	 << __FILE__ << ":" << __LINE__
	 << endl;
      
      //...
      return false;
    }

    cairo_context = cairo_create(cairo_surface);
    if(cairo_operation_status != CAIRO_STATUS_SUCCESS) {
      cerr << "cairo_create() failed: "
         << cairo_status_to_string(cairo_operation_status) << "\n"
	 << __FILE__ << ":" << __LINE__
	 << endl;
      //...
      return false;
    }

    //...
    cairo_save(cairo_context);
    
    cairo_identity_matrix(cairo_context);
    cairo_scale(cairo_context, 227, 371); 
    cairo_translate(cairo_context, -17.5, 53.5);
    
    //...
    svg_cairo_t* svg_cairo_context;
    svg_cairo_status_t svg_status = svg_cairo_create (&svg_cairo_context);
    if(svg_status != SVG_CAIRO_STATUS_SUCCESS) {
      cerr << "svg_cairo_create" << svg_status_to_string(svg_status) << endl;
      
      //...
      return false;
    }
    
    std::string svgBuffer = ...//svg content from file 1.svg or 2.svg
    
    svg_status = svg_cairo_parse_buffer(svg_cairo_context, svgBuffer.c_str(),
      svgBuffer.size());
    if(svg_status != SVG_CAIRO_STATUS_SUCCESS) {
      cerr << "svg_cairo_parse_buffer" << svg_status_to_string(svg_status) << endl;
      
      //...
      return false;
    }

    svg_status = svg_cairo_render(svg_cairo_context, cairo_context);
    if(svg_status != SVG_CAIRO_STATUS_SUCCESS) {
      cerr << "svg_cairo_render" << svg_status_to_string(svg_status) << endl;
      
      //...
      return false;
    }

    cairo_restore(cairo_context);
    cairo_surface_flush(cairo_surface);

    //... code, that display image from imageArray
    
    //cleaning
    svg_cairo_destroy (svg_cairo_context);
    cairo_destroy(cairo_context);
    cairo_surface_destroy(cairo_surface);
    
    delete[] imageArray;
    imageArray = NULL;
    
    return true;

Files 1.svg, 2.svg parse successfully. File 2.svg renders successfully and
displays. When I render svg from file 1.svg, function svg_cairo_render()
ends with code SVG_STATUS_NO_MEMORY, but when I trace memory usage with top, lot of memory is avaible. 

I know that svg from file 1.svg is more complex than svg from file 2.svg,
but these two files renderd OK, when I used cairo 0.5.1. When I have to change cairo to version 1.0.2, I discovered this problem. Can someone tell me, what I do wrong, or what to do for render this kind of svg's successfully using cairo 1.0.2 ?

Thanks in advance for help  
--
Robert,
Beginer cairo user
ml.user at op.pl

   
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1.svg.tgz
Type: application/x-gzip-compressed
Size: 26448 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20051114/01b784c3/1.svg-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2.svg.tgz
Type: application/x-gzip-compressed
Size: 20443 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20051114/01b784c3/2.svg-0001.bin


More information about the cairo mailing list