[goffice] Update shapes-demo.



commit 0f466c39d937a778b9e9514e1acf1d72a850597e
Author: Jean Brefort <jean brefort normalesup org>
Date:   Sat Mar 6 09:40:12 2010 +0100

    Update shapes-demo.

 ChangeLog                     |    7 +
 goffice/canvas/goc-polyline.c |    2 +-
 tests/shapes-demo.c           |  339 +++++++++++++++++++----------------------
 3 files changed, 167 insertions(+), 181 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7b775aa..7f0a20b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-03-06  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/canvas/goc-polyline.c (goc_polyline_draw): missing white spaces.
+	* tests/shapes-demo.c (my_test), (parse_line), (enter_callback): add
+	missing calls to goc_item_bounds_changed and fix white spaces and other
+	presentation issues.
+
 2010-03-06  Valek Filippov  <frob gnome org>
 
 	* goffice/canvas/goc-arc.c (prepare_draw_arrow),
diff --git a/goffice/canvas/goc-polyline.c b/goffice/canvas/goc-polyline.c
index 3787a13..472d159 100644
--- a/goffice/canvas/goc-polyline.c
+++ b/goffice/canvas/goc-polyline.c
@@ -196,7 +196,7 @@ static void
 goc_polyline_draw (GocItem const *item, cairo_t *cr)
 {
 	cairo_save (cr);
-	if (goc_polyline_prepare_draw (item,cr,1)) {
+	if (goc_polyline_prepare_draw (item, cr, 1)) {
 		cairo_stroke (cr);
 	}
 	cairo_restore (cr);
diff --git a/tests/shapes-demo.c b/tests/shapes-demo.c
index c536e99..f7b4b42 100644
--- a/tests/shapes-demo.c
+++ b/tests/shapes-demo.c
@@ -36,8 +36,8 @@ open_file (GocCanvas* canvas, char* filename)
 	s = (char *) malloc (n + 1);
 	
 	if (NULL == (fd = fopen (filename, "r"))) {
-	 g_print ("The file can't be opened!\n");
-	 return;
+		g_print ("The file can't be opened!\n");
+		return;
 	}
 
 	while (-1 != getline (&s, &n, fd)) {
@@ -100,8 +100,7 @@ my_test (GocCanvas *canvas, GdkEventButton *event, G_GNUC_UNUSED gpointer data)
 		if (2 == event->button) {
 			ppu *= 1.5;
 			goc_canvas_set_pixels_per_unit (canvas, ppu);
-		} else
-		if (3 == event->button){
+		} else if (3 == event->button) {
 			ppu /= 1.5;
 			goc_canvas_set_pixels_per_unit (canvas, ppu);
 		}
@@ -110,7 +109,7 @@ my_test (GocCanvas *canvas, GdkEventButton *event, G_GNUC_UNUSED gpointer data)
 }
 
 static void
-parse_line(GocCanvas *canvas, const gchar *entry)
+parse_line (GocCanvas *canvas, const gchar *entry)
 {
 	gchar		**v = NULL;
 	GocItem		*item;
@@ -121,228 +120,208 @@ parse_line(GocCanvas *canvas, const gchar *entry)
 	guint			i;
 	int			cmd = -1;
 	
-	// check for "comment"
+	/* check for "comment" */
 	if (g_str_has_prefix (entry, "#"))
 		return;
 
 	g_strstrip (entry);
 	v = g_strsplit_set (entry, " ", -1);
 
-	if (v != NULL){
+	if (v != NULL) {
 		if (g_ascii_strcasecmp (v[0], "ARC") == 0) {
 			cmd = 0;
-		}else
-		if (g_ascii_strcasecmp (v[0], "CHORD") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "CHORD") == 0) {
 			cmd = 1;
-		}else
-		if (g_ascii_strcasecmp (v[0], "PIE") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "PIE") == 0) {
 			cmd = 2;
-		}else
-		if (g_ascii_strcasecmp (v[0], "LINE") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "LINE") == 0) {
 			cmd = 3;
-		}else
-		if (g_ascii_strcasecmp (v[0], "RECT") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "RECT") == 0) {
 			cmd = 4;
-		}else
-		if (g_ascii_strcasecmp (v[0], "OVAL") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "OVAL") == 0) {
 			cmd = 5;
-		}else
-		if (g_ascii_strcasecmp (v[0], "POLYL") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "POLYL") == 0) {
 			cmd = 6;
-		}else
-		if (g_ascii_strcasecmp (v[0], "POLYG") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "POLYG") == 0) {
 			cmd = 7;
-		}else
-		if (g_ascii_strcasecmp (v[0], "STROKE") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "STROKE") == 0) {
 			cmd = 20;
-		}else
-		if (g_ascii_strcasecmp (v[0], "FILL") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "FILL") == 0) {
 			cmd = 21;
-		}else
-		if (g_ascii_strcasecmp (v[0], "ARROW") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "ARROW") == 0) {
 			cmd = 22;
-		}else
-		if (g_ascii_strcasecmp (v[0], "RTL") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "RTL") == 0) {
 			cmd = 100;
-		}else
-		if (g_ascii_strcasecmp (v[0], "SCROLL") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "SCROLL") == 0) {
 			cmd = 101;
-		}else
-		if (g_ascii_strcasecmp (v[0], "DEL") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "DEL") == 0) {
 			cmd = 102;
-		}else
-		if (g_ascii_strcasecmp (v[0], "FILE") == 0) {
+		} else if (g_ascii_strcasecmp (v[0], "FILE") == 0) {
 			cmd = 1000;
 		}
 	}
 
-	switch (cmd){
-		case -1:
-			break;
-		case 0:
-		case 1:
-		case 2: // ARC / CHORD / PIE
-			if (g_strv_length (v) > 6) {
-				item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_ARC,
-					"xc", (double) atoi(v[1]), "yc", (double) atoi(v[2]), "xr", (double) atoi(v[3]), "yr", (double) atoi(v[4]),
-					"ang1", (double) atoi(v[5])*M_PI/180., "ang2", (double) atoi(v[6])*M_PI/180.,"type",cmd, NULL);
-				if (g_strv_length (v) > 7) {
-					goc_item_set (item, "rotation", (double) atoi(v[7])*M_PI/180., NULL);
-				}
-				goc_item_invalidate (item);
+	switch (cmd) {
+	case -1:
+		break;
+	case 0:
+	case 1:
+	case 2: /* ARC / CHORD / PIE */
+		if (g_strv_length (v) > 6) {
+			item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_ARC,
+				"xc", (double) atoi (v[1]), "yc", (double) atoi (v[2]), "xr", (double) atoi (v[3]), "yr", (double) atoi (v[4]),
+				"ang1", (double) atoi (v[5]) * M_PI / 180., "ang2", (double) atoi (v[6]) * M_PI / 180., "type", cmd, NULL);
+			if (g_strv_length (v) > 7) {
+				goc_item_set (item, "rotation", (double) atoi (v[7]) * M_PI/ 180., NULL);
 			}
-			break;
-		case 3: // LINE
-			if (g_strv_length (v) > 4) {
-				item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_LINE,
-					"x0", (double) atoi(v[1]), "y0", (double) atoi(v[2]), "x1", (double) atoi(v[3]), "y1", (double) atoi(v[4]), NULL);
-				goc_item_invalidate (item);
+			goc_item_invalidate (item);
+		}
+		break;
+	case 3: /* LINE */
+		if (g_strv_length (v) > 4) {
+			item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_LINE,
+				"x0", (double) atoi (v[1]), "y0", (double) atoi (v[2]), "x1", (double) atoi (v[3]), "y1", (double) atoi (v[4]), NULL);
+			goc_item_invalidate (item);
+		}
+		break;
+	case 4: /* RECTANGLE */
+		if (g_strv_length (v) > 4) {
+			item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_RECTANGLE,
+				"x", (double) atoi (v[1]), "y", (double) atoi (v[2]), "width", (double) atoi (v[3]), "height", (double) atoi (v[4]), NULL);
+			if( g_strv_length (v) > 5) {
+				goc_item_set (item, "rotation", (double) atoi (v[5]) * M_PI / 180., NULL);
 			}
-			break;
-		case 4: // RECTANGLE
-			if (g_strv_length (v) > 4) {
-				item = goc_item_new (goc_canvas_get_root(canvas), GOC_TYPE_RECTANGLE,
-					"x", (double) atoi(v[1]), "y", (double) atoi(v[2]), "width", (double) atoi(v[3]), "height", (double) atoi(v[4]), NULL);
-				if( g_strv_length (v) > 5) {
-					goc_item_set (item, "rotation", (double) atoi(v[5])*M_PI/180., NULL);
-				}
-				goc_item_invalidate(item);
+			goc_item_invalidate (item);
+		}
+		break;
+	case 5: /* ELLIPSE */
+		if(g_strv_length(v) > 4) {
+			item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_ELLIPSE,
+				"x", (double) atoi (v[1]), "y", (double) atoi (v[2]), "width", (double) atoi (v[3]), "height", (double) atoi (v[4]), NULL);
+			if(g_strv_length (v) > 5) {
+				goc_item_set (item,"rotation",(double) atoi (v[5]) * M_PI / 180., NULL);
 			}
-			break;
-		case 5: // ELLIPSE
-			if(g_strv_length(v) > 4) {
-				item = goc_item_new(goc_canvas_get_root(canvas), GOC_TYPE_ELLIPSE,
-					"x", (double) atoi(v[1]), "y", (double) atoi(v[2]), "width", (double) atoi(v[3]), "height", (double) atoi(v[4]), NULL);
-				if(g_strv_length(v) > 5) {
-					goc_item_set(item,"rotation",(double) atoi(v[5])*M_PI/180., NULL);
-				}
-				goc_item_invalidate (item);
+			goc_item_invalidate (item);
+		}
+		break;
+	case 6: /* POLY */
+	case 7:
+		if(g_strv_length(v) > 2) {
+			GocPoints *points = goc_points_new ((g_strv_length(v) - 1) / 2);
+			for (i=0; i < g_strv_length (v) / 2; i++) {
+				points->points[i].x = atoi (v[i * 2 + 1]);
+				points->points[i].y = atoi (v[i * 2 + 2]);
 			}
-			break;
-		case 6: // POLY
-		case 7:
-			if(g_strv_length(v) > 2) {
-				GocPoints *points = goc_points_new ((g_strv_length(v) - 1)/2);
-				for (i=0; i < g_strv_length (v)/2; i++){
-					points->points[i].x = atoi(v[i * 2 + 1]);
-					points->points[i].y = atoi(v[i * 2 + 2]);
-				}
-				if (cmd == 6) {
-					item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_POLYLINE, "points", points, NULL);
-				} else {
-					item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_POLYGON, "points", points, NULL);
-				}
-				goc_item_invalidate (item);
+			if (cmd == 6)
+				item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_POLYLINE, "points", points, NULL);
+			else
+				item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_POLYGON, "points", points, NULL);
+			goc_item_invalidate (item);
+		}
+		break;
+	case 20: /* STROKE */
+		group = (GocGroup*) goc_canvas_get_root (canvas);
+		item = g_list_nth_data (group->children, atoi (v[1]));
+		if (item != NULL && g_strv_length (v) > 2) {
+			style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
+			style->line.width = atoi (v[2]);
+			if (g_ascii_strcasecmp (v[2], "DASH") == 0) {
+				if(g_strv_length (v) > 3)
+					style->line.dash_type = atoi (v[3]);
+				else
+					style->line.dash_type = 0;
+			} else if (g_strv_length(v) > 6) {
+				style->line.color = GO_COLOR_FROM_RGBA (atoi (v[3]), atoi (v[4]), atoi (v[5]), atoi (v[6]));
 			}
-			break;
-		case 20: // STROKE
-			group = (GocGroup*) goc_canvas_get_root (canvas);
-			item = g_list_nth_data (group->children, atoi(v[1]));
-			if (item != NULL && g_strv_length (v) > 2) {
-				style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
-				style->line.width = atoi(v[2]);
-				if (g_ascii_strcasecmp (v[2], "DASH") == 0) {
-					if(g_strv_length (v) > 3) {
-						style->line.dash_type = atoi(v[3]);
-					} else {
-						style->line.dash_type = 0;
-					}
-				} else
-				if (g_strv_length(v) > 6) {
-					style->line.color = GO_COLOR_FROM_RGBA (atoi(v[3]), atoi(v[4]), atoi(v[5]), atoi(v[6]));
-				}
-				goc_item_invalidate (item);
+			goc_item_bounds_changed (item);
+			goc_item_invalidate (item);
+		}
+		break;
+	case 21: /* FILL */
+		group = (GocGroup*) goc_canvas_get_root (canvas);
+		item = g_list_nth_data (group->children, atoi (v[1]));
+		if (item != NULL && g_strv_length (v) > 2) {
+			style = go_styled_object_get_style (GO_STYLED_OBJECT (item)); 
+			if (g_ascii_strcasecmp (v[2], "NONE") == 0) {
+				style->fill.type = GO_STYLE_FILL_NONE;
+			} else if (g_strv_length (v) > 5) {
+				style->fill.type = GO_STYLE_FILL_PATTERN;
+				style-> fill.pattern.back = GO_COLOR_FROM_RGBA (atoi (v[2]), atoi (v[3]), atoi (v[4]), atoi (v[5]));
 			}
-			break;
-		case 21: // FILL
-			group = (GocGroup*) goc_canvas_get_root (canvas);
-			item = g_list_nth_data (group->children, atoi(v[1]));
-			if (item != NULL && g_strv_length (v) > 2) {
-				style = go_styled_object_get_style (GO_STYLED_OBJECT (item)); 
-				if (g_ascii_strcasecmp (v[2], "NONE") == 0) {
-					style->fill.type = GO_STYLE_FILL_NONE;
-				} else
-				if (g_strv_length (v) > 5) {
-					style->fill.type = GO_STYLE_FILL_PATTERN;
-					style-> fill.pattern.back = GO_COLOR_FROM_RGBA (atoi(v[2]), atoi(v[3]), atoi(v[4]), atoi(v[5]));
+			goc_item_bounds_changed (item);
+			goc_item_invalidate (item);
+		}
+		break;
+	case 22: /* ARROW */
+		group = (GocGroup*) goc_canvas_get_root (canvas);
+		item = g_list_nth_data (group->children, atoi (v[1]));
+		if (item != NULL) {
+			if(g_strv_length (v) > 6) {
+				arr = g_new0 (GOArrow, 1);
+				if(arr) {
+					if (atoi (v[2]) == 0)
+						go_arrow_init_kite (arr, atoi (v[3]), atoi (v[4]), atoi (v[5]));
+					else
+						go_arrow_init_oval (arr, atoi (v[3]), atoi (v[4]));
+					if (atoi (v[6]) == 0)
+						goc_item_set (item, "start-arrow", arr, NULL);
+					else
+						goc_item_set (item, "end-arrow", arr, NULL);
 				}
-				goc_item_invalidate (item);
 			}
-			break;
-		case 22: // ARROW
+		}
+		goc_item_bounds_changed (item);
+		break;
+	case 100: /* RTL */
+		if (g_strv_length (v) > 1) {
+			canvas->direction = atoi (v[1]);
+			goc_canvas_get_scroll_position (canvas, &x, &y);
+			goc_canvas_scroll_to (canvas, x+1, y+1);
+			goc_canvas_scroll_to (canvas, x, y);
+		}
+		break;
+	case 101: /* SCROLL */
+		if (g_strv_length (v) > 2)
+			goc_canvas_scroll_to (canvas, atoi (v[1]), atoi (v[2]));
+		break;
+	case 102: /* DELETE */
+		if (v[1] != NULL && atoi (v[1]) > 0) { /* crash with 0, why? */
 			group = (GocGroup*) goc_canvas_get_root (canvas);
-			item = g_list_nth_data (group->children, atoi(v[1]));
-			if (item != NULL) {
-				if(g_strv_length (v) > 6) {
-					arr = g_new0 (GOArrow, 1);
-					if(arr){
-						if (atoi(v[2]) == 0) {
-							go_arrow_init_kite (arr, atoi(v[3]), atoi(v[4]), atoi(v[5]));
-						} else {
-							go_arrow_init_oval (arr, atoi(v[3]), atoi(v[4]));
-						}
-						if (atoi(v[6]) == 0) {
-							goc_item_set (item, "start-arrow", arr, NULL);
-						} else {
-							goc_item_set (item, "end-arrow", arr, NULL);
-						}
-					}
-				}
-			}
-			goc_item_bounds_changed (item);
-			break;
-		case 100: // RTL
-			if (g_strv_length (v) > 1) {
-				canvas->direction = atoi(v[1]);
-				goc_canvas_get_scroll_position (canvas, &x, &y);
-				goc_canvas_scroll_to (canvas, x+1, y+1);
-				goc_canvas_scroll_to (canvas, x, y);
-			}
-			break;
-		case 101: // SCROLL
-			if (g_strv_length (v) > 2) {
-				goc_canvas_scroll_to (canvas, atoi(v[1]), atoi(v[2]));
-			}
-			break;
-		case 102: // DELETE
-			if (v[1] != NULL && atoi(v[1]) > 0) { // crash with 0, why?
-				group = (GocGroup*) goc_canvas_get_root (canvas);
-				item = g_list_nth_data (group->children, atoi(v[1]));
-				if (item != NULL)
-					g_list_remove (group->children, item);
-
-				goc_canvas_get_scroll_position (canvas, &x, &y);
-				goc_canvas_scroll_to (canvas, x+1, y+1);
-				goc_canvas_scroll_to (canvas, x, y);
+			item = g_list_nth_data (group->children, atoi (v[1]));
+			if (item != NULL)
+				g_list_remove (group->children, item);
 
-			}
-			break;
-		case 1000: // FILE
-			if (v[1] != NULL) {
-				open_file (canvas, v[1]);
-			} else {
-				on_open (canvas);
-			}
-			
-			break;
-		default:
-			break;
+			goc_canvas_get_scroll_position (canvas, &x, &y);
+			goc_canvas_scroll_to (canvas, x + 1, y + 1);
+			goc_canvas_scroll_to (canvas, x, y);
+
+		}
+		break;
+	case 1000: /* FILE */
+		if (v[1] != NULL) {
+			open_file (canvas, v[1]);
+		} else {
+			on_open (canvas);
+		}
+		
+		break;
+	default:
+		break;
 	}
 
-	if (v != NULL) {
+	if (v != NULL)
 		g_strfreev (v);
-	}
 }
 
 
 static void
-enter_callback(GocCanvas* canvas, GtkWidget *entry, G_GNUC_UNUSED gpointer data)
+enter_callback (GocCanvas* canvas, GtkWidget *entry, G_GNUC_UNUSED gpointer data)
 {
 	const gchar *entry_text;
-	const gchar *clean="";
+	const gchar *clean = "";
 			
 	entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
-	if (0 != gtk_entry_get_text_length (GTK_ENTRY (entry))){
+	if (0 != gtk_entry_get_text_length (GTK_ENTRY (entry))) {
 		g_print ("%s\n", entry_text);
 		parse_line (canvas, entry_text);
 		gtk_entry_set_text (GTK_ENTRY (entry), clean);



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