[goffice] Replaced some private data by public members in canvas items.



commit 9b6833a4356f5e9f568cbd65ac8d3cbe2e34b523
Author: Jean Brefort <jean brefort normalesup org>
Date:   Wed Aug 3 13:41:53 2011 +0200

    Replaced some private data by public members in canvas items.

 ChangeLog                      |   10 +++++
 goffice/canvas/goc-polygon.c   |   64 +++++++++++------------------------
 goffice/canvas/goc-polygon.h   |    3 ++
 goffice/canvas/goc-rectangle.c |   72 +++++++++++++--------------------------
 goffice/canvas/goc-rectangle.h |   11 ++++++
 5 files changed, 69 insertions(+), 91 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5b1c8ce..65b2722 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-08-03  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/canvas/goc-polygon.c (goc_polygon_finalize),
+	(goc_polygon_set_property), (goc_polygon_get_property),
+	(goc_polygon_prepare_path): replaced private structures by public data.
+	* goffice/canvas/goc-polygon.h: ditto.
+	* goffice/canvas/goc-rectangle.c (goc_rectangle_set_property),
+	(goc_rectangle_get_property), (goc_rectangle_prepare_draw): ditto.
+	* goffice/canvas/goc-rectangle.h: ditto.
+
 2011-08-02  Jean Brefort  <jean brefort normalesup org>
 
 	* configure.in: needs librsvg.
diff --git a/goffice/canvas/goc-polygon.c b/goffice/canvas/goc-polygon.c
index b6f6909..f005ce2 100644
--- a/goffice/canvas/goc-polygon.c
+++ b/goffice/canvas/goc-polygon.c
@@ -39,19 +39,6 @@ enum {
 	POLYGON_PROP_SIZES
 };
 
-typedef struct {
-	gboolean fill_rule;
-	unsigned nb_sizes;
-	int *sizes;
-} GocPolygonPriv;
-
-static void goc_polygon_priv_free (gpointer data)
-{
-	GocPolygonPriv *priv = (GocPolygonPriv *) data;
-	g_free (priv->sizes);
-	g_free (priv);
-}
-
 static GocStyledItemClass *parent_class;
 
 static void
@@ -59,6 +46,7 @@ goc_polygon_finalize (GObject *obj)
 {
 	GocPolygon *polygon = GOC_POLYGON (obj);
 	g_free (polygon->points);
+	g_free (polygon->sizes);
 	((GObjectClass *) parent_class)->finalize (obj);
 }
 
@@ -67,7 +55,6 @@ goc_polygon_set_property (GObject *gobject, guint param_id,
 			  GValue const *value, GParamSpec *pspec)
 {
 	GocPolygon *polygon = GOC_POLYGON (gobject);
-	GocPolygonPriv *priv = g_object_get_data (gobject, "polygon-private");
 
 	switch (param_id) {
 	case POLYGON_PROP_POINTS: {
@@ -83,32 +70,32 @@ goc_polygon_set_property (GObject *gobject, guint param_id,
 			polygon->points = NULL;
 		/* reset sizes */
 		g_free (priv->sizes);
-		priv->sizes = NULL;
-		priv->nb_sizes = 0;
+		polygon->sizes = NULL;
+		polygon->nb_sizes = 0;
 		break;
 	}
 	case POLYGON_PROP_SPLINE:
 		polygon->use_spline = g_value_get_boolean (value);
 		break;
 	case POLYGON_PROP_FILL_RULE:
-		priv->fill_rule = g_value_get_boolean (value);
+		polygon->fill_rule = g_value_get_boolean (value);
 		break;
 	case POLYGON_PROP_SIZES: {
 		unsigned i, avail = polygon->nb_points - 3;
 		GocIntArray *array = (GocIntArray *) g_value_get_boxed (value);
-		g_free (priv->sizes);
-		priv->sizes = NULL;
-		priv->nb_sizes = 0;
+		g_free (polygon->sizes);
+		polygon->sizes = NULL;
+		polygon->nb_sizes = 0;
 		for (i = 0; i < array->n; i++) {
 			if (array->vals[i] < 3 || array->vals[i] > (int) avail)
 				break;
 			avail -= array->vals[i];
-			priv->nb_sizes++;
+			polygon->nb_sizes++;
 		}
-		if (priv->nb_sizes > 0) {
-			priv->sizes = g_new (int, priv->nb_sizes);
-			for (i = 0; i < priv->nb_sizes; i++)
-				priv->sizes[i] = array->vals[i];
+		if (polygon->nb_sizes > 0) {
+			polygon->sizes = g_new (int, polygon->nb_sizes);
+			for (i = 0; i < polygon->nb_sizes; i++)
+				polygon->sizes[i] = array->vals[i];
 		}
 		break;
 	}
@@ -135,7 +122,6 @@ goc_polygon_get_property (GObject *gobject, guint param_id,
 				    GValue *value, GParamSpec *pspec)
 {
 	GocPolygon *polygon = GOC_POLYGON (gobject);
-	GocPolygonPriv *priv = g_object_get_data (gobject, "polygon-private");
 
 	switch (param_id) {
 	case POLYGON_PROP_POINTS: {
@@ -151,13 +137,13 @@ goc_polygon_get_property (GObject *gobject, guint param_id,
 		g_value_set_boolean (value, polygon->use_spline);
 		break;
 	case POLYGON_PROP_FILL_RULE:
-		g_value_set_boolean (value, priv->fill_rule);
+		g_value_set_boolean (value, polygon->fill_rule);
 		break;
 	case POLYGON_PROP_SIZES: {
 		unsigned i;
-		GocIntArray *array = goc_int_array_new (priv->nb_sizes);
+		GocIntArray *array = goc_int_array_new (polygon->nb_sizes);
 		for (i = 0; i < array->n; i++)
-			array->vals[i] = priv->sizes[i];
+			array->vals[i] = polygon->sizes[i];
 		g_value_set_boxed (value, array);
 		goc_int_array_unref (array);
 		break;
@@ -172,14 +158,13 @@ static gboolean
 goc_polygon_prepare_path (GocItem const *item, cairo_t *cr, gboolean flag)
 {
 	GocPolygon *polygon = GOC_POLYGON (item);
-	GocPolygonPriv *priv = g_object_get_data (G_OBJECT (polygon), "polygon-private");
 	unsigned snum;
 	int i, j;
 
 	if (polygon->nb_points == 0)
 		return FALSE;
 
-	cairo_set_fill_rule (cr, priv->fill_rule);
+	cairo_set_fill_rule (cr, polygon->fill_rule);
 	if (1 == flag) {
 		goc_group_cairo_transform (item->parent, cr, polygon->points[0].x, polygon->points[0].y);
 		cairo_move_to (cr, 0., 0.);
@@ -195,16 +180,16 @@ goc_polygon_prepare_path (GocItem const *item, cairo_t *cr, gboolean flag)
 		cairo_restore (cr);
 	} else {
 		double sign = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)? -1: 1;
-		if (priv->nb_sizes > 0) {
+		if (polygon->nb_sizes > 0) {
 			snum = 0;
-			for (j = 0; j < (int) priv->nb_sizes; j++) {
+			for (j = 0; j < (int) polygon->nb_sizes; j++) {
 				cairo_move_to (cr, (polygon->points[snum].x - polygon->points[0].x * flag) * sign,
 					polygon->points[snum].y - polygon->points[0].y * flag);
-				for (i = 1; i < priv->sizes[j]; i++)
+				for (i = 1; i < polygon->sizes[j]; i++)
 					cairo_line_to (cr, (polygon->points[snum + i].x - polygon->points[0].x * flag) * sign,
 						polygon->points[snum + i].y - polygon->points[0].y * flag);
 				cairo_close_path (cr);
-				snum += priv->sizes[j];
+				snum += polygon->sizes[j];
 			}
 			cairo_move_to (cr, (polygon->points[snum].x - polygon->points[0].x * flag) * sign,
 						polygon->points[snum].y - polygon->points[0].y * flag);
@@ -370,13 +355,6 @@ goc_polygon_class_init (GocItemClass *item_klass)
 	item_klass->draw = goc_polygon_draw;
 }
 
-static void
-goc_polygon_init (GocPolygon *polygon)
-{
-	GocPolygonPriv *priv = g_new0 (GocPolygonPriv, 1);
-	g_object_set_data_full (G_OBJECT (polygon), "polygon-private", priv, goc_polygon_priv_free);
-}
-
 GSF_CLASS (GocPolygon, goc_polygon,
-	   goc_polygon_class_init, goc_polygon_init,
+	   goc_polygon_class_init, NULL,
 	   GOC_TYPE_STYLED_ITEM)
diff --git a/goffice/canvas/goc-polygon.h b/goffice/canvas/goc-polygon.h
index 2d7a494..8a94394 100644
--- a/goffice/canvas/goc-polygon.h
+++ b/goffice/canvas/goc-polygon.h
@@ -35,6 +35,9 @@ struct _GocPolygon {
 	GocPoint *points;
 	unsigned nb_points;
 	gboolean use_spline;
+	gboolean fill_rule;
+	unsigned nb_sizes;
+	int *sizes;
 };
 
 #define GOC_TYPE_POLYGON	(goc_polygon_get_type ())
diff --git a/goffice/canvas/goc-rectangle.c b/goffice/canvas/goc-rectangle.c
index 3ba6ca9..285ec5a 100644
--- a/goffice/canvas/goc-rectangle.c
+++ b/goffice/canvas/goc-rectangle.c
@@ -33,20 +33,6 @@
 **/
 
 enum {
-	GOC_RECTANGLE_CORNER_NORMAL		= 0,
-	GOC_RECTANGLE_NW_CORNER_ROUND	= 1,
-	GOC_RECTANGLE_NE_CORNER_ROUND	= 2,
-	GOC_RECTANGLE_SW_CORNER_ROUND	= 4,
-	GOC_RECTANGLE_SE_CORNER_ROUND	= 8,
-	GOC_RECTANGLE_ALL_CORNERS_ROUND	= 15,
-};
-
-typedef struct {
-	int type;
-	double rx, ry;
-} GocRectPriv;
-
-enum {
 	RECT_PROP_0,
 	RECT_PROP_X,
 	RECT_PROP_Y,
@@ -63,7 +49,6 @@ goc_rectangle_set_property (GObject *gobject, guint param_id,
 				    GValue const *value, GParamSpec *pspec)
 {
 	GocRectangle *rect = GOC_RECTANGLE (gobject);
-	GocRectPriv *priv = g_object_get_data (gobject, "rect-private");
 
 	switch (param_id) {
 	case RECT_PROP_X:
@@ -87,15 +72,15 @@ goc_rectangle_set_property (GObject *gobject, guint param_id,
 		break;
 
 	case RECT_PROP_RX:
-		priv->rx = g_value_get_double (value);
+		rect->rx = g_value_get_double (value);
 		break;
 
 	case RECT_PROP_RY:
-		priv->ry = g_value_get_double (value);
+		rect->ry = g_value_get_double (value);
 		break;
 
 	case RECT_PROP_TYPE:
-		priv->type = g_value_get_int (value);
+		rect->type = g_value_get_int (value);
 		break;
 
 	default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
@@ -110,7 +95,6 @@ goc_rectangle_get_property (GObject *gobject, guint param_id,
 				    GValue *value, GParamSpec *pspec)
 {
 	GocRectangle *rect = GOC_RECTANGLE (gobject);
-	GocRectPriv *priv = g_object_get_data (gobject, "rect-private");
 
 	switch (param_id) {
 	case RECT_PROP_X:
@@ -134,15 +118,15 @@ goc_rectangle_get_property (GObject *gobject, guint param_id,
 		break;
 
 	case RECT_PROP_RX:
-		g_value_set_double (value, priv->rx);
+		g_value_set_double (value, rect->rx);
 		break;
 
 	case RECT_PROP_RY:
-		g_value_set_double (value, priv->ry);
+		g_value_set_double (value, rect->ry);
 		break;
 
 	case RECT_PROP_TYPE:
-		g_value_set_int (value, priv->type);
+		g_value_set_int (value, rect->type);
 		break;
 
 	default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
@@ -154,7 +138,6 @@ static gboolean
 goc_rectangle_prepare_draw (GocItem const *item, cairo_t *cr, gboolean flag)
 {
 	GocRectangle *rect = GOC_RECTANGLE (item);
-	GocRectPriv *priv = g_object_get_data (G_OBJECT (rect), "rect-private");
 	double sign = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)? -1.: 1.;
 
 	if (0 == rect->width && 0 == rect->height)
@@ -167,48 +150,48 @@ goc_rectangle_prepare_draw (GocItem const *item, cairo_t *cr, gboolean flag)
 		cairo_translate (cr, rect->x, rect->y);
 	}
 	cairo_rotate (cr, rect->rotation * sign);
-	if (0 == priv->type || 0 == priv->rx || 0 == priv->ry) {
+	if (0 == rect->type || 0 == rect->rx || 0 == rect->ry) {
 		cairo_rectangle (cr, 0., 0., (int) rect->width * sign, (int) rect->height);
 	} else {
 
-		if (priv->type&1) {
-			cairo_move_to (cr, priv->rx, 0.);
+		if (rect->type & 1) {
+			cairo_move_to (cr, rect->rx, 0.);
 			cairo_save (cr);
-			cairo_translate (cr, priv->rx, priv->ry);
-			cairo_scale (cr, priv->rx, priv->ry);
+			cairo_translate (cr, rect->rx, rect->ry);
+			cairo_scale (cr, rect->rx, rect->ry);
 			cairo_arc_negative (cr, 0. , 0. ,1. , -M_PI/2. , M_PI);
 			cairo_restore (cr);
 		} else {
 			cairo_move_to (cr, 0., 0.);
 		}
 
-		if (priv->type&8) {
-			cairo_line_to (cr, 0., rect->height - priv->ry);
+		if (rect->type & 8) {
+			cairo_line_to (cr, 0., rect->height - rect->ry);
 			cairo_save (cr);
-			cairo_translate (cr, priv->rx, rect->height - priv->ry);
-			cairo_scale (cr, priv->rx, priv->ry);
+			cairo_translate (cr, rect->rx, rect->height - rect->ry);
+			cairo_scale (cr, rect->rx, rect->ry);
 			cairo_arc_negative (cr, 0., 0. ,1. , M_PI, M_PI/2.);
 			cairo_restore (cr);
 		} else {
 			cairo_line_to (cr, 0., rect->height);
 		}
 
-		if (priv->type&4) {
-			cairo_line_to (cr, rect->width - priv->rx, rect->height);
+		if (rect->type & 4) {
+			cairo_line_to (cr, rect->width - rect->rx, rect->height);
 			cairo_save (cr);
-			cairo_translate (cr, rect->width - priv->rx, rect->height - priv->ry);
-			cairo_scale (cr, priv->rx, priv->ry);
+			cairo_translate (cr, rect->width - rect->rx, rect->height - rect->ry);
+			cairo_scale (cr, rect->rx, rect->ry);
 			cairo_arc_negative (cr, 0., 0. ,1. , M_PI/2., 0.);
 			cairo_restore (cr);
 		} else {
 			cairo_line_to (cr, rect->width, rect->height);
 		}
 
-		if (priv->type&2) {
-			cairo_line_to (cr, rect->width, priv->ry);
+		if (rect->type & 2) {
+			cairo_line_to (cr, rect->width, rect->ry);
 			cairo_save (cr);
-			cairo_translate (cr, rect->width - priv->rx, priv->ry);
-			cairo_scale (cr, priv->rx, priv->ry);
+			cairo_translate (cr, rect->width - rect->rx, rect->ry);
+			cairo_scale (cr, rect->rx, rect->ry);
 			cairo_arc_negative (cr, 0., 0. ,1. , 0., -M_PI/2.);
 			cairo_restore (cr);
 		} else {
@@ -381,13 +364,6 @@ goc_rectangle_class_init (GocItemClass *item_klass)
 	item_klass->draw = goc_rectangle_draw;
 }
 
-static void
-goc_rectangle_init (GocRectangle *rect)
-{
-	GocRectPriv *priv = g_new0 (GocRectPriv, 1);
-	g_object_set_data_full (G_OBJECT (rect), "rect-private", priv, g_free);
-}
-
 GSF_CLASS (GocRectangle, goc_rectangle,
-	   goc_rectangle_class_init, goc_rectangle_init,
+	   goc_rectangle_class_init, NULL,
 	   GOC_TYPE_STYLED_ITEM)
diff --git a/goffice/canvas/goc-rectangle.h b/goffice/canvas/goc-rectangle.h
index f02d579..95b8f8e 100644
--- a/goffice/canvas/goc-rectangle.h
+++ b/goffice/canvas/goc-rectangle.h
@@ -27,11 +27,22 @@
 
 G_BEGIN_DECLS
 
+enum {
+	GOC_RECTANGLE_CORNER_NORMAL		= 0,
+	GOC_RECTANGLE_NW_CORNER_ROUND	= 1,
+	GOC_RECTANGLE_NE_CORNER_ROUND	= 2,
+	GOC_RECTANGLE_SW_CORNER_ROUND	= 4,
+	GOC_RECTANGLE_SE_CORNER_ROUND	= 8,
+	GOC_RECTANGLE_ALL_CORNERS_ROUND	= 15,
+};
+
 struct _GocRectangle {
 	GocStyledItem base;
 
 	double rotation; /* rotation around the center in radians */
 	double x, y, width, height;
+	int type;
+	double rx, ry;
 };
 
 typedef GocStyledItemClass GocRectangleClass;



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