[cairo] stroke extents after scaling and rotation

Theo Veenker Theo.Veenker at let.uu.nl
Tue Jun 10 06:46:17 PDT 2008


Hi,

Regarding this thread:
http://lists.cairographics.org/archives/cairo/2008-May/014207.html

I found out I did something wrong in the test program there. I've
changed it to the code below. This does work as expected, but when
the target path is scaled > 1 then the stroke extents don't quite
follow the ink. As demonstrated in the attached images. For the
the horizontal line case and the vertical line case the y resp x
extents are one line width too small.

// gcc -o extents2 $(pkg-config --cflags --libs cairo) extents2.c
#include <cairo.h>
#include <math.h>

int main()
{
     cairo_surface_t *surface;
     cairo_t *cr;
     double x1, y1, x2, y2;
     int n;

     double offsetx = 60, offsety = 60;
     double scalex = 1.0, scaley = 1.0;
     double rotangle = 0.0 / 360.0 * M_PI;

     surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 620, 220);
     cr = cairo_create(surface);

     cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
     cairo_paint(cr);

     for (n = 0; n < 12; n++) {
     	rotangle = n * 30.0 / 360.0 * M_PI;
	cairo_save(cr);
	cairo_translate(cr, offsetx, offsety);
	cairo_scale(cr, scalex, scaley);
	cairo_rotate(cr, rotangle);
	cairo_move_to(cr, -25, 0);
	cairo_line_to(cr, 25, 0);
	cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
	cairo_set_line_width(cr, 10);
	cairo_stroke(cr);
	cairo_restore(cr);

	cairo_save(cr);
	cairo_save(cr);
	cairo_translate(cr, offsetx, offsety);
	cairo_scale(cr, scalex, scaley);
	cairo_rotate(cr, rotangle);
	cairo_move_to(cr, -25, 0);
	cairo_line_to(cr, 25, 0);
	cairo_restore(cr);
	cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
	cairo_set_line_width(cr, 10);
	cairo_stroke_extents(cr, &x1, &y1, &x2, &y2);
	cairo_restore(cr);

	cairo_save(cr);
	cairo_new_path(cr);
	cairo_rectangle(cr, x1, y1, x2-x1, y2-y1);
	cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
	cairo_set_line_width(cr, 0.5);
	cairo_stroke(cr);
	cairo_restore(cr);

     	offsetx += 100;
	if (n == 5) {
	    offsety += 100;
     	    offsetx = 60;
	}
     }

     cairo_destroy(cr);

     cairo_surface_write_to_png(surface, "extents.png");
     cairo_surface_destroy(surface);

     return 0;
}

Could this be a bug or do I still not get it?

Regards,
Theo

-------------- next part --------------
A non-text attachment was scrubbed...
Name: extents-scaled.png
Type: image/png
Size: 14399 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080610/b3ee922b/attachment-0002.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: extents-unscaled.png
Type: image/png
Size: 8715 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080610/b3ee922b/attachment-0003.png 


More information about the cairo mailing list