[cairo-commit] libsvg/src svg_gradient.c, 1.2, 1.3 svg_parser.c, 1.31, 1.32 svgint.h, 1.41, 1.42

David Reveman commit at pdx.freedesktop.org
Mon Jun 7 09:00:19 PDT 2004


Committed by: davidr

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

Modified Files:
	svg_gradient.c svg_parser.c svgint.h 
Log Message:
Better gradient support

Index: svg_gradient.c
===================================================================
RCS file: /cvs/cairo/libsvg/src/svg_gradient.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** a/svg_gradient.c	30 Apr 2004 06:50:33 -0000	1.2
--- b/svg_gradient.c	7 Jun 2004 16:00:17 -0000	1.3
***************
*** 31,44 ****
      svg_transform_t transform;
  
!     gradient->type = SVG_GRADIENT_LINEAR;
! 
!     /* XXX: Should check what these defaults should really be. */
! 
!     _svg_length_init_unit (&gradient->u.linear.x1, 0, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
!     _svg_length_init_unit (&gradient->u.linear.y1, 0, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
!     _svg_length_init_unit (&gradient->u.linear.x2, 0, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
!     _svg_length_init_unit (&gradient->u.linear.y2, 0, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
  
!     gradient->units = SVG_GRADIENT_UNITS_USER;
      gradient->spread = SVG_GRADIENT_SPREAD_PAD;
  
--- 31,37 ----
      svg_transform_t transform;
  
!     _svg_gradient_set_type (gradient, SVG_GRADIENT_LINEAR);
  
!     gradient->units = SVG_GRADIENT_UNITS_BBOX;
      gradient->spread = SVG_GRADIENT_SPREAD_PAD;
  
***************
*** 60,63 ****
--- 53,57 ----
  {
      *gradient = *other;
+     
      gradient->stops = malloc (gradient->stops_size * sizeof (svg_gradient_stop_t));
      if (gradient->stops == NULL)
***************
*** 81,84 ****
--- 75,100 ----
  }
  
+ svg_status_t
+ _svg_gradient_set_type (svg_gradient_t *gradient,
+ 			svg_gradient_type_t type)
+ {
+     gradient->type = type;
+ 
+     /* XXX: Should check what these defaults should really be. */
+ 
+     if (gradient->type == SVG_GRADIENT_LINEAR) {
+ 	_svg_length_init_unit (&gradient->u.linear.x1, 0, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
+ 	_svg_length_init_unit (&gradient->u.linear.y1, 0, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_VERTICAL);
+ 	_svg_length_init_unit (&gradient->u.linear.x2, 100, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
+ 	_svg_length_init_unit (&gradient->u.linear.y2, 0, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_VERTICAL);
+     } else {
+ 	_svg_length_init_unit (&gradient->u.radial.cx, 50, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
+ 	_svg_length_init_unit (&gradient->u.radial.cy, 50, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_VERTICAL);
+ 	_svg_length_init_unit (&gradient->u.radial.fx, 50, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
+ 	_svg_length_init_unit (&gradient->u.radial.fy, 50, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_VERTICAL);
+ 	_svg_length_init_unit (&gradient->u.radial.r, 50, SVG_LENGTH_UNIT_PCT, SVG_LENGTH_ORIENTATION_HORIZONTAL);
+     }
+ }
+ 
  #define SVG_GRADIENT_STOPS_GROWTH 2
  
***************
*** 127,137 ****
      	svg_element_t *ref = NULL;
  	_svg_fetch_element_by_id (svg, href + 1, &ref);
! 
! 	/* XXX: Is it correct to ignore the referenced gradient if it
!            is of a different gradient type? */
! 	if (ref && ref->type == SVG_ELEMENT_TYPE_GRADIENT
! 	    && ref->e.gradient.type == gradient->type) {
  	    prototype = &ref->e.gradient;
  	    _svg_gradient_init_copy (gradient, prototype);
  	}
      }
--- 143,157 ----
      	svg_element_t *ref = NULL;
  	_svg_fetch_element_by_id (svg, href + 1, &ref);
! 	
! 	if (ref && ref->type == SVG_ELEMENT_TYPE_GRADIENT) {
! 	    svg_gradient_t save_gradient = *gradient;
! 	    
  	    prototype = &ref->e.gradient;
  	    _svg_gradient_init_copy (gradient, prototype);
+ 	    
+ 	    if (gradient->type != save_gradient.type) {
+ 		gradient->type = save_gradient.type;
+ 		gradient->u = save_gradient.u;
+ 	    }
  	}
      }
***************
*** 147,152 ****
  	else
  	    return SVG_STATUS_INVALID_VALUE;
!     }
      
      if (gradient->type == SVG_GRADIENT_LINEAR) {
  	status = _svg_attribute_get_length (attributes, "x1", &gradient->u.linear.x1, "0%");
--- 167,202 ----
  	else
  	    return SVG_STATUS_INVALID_VALUE;
!     }    
      
+     status = _svg_attribute_get_string (attributes, "gradientTransform", &str, 0);
+     if (str) {
+ 	_svg_transform_init (&transform);
+ 	_svg_transform_parse_str (&transform, str);
+ 	for (i = 0 ; i < 6 ; i++) {
+ 	    gradient->transform [i] = transform.m[i/2][i%2];
+ 	}
+     } else if (prototype) {
+ 	for (i = 0 ; i < 6 ; ++i)
+ 	    gradient->transform[i] = prototype->transform[i];
+     }
+ 
+     status = _svg_attribute_get_string (attributes, "spreadMethod",
+ 					&str, "pad");
+     if (status == SVGINT_STATUS_ATTRIBUTE_NOT_FOUND && prototype) {
+ 	gradient->spread = prototype->spread;
+     } else {
+ 	if (strcmp (str, "pad") == 0)
+ 	    gradient->spread = SVG_GRADIENT_SPREAD_PAD;
+ 	else if (strcmp (str, "reflect") == 0)
+ 	    gradient->spread = SVG_GRADIENT_SPREAD_REFLECT;
+ 	else if (strcmp (str, "repeat") == 0)
+ 	    gradient->spread = SVG_GRADIENT_SPREAD_REPEAT;
+ 	else
+ 	    return SVG_STATUS_INVALID_VALUE;
+     }
+ 
+     if (prototype && prototype->type != gradient->type)
+ 	prototype = NULL;
+ 
      if (gradient->type == SVG_GRADIENT_LINEAR) {
  	status = _svg_attribute_get_length (attributes, "x1", &gradient->u.linear.x1, "0%");
***************
*** 182,199 ****
  	    gradient->u.radial.fy = gradient->u.radial.cy;
      }
-     
-     status = _svg_attribute_get_string (attributes, "gradientTransform", &str, 0);
-     if (str) {
- 	_svg_transform_init (&transform);
- 	_svg_transform_parse_str (&transform, str);
- 	for (i = 0 ; i < 6 ; i++) {
- 	    gradient->transform [i] = transform.m[i/2][i%2];
- 	}
-     } else if (prototype) {
- 	for (i = 0 ; i < 6 ; ++i)
- 	    gradient->transform[i] = prototype->transform[i];
-     }
  
      return SVG_STATUS_SUCCESS;
  }
- 
--- 232,236 ----

Index: svg_parser.c
===================================================================
RCS file: /cvs/cairo/libsvg/src/svg_parser.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** a/svg_parser.c	4 May 2004 19:01:10 -0000	1.31
--- b/svg_parser.c	7 Jun 2004 16:00:17 -0000	1.32
***************
*** 897,904 ****
      if (status)
  	return status;
  
!     (*gradient_element)->e.gradient.type = SVG_GRADIENT_LINEAR;
! 
!     return SVG_STATUS_SUCCESS;;
  }
  
--- 897,905 ----
      if (status)
  	return status;
+     
+     _svg_gradient_set_type (&(*gradient_element)->e.gradient,
+ 			    SVG_GRADIENT_LINEAR);
  
!     return SVG_STATUS_SUCCESS;
  }
  
***************
*** 916,920 ****
  	return status;
  
!     (*gradient_element)->e.gradient.type = SVG_GRADIENT_RADIAL;
  
      return SVG_STATUS_SUCCESS;
--- 917,922 ----
  	return status;
  
!     _svg_gradient_set_type (&(*gradient_element)->e.gradient,
! 			    SVG_GRADIENT_RADIAL);
  
      return SVG_STATUS_SUCCESS;

Index: svgint.h
===================================================================
RCS file: /cvs/cairo/libsvg/src/svgint.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** a/svgint.h	30 Apr 2004 06:50:33 -0000	1.41
--- b/svgint.h	7 Jun 2004 16:00:17 -0000	1.42
***************
*** 466,469 ****
--- 466,473 ----
  
  svg_status_t
+ _svg_gradient_set_type (svg_gradient_t *gradient,
+ 			svg_gradient_type_t type);
+ 
+ svg_status_t
  _svg_gradient_add_stop (svg_gradient_t *gradient,
  			double		offset,





More information about the cairo-commit mailing list