[cairo] unbounded recording surface

Vojtech Fried vfried at opentext.com
Wed Mar 9 00:44:16 PST 2011


Hi,

My use case is to determine the size of some rendering and then create an image with the determined size. I thought that unbounded (NULL extents) recording surface is exactly the way to go. A code like below however didn't work. (I think https://bugs.freedesktop.org/show_bug.cgi?id=31657 is related)

recording_surf = cairo_recording_surface_create( CAIRO_CONTENT_COLOR_ALPHA, NULL );
recording_ctx = cairo_create( recording_surf );
cairo_scale( recording_ctx, m_dpi_x_ratio, m_dpi_y_ratio );
...do the rendering...
cairo_recording_surface_ink_extents( recording_surf, &x, &y, &w, &h );
image_surf = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, w, h );
image_ctx = cairo_create( image_surf );
cairo_set_source_surface( image_ctx, recording_surf, x, y );
cairo_paint( image_ctx );

During the paint cairo wanted to create a huge (unbounded) image and it failed. What helped me was the following hack.

cairo_rectangle_t rect;
rect.x = x;
rect.y = y;
rect.width = w - x; //not sure why there has to be -x and -y
rect.height = h - y;
recording_surf_dummy = cairo_recording_surface_create( CAIRO_CONTENT_COLOR_ALPHA, &rect );
cairo_recording_surface_t* recording_surf_dummy_( (cairo_recording_surface_t*)recording_surf_dummy );
cairo_recording_surface_t* recording_surf_( (cairo_recording_surface_t*)recording_surf );
recording_surf_->extents = recording_surf_dummy_->extents;
recording_surf_->extents_pixels = recording_surf_dummy_->extents_pixels;
recording_surf_->unbounded = recording_surf_dummy_->unbounded;

Still I get some small differences between the replayed output and an output directly to image surface without recording surface (and with some arbitrary hardcoded size).

Vojtech

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20110309/2ec98b11/attachment.html>


More information about the cairo mailing list