[cairo] Dealing with unbounded surfaces

cecashon at aol.com cecashon at aol.com
Thu Apr 30 22:00:47 UTC 2020


 
Cairo can get the width and height of the inked part of a drawing which makes the drawing easy to position in another surface. This will work with a bounded or unbounded recording surface.

If the recording surface is unbounded and the background gets painted... then it isn't going to make much sense.

If the recording surface is bounded and the background is painted, then the ink extents will be the surface bounds.

To get the extents of the inked drawing, don't paint the recording surface background. Try something like the following.

Eric

//Paint the background white in recording surface.
//cairo_set_source_rgba(cr1, 1.0, 1.0, 1.0, 1.0);
//cairo_paint(cr1);

...
cairo_line_to(cr1, 200.0, 0.0);
cairo_stroke(cr1); 

//Set drawing extents box.
double x, y, extents_x, extents_y;
cairo_set_source_rgba(cr1, 1.0, 0.0, 1.0, 1.0); 
cairo_recording_surface_ink_extents(surface1, &x, &y, &extents_x, &extents_y);
printf("%f %f %f %f\n", x, y, extents_x, extents_y);
cairo_rectangle(cr1, x, y, extents_x, extents_y);
cairo_stroke(cr1);
...
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20200430/dc3e6fba/attachment.htm>


More information about the cairo mailing list