[cairo-commit] cairo/src cairo.c,1.27,1.28 cairo.h,1.28,1.29 cairo_gstate.c,1.31,1.32 cairo_path.c,1.9,1.10 cairo_traps.c,1.11,1.12 cairoint.h,1.38,1.39

Carl Worth commit at pdx.freedesktop.org
Thu Nov 6 18:33:30 PST 2003


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory pdx:/tmp/cvs-serv18990/src

Modified Files:
	cairo.c cairo.h cairo_gstate.c cairo_path.c cairo_traps.c 
	cairoint.h 
Log Message:

        * configure.in (CAIRO_VERSION): Bumped version to 0.1.12 for new
        cairo_in_stroke and cairo_in_fill functions.

        * src/cairo.h:
        * src/cairo.c (cairo_in_stroke):
        (cairo_in_fill): Added new cairo_in_stroke and cairo_in_fill.

        * src/cairo_traps.c (_cairo_trap_contains):
        (_cairo_traps_contain): * src/cairo_gstate.c
        (_cairo_gstate_in_stroke):
        (_cairo_gstate_in_fill): New functions to support for
        cairo_in_stroke and cairo_in_fill. Many thanks to Thomas Hunger
        <info at teh-web.de> for the initial implementation which
        demonstrated how easy this would be and pushed me to go and write
        it already.

        * src/cairo_gstate.c (_cairo_gstate_clip_and_composite_trapezoids):
        * src/cairo_traps.c (_line_segs_intersect_ceil):
        * src/cairo_path.c (_cairo_path_move_to):
        (_cairo_path_line_to):
        (_cairo_path_curve_to): Fixed to use _cairo_fixed_from_double
        instead of XDoubleToFixed.


Index: cairo.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** cairo.c	6 Nov 2003 21:32:15 -0000	1.27
--- cairo.c	7 Nov 2003 02:33:28 -0000	1.28
***************
*** 602,605 ****
--- 602,637 ----
  }
  
+ int
+ cairo_in_stroke (cairo_t *cr, double x, double y)
+ {
+     int inside;
+ 
+     if (cr->status)
+ 	return 0;
+ 
+     cr->status = _cairo_gstate_in_stroke (cr->gstate, x, y, &inside);
+ 
+     if (cr->status)
+ 	return 0;
+ 
+     return inside;
+ }
+ 
+ int
+ cairo_in_fill (cairo_t *cr, double x, double y)
+ {
+     int inside;
+ 
+     if (cr->status)
+ 	return 0;
+ 
+     cr->status = _cairo_gstate_in_fill (cr->gstate, x, y, &inside);
+ 
+     if (cr->status)
+ 	return 0;
+ 
+     return inside;
+ }
+ 
  void
  cairo_clip (cairo_t *cr)

Index: cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** cairo.h	6 Nov 2003 20:53:39 -0000	1.28
--- cairo.h	7 Nov 2003 02:33:28 -0000	1.29
***************
*** 302,305 ****
--- 302,312 ----
  cairo_show_page (cairo_t *cr);
  
+ /* Insideness testing */
+ extern int __external_linkage
+ cairo_in_stroke (cairo_t *cr, double x, double y);
+ 
+ extern int __external_linkage
+ cairo_in_fill (cairo_t *cr, double x, double y);
+ 
  /* Clipping */
  extern void __external_linkage

Index: cairo_gstate.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_gstate.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** cairo_gstate.c	6 Nov 2003 20:53:39 -0000	1.31
--- cairo_gstate.c	7 Nov 2003 02:33:28 -0000	1.32
***************
*** 1195,1198 ****
--- 1195,1225 ----
  }
  
+ cairo_status_t
+ _cairo_gstate_in_stroke (cairo_gstate_t	*gstate,
+ 			 double		x,
+ 			 double		y,
+ 			 int		*inside_ret)
+ {
+     cairo_status_t status = CAIRO_STATUS_SUCCESS;
+     cairo_traps_t traps;
+ 
+     cairo_matrix_transform_point (&gstate->ctm, &x, &y);
+ 
+     _cairo_pen_init (&gstate->pen_regular, gstate->line_width / 2.0, gstate);
+ 
+     _cairo_traps_init (&traps);
+ 
+     status = _cairo_path_stroke_to_traps (&gstate->path, gstate, &traps);
+     if (status)
+ 	goto BAIL;
+ 
+     *inside_ret = _cairo_traps_contain (&traps, x, y);
+ 
+ BAIL:
+     _cairo_traps_fini (&traps);
+ 
+     return status;
+ }
+ 
  /* Warning: This call modifies the coordinates of traps */
  static cairo_status_t
***************
*** 1242,1247 ****
             the coordinates to align with the offset origin of the clip
             surface. */
! 	xoff = XDoubleToFixed (gstate->clip.x);
! 	yoff = XDoubleToFixed (gstate->clip.y);
  	for (i=0, t=traps->traps; i < traps->num_traps; i++, t++) {
  	    t->top -= yoff;
--- 1269,1274 ----
             the coordinates to align with the offset origin of the clip
             surface. */
! 	xoff = _cairo_fixed_from_double (gstate->clip.x);
! 	yoff = _cairo_fixed_from_double (gstate->clip.y);
  	for (i=0, t=traps->traps; i < traps->num_traps; i++, t++) {
  	    t->top -= yoff;
***************
*** 1358,1361 ****
--- 1385,1413 ----
  
  cairo_status_t
+ _cairo_gstate_in_fill (cairo_gstate_t	*gstate,
+ 		       double		x,
+ 		       double		y,
+ 		       int		*inside_ret)
+ {
+     cairo_status_t status = CAIRO_STATUS_SUCCESS;
+     cairo_traps_t traps;
+ 
+     cairo_matrix_transform_point (&gstate->ctm, &x, &y);
+ 
+     _cairo_traps_init (&traps);
+ 
+     status = _cairo_path_fill_to_traps (&gstate->path, gstate, &traps);
+     if (status)
+ 	goto BAIL;
+ 
+     *inside_ret = _cairo_traps_contain (&traps, x, y);
+ 
+ BAIL:
+     _cairo_traps_fini (&traps);
+ 
+     return status;
+ }
+ 
+ cairo_status_t
  _cairo_gstate_copy_page (cairo_gstate_t *gstate)
  {

Index: cairo_path.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_path.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** cairo_path.c	23 Oct 2003 14:47:29 -0000	1.9
--- cairo_path.c	7 Nov 2003 02:33:28 -0000	1.10
***************
*** 128,133 ****
      cairo_point_t point;
  
!     point.x = XDoubleToFixed (x);
!     point.y = XDoubleToFixed (y);
  
      return _cairo_path_add (path, CAIRO_PATH_OP_MOVE_TO, &point, 1);
--- 128,133 ----
      cairo_point_t point;
  
!     point.x = _cairo_fixed_from_double (x);
!     point.y = _cairo_fixed_from_double (y);
  
      return _cairo_path_add (path, CAIRO_PATH_OP_MOVE_TO, &point, 1);
***************
*** 139,144 ****
      cairo_point_t point;
  
!     point.x = XDoubleToFixed (x);
!     point.y = XDoubleToFixed (y);
  
      return _cairo_path_add (path, CAIRO_PATH_OP_LINE_TO, &point, 1);
--- 139,144 ----
      cairo_point_t point;
  
!     point.x = _cairo_fixed_from_double (x);
!     point.y = _cairo_fixed_from_double (y);
  
      return _cairo_path_add (path, CAIRO_PATH_OP_LINE_TO, &point, 1);
***************
*** 153,164 ****
      cairo_point_t point[3];
  
!     point[0].x = XDoubleToFixed (x1);
!     point[0].y = XDoubleToFixed (y1);
  
!     point[1].x = XDoubleToFixed (x2);
!     point[1].y = XDoubleToFixed (y2);
  
!     point[2].x = XDoubleToFixed (x3);
!     point[2].y = XDoubleToFixed (y3);
  
      return _cairo_path_add (path, CAIRO_PATH_OP_CURVE_TO, point, 3);
--- 153,164 ----
      cairo_point_t point[3];
  
!     point[0].x = _cairo_fixed_from_double (x1);
!     point[0].y = _cairo_fixed_from_double (y1);
  
!     point[1].x = _cairo_fixed_from_double (x2);
!     point[1].y = _cairo_fixed_from_double (y2);
  
!     point[2].x = _cairo_fixed_from_double (x3);
!     point[2].y = _cairo_fixed_from_double (y3);
  
      return _cairo_path_add (path, CAIRO_PATH_OP_CURVE_TO, point, 3);

Index: cairo_traps.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_traps.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** cairo_traps.c	5 Sep 2003 22:29:49 -0000	1.11
--- cairo_traps.c	7 Nov 2003 02:33:28 -0000	1.12
***************
*** 404,408 ****
  	return 0;
  
!     y_intersect = XDoubleToFixed ((b2 - b1) / (m1 - m2));
  
      if (m1 < m2) {
--- 404,408 ----
  	return 0;
  
!     y_intersect = _cairo_fixed_from_double ((b2 - b1) / (m1 - m2));
  
      if (m1 < m2) {
***************
*** 567,568 ****
--- 567,610 ----
      return CAIRO_STATUS_SUCCESS;
  }
+ 
+ static int
+ _cairo_trap_contains (cairo_trapezoid_t *t, cairo_point_t *pt)
+ {
+     cairo_slope_t slope_left, slope_pt, slope_right;
+     
+     if (t->top > pt->y)
+ 	return 0;
+     if (t->bottom < pt->y)
+ 	return 0;
+     
+     _cairo_slope_init (&slope_left, &t->left.p1, &t->left.p2);
+     _cairo_slope_init (&slope_pt, &t->left.p1, pt);
+ 
+     if (_cairo_slope_compare (&slope_left, &slope_pt) < 0)
+ 	return 0;
+ 
+     _cairo_slope_init (&slope_right, &t->right.p1, &t->right.p2);
+     _cairo_slope_init (&slope_pt, &t->right.p1, pt);
+ 
+     if (_cairo_slope_compare (&slope_pt, &slope_right) < 0)
+ 	return 0;
+ 
+     return 1;
+ }
+ 
+ int
+ _cairo_traps_contain (cairo_traps_t *traps, double x, double y)
+ {
+     int i;
+     cairo_point_t point;
+ 
+     point.x = _cairo_fixed_from_double (x);
+     point.y = _cairo_fixed_from_double (y);
+ 
+     for (i = 0; i < traps->num_traps; i++) {
+ 	if (_cairo_trap_contains (&traps->traps[i], &point))
+ 	    return 1;
+     }
+ 
+     return 0;
+ }

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** cairoint.h	4 Nov 2003 03:17:31 -0000	1.38
--- cairoint.h	7 Nov 2003 02:33:28 -0000	1.39
***************
*** 723,726 ****
--- 723,738 ----
  
  extern cairo_status_t __internal_linkage
+ _cairo_gstate_in_stroke (cairo_gstate_t	*gstate,
+ 			 double		x,
+ 			 double		y,
+ 			 int		*inside_ret);
+ 
+ extern cairo_status_t __internal_linkage
+ _cairo_gstate_in_fill (cairo_gstate_t	*gstate,
+ 		       double		x,
+ 		       double		y,
+ 		       int		*inside_ret);
+ 
+ extern cairo_status_t __internal_linkage
  _cairo_gstate_clip (cairo_gstate_t *gstate);
  
***************
*** 1126,1129 ****
--- 1138,1144 ----
  				 cairo_fill_rule_t fill_rule);
  
+ extern int __internal_linkage
+ _cairo_traps_contain (cairo_traps_t *traps, double x, double y);
+ 
  /* cairo_slope.c */
  extern void __internal_linkage





More information about the cairo-commit mailing list