[goocanvas/new-api] 2010-06-30 Damon Chaplin <damon gnome org>



commit e96d354b81f00f01e7c57e666fe3afc61c5d0660
Author: Damon Chaplin <damon gnome org>
Date:   Wed Jun 30 14:13:34 2010 +0100

    2010-06-30  Damon Chaplin  <damon gnome org>
    
    	    * src/goocanvasitemsimple.c (goo_canvas_item_simple_set_property): if
    	    a shared style is being used, make a copy of it before setting the
    	    property.
    
    	    * src/goocanvasstyle.c (goo_canvas_style_copy): new function.

 src/goocanvasitemsimple.c |   11 +++++++++--
 src/goocanvasstyle.c      |   36 ++++++++++++++++++++++++++++++++++++
 src/goocanvasstyle.h      |    6 ++++--
 3 files changed, 49 insertions(+), 4 deletions(-)
---
diff --git a/src/goocanvasitemsimple.c b/src/goocanvasitemsimple.c
index dbb74ce..1fa3a78 100644
--- a/src/goocanvasitemsimple.c
+++ b/src/goocanvasitemsimple.c
@@ -298,11 +298,18 @@ goo_canvas_item_simple_set_property (GObject              *object,
   const char *font_name, *path_data;
   PangoFontDescription *font_desc = NULL;
 
-  /* See if we need to create a style. */
+  /* See if we need to create our own style or copy a shared style. */
   if (prop_id < PROP_TRANSFORM)
     {
       if (!simple->style)
-	simple->style = goo_canvas_style_new ();
+	{
+	  simple->style = goo_canvas_style_new ();
+	}
+      else if (((GObject*)simple->style)->ref_count > 1)
+	{
+	  g_object_unref ((GObject*) simple->style);
+	  simple->style = goo_canvas_style_copy (simple->style);
+	}
     }
 
   style = simple->style;
diff --git a/src/goocanvasstyle.c b/src/goocanvasstyle.c
index a9c7b43..d23ea9a 100644
--- a/src/goocanvasstyle.c
+++ b/src/goocanvasstyle.c
@@ -80,6 +80,42 @@ goo_canvas_style_new (void)
 }
 
 
+GooCanvasStyle*
+goo_canvas_style_copy (GooCanvasStyle* style)
+{
+  GooCanvasStyle *copy;
+
+  copy = g_object_new (GOO_TYPE_CANVAS_STYLE, NULL);
+
+  if (style->stroke_pattern)
+    copy->stroke_pattern = cairo_pattern_reference (style->stroke_pattern);
+
+  if (style->fill_pattern)
+    copy->fill_pattern = cairo_pattern_reference (style->fill_pattern);
+
+  if (style->dash)
+    copy->dash = goo_canvas_line_dash_ref (style->dash);
+
+  if (style->font_desc)
+    copy->font_desc = pango_font_description_copy (style->font_desc);
+
+  copy->line_width = style->line_width;
+  copy->line_width_tolerance = style->line_width_tolerance;
+  copy->line_join_miter_limit = style->line_join_miter_limit;
+  copy->stroke_pattern_set = style->stroke_pattern_set;
+  copy->fill_pattern_set = style->fill_pattern_set;
+  copy->op = style->op;
+  copy->antialias = style->antialias;
+  copy->fill_rule = style->fill_rule;
+  copy->line_cap = style->line_cap;
+  copy->line_join = style->line_join;
+  copy->hint_metrics = style->hint_metrics;
+  copy->line_width_is_unscaled = style->line_width_is_unscaled;
+
+  return copy;
+}
+
+
 static void
 goo_canvas_style_finalize (GObject *object)
 {
diff --git a/src/goocanvasstyle.h b/src/goocanvasstyle.h
index d7b6afc..c8dfbc6 100644
--- a/src/goocanvasstyle.h
+++ b/src/goocanvasstyle.h
@@ -64,8 +64,10 @@ struct _GooCanvasStyleClass
 };
 
 
-GType           goo_canvas_style_get_type          (void) G_GNUC_CONST;
-GooCanvasStyle* goo_canvas_style_new               (void);
+GType           goo_canvas_style_get_type        (void) G_GNUC_CONST;
+GooCanvasStyle* goo_canvas_style_new             (void);
+
+GooCanvasStyle* goo_canvas_style_copy		 (GooCanvasStyle* style);
 
 void         goo_canvas_style_set_stroke_pattern (GooCanvasStyle    *style,
 						  cairo_pattern_t   *pattern);



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