[lasem] [SVG] Support of the group opacity property.



commit 75c564901c5799bccc91ea3bee2449324adf3921
Author: Emmanuel Pacaud <emmanuel pacaud lapp in2p3 fr>
Date:   Mon Apr 27 23:46:26 2009 +0200

    [SVG] Support of the group opacity property.
---
 src/lsmsvggraphic.c    |   16 ++++++++++++++--
 src/lsmsvggraphic.h    |    1 +
 src/lsmsvgsvgelement.c |    1 +
 src/lsmsvgview.c       |   17 +++++++++++++++++
 src/lsmsvgview.h       |    3 +++
 5 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/lsmsvggraphic.c b/src/lsmsvggraphic.c
index 36a867e..41f0b6d 100644
--- a/src/lsmsvggraphic.c
+++ b/src/lsmsvggraphic.c
@@ -30,6 +30,7 @@ static void
 lsm_svg_graphic_update (LsmSvgElement *self, LsmSvgStyle *parent_style)
 {
 	LsmSvgGraphic *graphic = LSM_SVG_GRAPHIC (self);
+	double default_opacity;
 
 	/* Handle inline style here for now. This should move to the CSS handling part. */
 
@@ -91,6 +92,9 @@ lsm_svg_graphic_update (LsmSvgElement *self, LsmSvgStyle *parent_style)
 
 	lsm_svg_color_attribute_parse (&graphic->color, &parent_style->color, &parent_style->color);
 
+	default_opacity = 1.0;
+	lsm_svg_double_attribute_parse (&graphic->opacity, &default_opacity); /* FIXME handle inherit */
+
 	if (graphic->fill != NULL) {
 		lsm_debug ("[LsmSvgGraphic::update] fill");
 
@@ -147,6 +151,9 @@ lsm_svg_graphic_render (LsmSvgElement *self, LsmSvgView *view)
 {
 	LsmSvgGraphic *graphic = LSM_SVG_GRAPHIC (self);
 
+	if (graphic->opacity.value < 1.0)
+		lsm_svg_view_push_group (view);
+
 	if (graphic->fill != NULL)
 		lsm_svg_view_push_fill_attributes (view, graphic->fill);
 	if (graphic->stroke != NULL)
@@ -166,6 +173,9 @@ lsm_svg_graphic_render (LsmSvgElement *self, LsmSvgView *view)
 		lsm_svg_view_pop_stroke_attributes (view);
 	if (graphic->fill != NULL)
 		lsm_svg_view_pop_fill_attributes (view);
+
+	if (graphic->opacity.value < 1.0)
+		lsm_svg_view_paint_group (view, graphic->opacity.value);
 }
 
 /* LsmSvgGraphic implementation */
@@ -200,11 +210,13 @@ lsm_svg_graphic_class_init (LsmSvgGraphicClass *s_graphic_class)
 	s_element_class->attributes = lsm_dom_attribute_map_duplicate (s_element_class->attributes);
 
 	lsm_dom_attribute_map_add_attribute (s_element_class->attributes, "class",
-					  offsetof (LsmSvgGraphic, class_name));
+					     offsetof (LsmSvgGraphic, class_name));
 	lsm_dom_attribute_map_add_attribute (s_element_class->attributes, "style",
-					  offsetof (LsmSvgGraphic, style));
+					     offsetof (LsmSvgGraphic, style));
 	lsm_dom_attribute_map_add_attribute (s_element_class->attributes, "color",
 					     offsetof (LsmSvgGraphic, color));
+	lsm_dom_attribute_map_add_attribute (s_element_class->attributes, "opacity",
+					     offsetof (LsmSvgGraphic, opacity));
 
 	lsm_dom_attribute_map_add_fill_attribute_bag (s_element_class->attributes, offsetof (LsmSvgGraphic, fill));
 	lsm_dom_attribute_map_add_stroke_attribute_bag (s_element_class->attributes, offsetof (LsmSvgGraphic, stroke));
diff --git a/src/lsmsvggraphic.h b/src/lsmsvggraphic.h
index dd805d2..b66118e 100644
--- a/src/lsmsvggraphic.h
+++ b/src/lsmsvggraphic.h
@@ -43,6 +43,7 @@ struct _GSvgGraphic {
 	LsmDomAttribute	style;
 
 	LsmSvgColorAttribute color;
+	LsmSvgDoubleAttribute opacity;
 
 	LsmSvgFillAttributeBag *fill;
 	LsmSvgStrokeAttributeBag *stroke;
diff --git a/src/lsmsvgsvgelement.c b/src/lsmsvgsvgelement.c
index da78421..61ed0d8 100644
--- a/src/lsmsvgsvgelement.c
+++ b/src/lsmsvgsvgelement.c
@@ -146,6 +146,7 @@ lsm_svg_svg_element_init (LsmSvgSvgElement *self)
 	self->default_style = style;
 	g_return_if_fail (style != NULL);
 
+	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "opacity", 		"1.0");
 	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "fill", 			"black");
 	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "fill-opacity", 		"1");
 	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "fill-rule",		"nonzero");
diff --git a/src/lsmsvgview.c b/src/lsmsvgview.c
index 756d979..dff7815 100644
--- a/src/lsmsvgview.c
+++ b/src/lsmsvgview.c
@@ -1010,6 +1010,23 @@ lsm_svg_view_show_text (LsmSvgView *view, char const *string, double x, double y
 	_paint (view);
 }
 
+void
+lsm_svg_view_push_group (LsmSvgView *view)
+{
+	g_return_if_fail (LSM_IS_SVG_VIEW (view));
+
+	cairo_push_group (view->dom_view.cairo);
+}
+
+void
+lsm_svg_view_paint_group (LsmSvgView *view, double opacity)
+{
+	g_return_if_fail (LSM_IS_SVG_VIEW (view));
+
+	cairo_pop_group_to_source (view->dom_view.cairo);
+	cairo_paint_with_alpha (view->dom_view.cairo, opacity);
+}
+
 static void
 lsm_svg_view_measure (LsmDomView *view, double *width, double *height)
 {
diff --git a/src/lsmsvgview.h b/src/lsmsvgview.h
index 6b90e1e..f3110be 100644
--- a/src/lsmsvgview.h
+++ b/src/lsmsvgview.h
@@ -96,6 +96,9 @@ void 		lsm_svg_view_show_polyline	(LsmSvgView *view, const char *points);
 void 		lsm_svg_view_show_polygon	(LsmSvgView *view, const char *points);
 void 		lsm_svg_view_show_text 		(LsmSvgView *view, char const *text, double x, double y);
 
+void 		lsm_svg_view_push_group 	(LsmSvgView *view);
+void 		lsm_svg_view_paint_group 	(LsmSvgView *view, double opacity);
+
 G_END_DECLS
 
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]