[cairo] Path_extents after coordinate system is rotated.

Stefan Salewski mail at ssalewski.de
Tue Apr 7 17:38:09 PDT 2015


I tried to fill polygons or curves with mesh or hatch pattern. Basically
that works, but while cleaning up my code I discovered that
cairo_path_extents gave me a larger area as expected -- which is not a
big problem for my case, because I used clipping. Following code
generates this picture:

http://ssalewski.de/tmp/image.png

Is that the expected result? My expectation was a smaller rectangle from
path_extents().

// gcc test.c -o test `pkg-config --cflags --libs gtk+-3.0`
#include <cairo.h>

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

  surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 400, 400);
  cr = cairo_create(surface);
  cairo_set_source_rgb(cr, 1, 1, 1);
  cairo_paint(cr);
  cairo_set_source_rgb(cr, 0, 0, 0);
  cairo_set_line_width(cr, 4);
  cairo_move_to(cr, 300, 200);
  cairo_line_to(cr, 300, 300);
  cairo_line_to(cr, 250, 250);
  cairo_stroke_preserve(cr);
  cairo_save(cr);
  cairo_rotate(cr, 0.8);
  cairo_path_extents(cr, &x1, &y1, &x2, &y2);
  cairo_new_path(cr);
  cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
  cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1);
  cairo_stroke(cr);
  cairo_restore(cr);
  cairo_surface_write_to_png(surface, "image.png");
  cairo_destroy(cr);
  cairo_surface_destroy(surface);
  return 0;
}



More information about the cairo mailing list