<div dir="ltr"><div><div><div>I am trying to get the bounded box using cairo_stroke_extents <br></div>(cairo_fill_extents has similar issue). I wind up with x1 being<br></div>way off. The rest look okay. I have attached a png. The blue<br></div><div>rectangle is the bounds box. Any suggestions? <br><br></div><div>Thanks in advance.<br></div><div><div><div><div><br>#include <cairo.h><br>#include <math.h><br>#include <string.h><br>#include <stdlib.h><br><br>int<br>main (int argc, char *argv[])<br>{<br> cairo_surface_t* cs;<br> cairo_t *cr;<br> double angle;<br> double skewx;<br> cairo_matrix_t matrix;<br> double x1, x2, y1, y2;<br><br> cs= cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 180.,100.);<br> cr= cairo_create(cs);<br><br> cairo_set_line_width(cr, 1.);<br><br> cairo_save(cr);<br> cairo_set_source_rgb(cr, 1., 0., 0.);<br> cairo_rectangle(cr, 50., 20., 50., 50.);<br> cairo_stroke(cr);<br> cairo_restore(cr);<br><br> cairo_save(cr);<br> angle= 45.;<br> skewx= tan(angle * M_PI / 180.);<br> cairo_matrix_init(<br> &matrix,<br> 1.0, 0.0,<br> skewx, 1.0,<br> 50.0, 20.0);<br> cairo_transform(cr, &matrix);<br> cairo_rectangle(cr, 0., 0., 50., 50.);<br> cairo_translate(cr, -50., -20.); // <a name="27279"></a>
<i>Lawrence D'Oliveiro tip</i><br> cairo_set_source_rgb(cr, 0., 0., 0.);<br> cairo_stroke_extents(cr, &x1, &y1, &x2, &y2);<br> cairo_stroke(cr);<br> cairo_restore(cr);<br><br> printf("(%lf, %lf) (%lf,%lf)\n", x1, y1, x2, y2);<br>/*<br></div><div>x1 is way off<br></div><div>(-1.500000, 19.500000) (151.500000,70.500000)<br>*/<br> cairo_set_source_rgb(cr, 0., 0., 1.);<br> cairo_rectangle(cr, x1, y1, x2-x1, y2-y1);<br> cairo_stroke(cr);<br><br> cairo_surface_write_to_png(cs, "skew.png");<br><br> cairo_destroy(cr);<br> cairo_surface_destroy(cs);<br><br> return 0;<br>}<br></div></div></div></div></div>