[cairo-commit] libsvg-cairo/src svg-cairo-internal.h, 1.13, 1.14 svg_cairo.c, 1.27, 1.28 svg_cairo_state.c, 1.9, 1.10

David Reveman commit at pdx.freedesktop.org
Mon Jun 7 09:07:28 PDT 2004


Committed by: davidr

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

Modified Files:
	svg-cairo-internal.h svg_cairo.c svg_cairo_state.c 
Log Message:
Gradient matrix and object bounding box support

Index: svg-cairo-internal.h
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg-cairo-internal.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** a/svg-cairo-internal.h	5 Dec 2003 17:35:43 -0000	1.13
--- b/svg-cairo-internal.h	7 Jun 2004 16:07:25 -0000	1.14
***************
*** 41,44 ****
--- 41,49 ----
  } svg_cairo_pt_t;
  
+ typedef enum svg_cairo_render_type {
+     SVG_CAIRO_RENDER_TYPE_FILL,
+     SVG_CAIRO_RENDER_TYPE_STROKE
+ } svg_cairo_render_type_t;
+ 
  typedef struct svg_cairo_state {
      cairo_surface_t *child_surface;
***************
*** 64,67 ****
--- 69,74 ----
      unsigned int viewport_height;
  
+     int bbox;
+ 
      svg_text_anchor_t text_anchor;
  

Index: svg_cairo.c
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg_cairo.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** a/svg_cairo.c	4 May 2004 19:02:13 -0000	1.27
--- b/svg_cairo.c	7 Jun 2004 16:07:25 -0000	1.28
***************
*** 537,545 ****
  
  static svg_status_t
! _svg_cairo_set_gradient (svg_cairo_t *svg_cairo, svg_gradient_t *gradient)
  {
      svg_gradient_stop_t *stop;
      cairo_pattern_t *pattern = NULL;
      int i;
      
      switch (gradient->type) {
--- 537,568 ----
  
  static svg_status_t
! _svg_cairo_set_gradient (svg_cairo_t *svg_cairo,
! 			 svg_gradient_t *gradient,
! 			 svg_cairo_render_type_t type)
  {
      svg_gradient_stop_t *stop;
      cairo_pattern_t *pattern = NULL;
+     cairo_matrix_t *matrix, *gradient_matrix;
      int i;
+ 
+     matrix = cairo_matrix_create ();
+ 
+     switch (gradient->units) {
+     case SVG_GRADIENT_UNITS_USER:
+ 	break;
+     case SVG_GRADIENT_UNITS_BBOX:
+     {
+ 	double x1, y1, x2, y2;
+ 	
+ 	if (type == SVG_CAIRO_RENDER_TYPE_FILL)
+ 	    cairo_fill_extents (svg_cairo->cr, &x1, &y1, &x2, &y2);
+ 	else
+ 	    cairo_stroke_extents (svg_cairo->cr, &x1, &y1, &x2, &y2);
+ 
+ 	cairo_matrix_translate (matrix, x1, y1);
+ 	cairo_matrix_scale (matrix, x2 - x1, y2 - y1);
+ 	svg_cairo->state->bbox = 1;
+     } break;
+     }
      
      switch (gradient->type) {
***************
*** 552,556 ****
  	_svg_cairo_length_to_pixel (svg_cairo, &gradient->u.linear.x2, &x2);
  	_svg_cairo_length_to_pixel (svg_cairo, &gradient->u.linear.y2, &y2);
! 	
  	pattern = cairo_pattern_create_linear (x1, y1, x2, y2);
      }
--- 575,579 ----
  	_svg_cairo_length_to_pixel (svg_cairo, &gradient->u.linear.x2, &x2);
  	_svg_cairo_length_to_pixel (svg_cairo, &gradient->u.linear.y2, &y2);
! 
  	pattern = cairo_pattern_create_linear (x1, y1, x2, y2);
      }
***************
*** 565,571 ****
  	_svg_cairo_length_to_pixel (svg_cairo, &gradient->u.radial.fx, &fx);
  	_svg_cairo_length_to_pixel (svg_cairo, &gradient->u.radial.fy, &fy);
! 	
! 	pattern = cairo_pattern_create_radial (fx, fy, 0.0,
! 					       cx, cy, r);
      } break;
      }
--- 588,593 ----
  	_svg_cairo_length_to_pixel (svg_cairo, &gradient->u.radial.fx, &fx);
  	_svg_cairo_length_to_pixel (svg_cairo, &gradient->u.radial.fy, &fy);
! 
! 	pattern = cairo_pattern_create_radial (fx, fy, 0.0, cx, cy, r);
      } break;
      }
***************
*** 579,583 ****
  				      stop->opacity);
      }
!     
      switch (gradient->spread) {
      case SVG_GRADIENT_SPREAD_REPEAT:
--- 601,605 ----
  				      stop->opacity);
      }
! 	    
      switch (gradient->spread) {
      case SVG_GRADIENT_SPREAD_REPEAT:
***************
*** 593,600 ****
      
      cairo_pattern_set_filter (pattern, CAIRO_FILTER_BILINEAR);
      
      cairo_set_pattern (svg_cairo->cr, pattern);
      cairo_pattern_destroy (pattern);
!     pattern = NULL;
      
      return SVG_STATUS_SUCCESS;
--- 615,634 ----
      
      cairo_pattern_set_filter (pattern, CAIRO_FILTER_BILINEAR);
+ 
+     gradient_matrix = cairo_matrix_create ();
+     cairo_matrix_set_affine (gradient_matrix,
+ 			     gradient->transform[0], gradient->transform[1],
+ 			     gradient->transform[2], gradient->transform[3],
+ 			     gradient->transform[4], gradient->transform[5]);
+     cairo_matrix_multiply (matrix, matrix, gradient_matrix);
+     cairo_matrix_destroy (gradient_matrix);
+     
+     cairo_matrix_invert (matrix);
+     cairo_pattern_set_matrix (pattern, matrix);
+     cairo_matrix_destroy (matrix);
      
      cairo_set_pattern (svg_cairo->cr, pattern);
      cairo_pattern_destroy (pattern);
!     svg_cairo->state->bbox = 0;
      
      return SVG_STATUS_SUCCESS;
***************
*** 602,606 ****
  
  static svg_status_t
! _svg_cairo_set_pattern (svg_cairo_t *svg_cairo, svg_element_t *pattern_element)
  {
      svg_pattern_t *pattern = svg_element_pattern (pattern_element);
--- 636,642 ----
  
  static svg_status_t
! _svg_cairo_set_pattern (svg_cairo_t *svg_cairo,
! 			svg_element_t *pattern_element,
! 			svg_cairo_render_type_t type)
  {
      svg_pattern_t *pattern = svg_element_pattern (pattern_element);
***************
*** 647,651 ****
  
  static svg_status_t
! _svg_cairo_set_paint_and_opacity (svg_cairo_t *svg_cairo, svg_paint_t *paint, double opacity)
  {
      svg_status_t status;
--- 683,687 ----
  
  static svg_status_t
! _svg_cairo_set_paint_and_opacity (svg_cairo_t *svg_cairo, svg_paint_t *paint, double opacity, svg_cairo_render_type_t type)
  {
      svg_status_t status;
***************
*** 660,669 ****
  	break;
      case SVG_PAINT_TYPE_GRADIENT:
! 	status = _svg_cairo_set_gradient (svg_cairo, paint->p.gradient);
  	if (status)
  	    return status;
  	break;
      case SVG_PAINT_TYPE_PATTERN:
! 	status = _svg_cairo_set_pattern (svg_cairo, paint->p.pattern_element);
  	if (status)
  	    return status;
--- 696,705 ----
  	break;
      case SVG_PAINT_TYPE_GRADIENT:
! 	status = _svg_cairo_set_gradient (svg_cairo, paint->p.gradient, type);
  	if (status)
  	    return status;
  	break;
      case SVG_PAINT_TYPE_PATTERN:
! 	status = _svg_cairo_set_pattern (svg_cairo, paint->p.pattern_element, type);
  	if (status)
  	    return status;
***************
*** 1002,1006 ****
  	    cairo_save (svg_cairo->cr);
  	_svg_cairo_set_paint_and_opacity (svg_cairo, fill_paint,
! 				     svg_cairo->state->fill_opacity);
  	cairo_fill (svg_cairo->cr);
  	if (stroke_paint->type)
--- 1038,1043 ----
  	    cairo_save (svg_cairo->cr);
  	_svg_cairo_set_paint_and_opacity (svg_cairo, fill_paint,
! 					  svg_cairo->state->fill_opacity,
! 					  SVG_CAIRO_RENDER_TYPE_FILL);
  	cairo_fill (svg_cairo->cr);
  	if (stroke_paint->type)
***************
*** 1011,1015 ****
  	&& (stroke_paint->type != SVG_PAINT_TYPE_PATTERN || !svg_cairo->state->in_set_pattern_HACK)) {
  	_svg_cairo_set_paint_and_opacity (svg_cairo, stroke_paint,
! 				     svg_cairo->state->stroke_opacity);
  	cairo_stroke (svg_cairo->cr);
      }
--- 1048,1053 ----
  	&& (stroke_paint->type != SVG_PAINT_TYPE_PATTERN || !svg_cairo->state->in_set_pattern_HACK)) {
  	_svg_cairo_set_paint_and_opacity (svg_cairo, stroke_paint,
! 					  svg_cairo->state->stroke_opacity,
! 					  SVG_CAIRO_RENDER_TYPE_STROKE);
  	cairo_stroke (svg_cairo->cr);
      }
***************
*** 1141,1145 ****
  	    cairo_save (svg_cairo->cr);
  	_svg_cairo_set_paint_and_opacity (svg_cairo, fill_paint,
! 					  svg_cairo->state->fill_opacity);
  	cairo_show_text (svg_cairo->cr, utf8);
  	if (stroke_paint->type)
--- 1179,1184 ----
  	    cairo_save (svg_cairo->cr);
  	_svg_cairo_set_paint_and_opacity (svg_cairo, fill_paint,
! 					  svg_cairo->state->fill_opacity,
! 					  SVG_CAIRO_RENDER_TYPE_FILL);
  	cairo_show_text (svg_cairo->cr, utf8);
  	if (stroke_paint->type)
***************
*** 1150,1154 ****
  	&& (stroke_paint->type != SVG_PAINT_TYPE_PATTERN || !svg_cairo->state->in_set_pattern_HACK)) {
  	_svg_cairo_set_paint_and_opacity (svg_cairo, stroke_paint,
! 					  svg_cairo->state->stroke_opacity);
  	cairo_text_path (svg_cairo->cr, utf8);
  	cairo_stroke (svg_cairo->cr);
--- 1189,1194 ----
  	&& (stroke_paint->type != SVG_PAINT_TYPE_PATTERN || !svg_cairo->state->in_set_pattern_HACK)) {
  	_svg_cairo_set_paint_and_opacity (svg_cairo, stroke_paint,
! 					  svg_cairo->state->stroke_opacity,
! 					  SVG_CAIRO_RENDER_TYPE_STROKE);
  	cairo_text_path (svg_cairo->cr, utf8);
  	cairo_stroke (svg_cairo->cr);
***************
*** 1262,1270 ****
  	break;
      case SVG_LENGTH_UNIT_PCT:
! 	/* TODO : we usually but not always want to compute against target window dimension.
! 	          Make it so we also computes against inner <svg> elements, maybe by storing a
! 		  width/height pair in the state? */
! 	width = svg_cairo->state->viewport_width;
! 	height = svg_cairo->state->viewport_height;
  	if (length->orientation == SVG_LENGTH_ORIENTATION_HORIZONTAL)
  	    *pixel = (length->value / 100.0) * width;
--- 1302,1312 ----
  	break;
      case SVG_LENGTH_UNIT_PCT:
! 	if (svg_cairo->state->bbox) {
! 	    width = 1.0;
! 	    height = 1.0;
! 	} else {
! 	    width = svg_cairo->state->viewport_width;
! 	    height = svg_cairo->state->viewport_height;
! 	}
  	if (length->orientation == SVG_LENGTH_ORIENTATION_HORIZONTAL)
  	    *pixel = (length->value / 100.0) * width;

Index: svg_cairo_state.c
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg_cairo_state.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** a/svg_cairo_state.c	5 Dec 2003 17:35:43 -0000	1.9
--- b/svg_cairo_state.c	7 Jun 2004 16:07:25 -0000	1.10
***************
*** 70,73 ****
--- 70,75 ----
      state->opacity = 1.0;
  
+     state->bbox = 0;
+ 
      state->text_anchor = SVG_TEXT_ANCHOR_START;
  





More information about the cairo-commit mailing list