get bounded box using cairo_stroke_extents

Submitted by Lawrence D'Oliveiro on Feb. 21, 2016, 10:55 p.m.

Details

Message ID 20160222115541.11dc5107@theon.geek-central.gen.nz
State New
Headers show
Series "get bounded box using cairo_stroke_extents" ( rev: 1 ) in Cairo

Not browsing as part of any series.

Commit Message

Lawrence D'Oliveiro Feb. 21, 2016, 10:55 p.m.
On Sat, 20 Feb 2016 23:52:30 -0700, Mark Olesen wrote:

> I am trying to get the bounded box using cairo_stroke_extents
> (cairo_fill_extents has similar issue). I wind up with x1 being
> way off. The rest look okay. I have attached a png. The blue
> rectangle is the bounds box. Any suggestions?

It makes more sense if you do cairo_restore before trying to get the
extents. Here is the patch I made, and attached is the patched source
and the PNG output.

Patch hide | download patch | download mbox

diff -u stroke_extents.c{-orig,}
--- stroke_extents.c-orig       2016-02-22 11:53:06.963033270 +1300
+++ stroke_extents.c    2016-02-22 11:53:46.594795711 +1300
@@ -1,7 +1,8 @@ 
-#include <cairo.h>
 #include <math.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <cairo/cairo.h>
 
 int
 main (int argc, char *argv[])
@@ -37,10 +38,11 @@ 
   cairo_translate(cr, -50., -20.); // *Lawrence D'Oliveiro tip*
   cairo_set_source_rgb(cr, 0., 0., 0.);
   cairo_stroke_extents(cr, &x1, &y1, &x2, &y2);
-  cairo_stroke(cr);
+  printf("(%lf, %lf) (%lf,%lf)\n", x1, y1, x2, y2);
   cairo_restore(cr);
-
+  cairo_stroke_extents(cr, &x1, &y1, &x2, &y2);
   printf("(%lf, %lf) (%lf,%lf)\n", x1, y1, x2, y2);
+  cairo_stroke(cr);
 /*
 x1 is way off
 (-1.500000, 19.500000) (151.500000,70.500000)

Comments

That's wicked. Your changes make the bounding box perfect. Thanks for the
help Lawrence.

On Sun, Feb 21, 2016 at 3:55 PM, Lawrence D'Oliveiro <
ldo@geek-central.gen.nz> wrote:

> On Sat, 20 Feb 2016 23:52:30 -0700, Mark Olesen wrote:
>
> > I am trying to get the bounded box using cairo_stroke_extents
> > (cairo_fill_extents has similar issue). I wind up with x1 being
> > way off. The rest look okay. I have attached a png. The blue
> > rectangle is the bounds box. Any suggestions?
>
> It makes more sense if you do cairo_restore before trying to get the
> extents. Here is the patch I made, and attached is the patched source
> and the PNG output.
>
> diff -u stroke_extents.c{-orig,}
> --- stroke_extents.c-orig       2016-02-22 11:53:06.963033270 +1300
> +++ stroke_extents.c    2016-02-22 11:53:46.594795711 +1300
> @@ -1,7 +1,8 @@
> -#include <cairo.h>
>  #include <math.h>
>  #include <string.h>
>  #include <stdlib.h>
> +#include <stdio.h>
> +#include <cairo/cairo.h>
>
>  int
>  main (int argc, char *argv[])
> @@ -37,10 +38,11 @@
>    cairo_translate(cr, -50., -20.); // *Lawrence D'Oliveiro tip*
>    cairo_set_source_rgb(cr, 0., 0., 0.);
>    cairo_stroke_extents(cr, &x1, &y1, &x2, &y2);
> -  cairo_stroke(cr);
> +  printf("(%lf, %lf) (%lf,%lf)\n", x1, y1, x2, y2);
>    cairo_restore(cr);
> -
> +  cairo_stroke_extents(cr, &x1, &y1, &x2, &y2);
>    printf("(%lf, %lf) (%lf,%lf)\n", x1, y1, x2, y2);
> +  cairo_stroke(cr);
>  /*
>  x1 is way off
>  (-1.500000, 19.500000) (151.500000,70.500000)
>
> --
> cairo mailing list
> cairo@cairographics.org
> https://lists.cairographics.org/mailman/listinfo/cairo
>