[goffice] Fixed rectangle and ellips bounds.



commit 1d8ac732a3f89b4eaf823b7fe039003d5886b4a5
Author: Jean Brefort <jean brefort normalesup org>
Date:   Mon Mar 8 11:18:21 2010 +0100

    Fixed rectangle and ellips bounds.

 ChangeLog                               |   12 +++++
 docs/reference/goffice-0.8-sections.txt |   14 +++++
 docs/reference/goffice-docs.sgml        |    1 +
 goffice/canvas/goc-ellipse.c            |    9 +++-
 goffice/canvas/goc-rectangle.c          |    9 +++-
 goffice/canvas/goc-styled-item.c        |    6 +--
 goffice/utils/go-bezier.c               |    1 +
 goffice/utils/go-styled-object.c        |   81 +++++++++++++++++++++++++++++++
 tests/shapes-demo.c                     |   15 +++---
 9 files changed, 135 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e49f94d..3fd1c9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-03-08  Jean Brefort  <jean brefort normalesup org>
+
+	* docs/reference/goffice-0.8-sections.txt: added GocArc.
+	* docs/reference/goffice-docs.sgml: ditto.
+	* goffice/canvas/goc-ellipse.c (goc_ellipse_update_bounds): fixed bounds.
+	* goffice/canvas/goc-rectangle.c (goc_rectangle_update_bounds): ditto.
+	* goffice/canvas/goc-styled-item.c (goc_styled_item_set_property),
+	(goc_styled_item_style_changed): minor changes.
+	* goffice/utils/go-bezier.c: fix docs.
+	* goffice/utils/go-styled-object.c: add docs.
+	* tests/shapes-demo.c (parse_line): enhance style changes.
+
 2010-03-07  Jean Brefort  <jean brefort normalesup org>
 
 	* goffice/utils/go-style.c (go_style_set_cairo_line): fix hairline.
diff --git a/docs/reference/goffice-0.8-sections.txt b/docs/reference/goffice-0.8-sections.txt
index bdab3b0..8be0fa4 100644
--- a/docs/reference/goffice-0.8-sections.txt
+++ b/docs/reference/goffice-0.8-sections.txt
@@ -546,6 +546,7 @@ gog_label_get_type
 <FILE>gog-text</FILE>
 <TITLE>GogText</TITLE>
 GogText
+GogTextClass
 gog_text_get_str
 <SUBSECTION Private>
 gog_text_get_type
@@ -1612,6 +1613,7 @@ GOBezierSpline
 go_bezier_spline_init
 go_bezier_spline_destroy
 go_bezier_spline_to_path
+go_bezier_spline_to_cairo
 </SECTION>
 
 <SECTION>
@@ -2994,6 +2996,18 @@ GOC_ITEM_GET_CLASS
 </SECTION>
 
 <SECTION>
+<FILE>goc-arc</FILE>
+<TITLE>GocArc</TITLE>
+GocArc
+GocArcClass
+<SUBSECTION Standard>
+GOC_ARC
+GOC_IS_ARC
+GOC_TYPE_ARC
+goc_arc_get_type
+</SECTION>
+
+<SECTION>
 <FILE>goc-line</FILE>
 <TITLE>GocLine</TITLE>
 GocLine
diff --git a/docs/reference/goffice-docs.sgml b/docs/reference/goffice-docs.sgml
index dc88ccd..e3384fe 100644
--- a/docs/reference/goffice-docs.sgml
+++ b/docs/reference/goffice-docs.sgml
@@ -64,6 +64,7 @@
 		</chapter>
 		<chapter>
 			<title>Items</title>
+			<xi:include href="xml/goc-arc.xml"/>
 			<xi:include href="xml/goc-circle.xml"/>
 			<xi:include href="xml/goc-ellipse.xml"/>
 			<xi:include href="xml/goc-graph.xml"/>
diff --git a/goffice/canvas/goc-ellipse.c b/goffice/canvas/goc-ellipse.c
index ac8ac2b..58a8247 100644
--- a/goffice/canvas/goc-ellipse.c
+++ b/goffice/canvas/goc-ellipse.c
@@ -139,7 +139,14 @@ goc_ellipse_update_bounds (GocItem *item)
 	cr = cairo_create (surface);
 
 	if (goc_ellipse_prepare_draw (item, cr, 0)) {
-		cairo_stroke_extents (cr, &item->x0, &item->y0, &item->x1, &item->y1);
+		if (go_styled_object_set_cairo_line (GO_STYLED_OBJECT (item), cr))
+			cairo_stroke_extents (cr, &item->x0, &item->y0, &item->x1, &item->y1);
+		else if (go_styled_object_set_cairo_fill (GO_STYLED_OBJECT (item), cr))
+			cairo_fill_extents (cr, &item->x0, &item->y0, &item->x1, &item->y1);
+		else {
+			item->x0 = item->y0 = G_MAXDOUBLE;
+			item->x1 = item->y1 = -G_MAXDOUBLE;
+		}
 	}
 
 	cairo_destroy (cr);
diff --git a/goffice/canvas/goc-rectangle.c b/goffice/canvas/goc-rectangle.c
index d7095d4..b5c7b41 100644
--- a/goffice/canvas/goc-rectangle.c
+++ b/goffice/canvas/goc-rectangle.c
@@ -214,7 +214,14 @@ goc_rectangle_update_bounds (GocItem *item)
 	cr = cairo_create (surface);
 
 	if (goc_rectangle_prepare_draw (item, cr, 0)) {
-		cairo_stroke_extents (cr, &item->x0, &item->y0, &item->x1, &item->y1);
+		if (go_styled_object_set_cairo_line (GO_STYLED_OBJECT (item), cr))
+			cairo_stroke_extents (cr, &item->x0, &item->y0, &item->x1, &item->y1);
+		else if (go_styled_object_set_cairo_fill (GO_STYLED_OBJECT (item), cr))
+			cairo_fill_extents (cr, &item->x0, &item->y0, &item->x1, &item->y1);
+		else {
+			item->x0 = item->y0 = G_MAXDOUBLE;
+			item->x1 = item->y1 = -G_MAXDOUBLE;
+		}
 	}
 
 	cairo_destroy (cr);
diff --git a/goffice/canvas/goc-styled-item.c b/goffice/canvas/goc-styled-item.c
index ef72613..4aeb4ca 100644
--- a/goffice/canvas/goc-styled-item.c
+++ b/goffice/canvas/goc-styled-item.c
@@ -72,10 +72,8 @@ goc_styled_item_set_property (GObject *obj, guint param_id,
 	default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
 		 return; /* NOTE : RETURN */
 	}
-	if (resize) {
-		goc_item_invalidate (item);
+	if (resize)
 		goc_item_bounds_changed (item);
-	}
 	goc_item_invalidate (item);
 }
 
@@ -224,7 +222,7 @@ static void
 goc_styled_item_style_changed (GOStyledObject *gsi)
 {
 	GocItem *item = GOC_ITEM (gsi);
-	goc_item_bounds_changed (item);
+	goc_item_bounds_changed (item); /* FIXME: should not be ther, remove when we branch */
 	g_signal_emit (G_OBJECT (gsi),
 		goc_styled_item_signals [STYLE_CHANGED], 0, GOC_STYLED_ITEM (gsi)->style);
 	goc_item_invalidate (item);
diff --git a/goffice/utils/go-bezier.c b/goffice/utils/go-bezier.c
index be8b06b..7b4347e 100644
--- a/goffice/utils/go-bezier.c
+++ b/goffice/utils/go-bezier.c
@@ -340,6 +340,7 @@ go_bezier_spline_to_path (GOBezierSpline *sp)
  * go_bezier_spline_to_cairo:
  * @sp: a struct GOBezierSpline instance returned by go_bezier_spline_init
  * @cr: a cairo context
+ * @horiz_flip: whether to flip horizontally (for a RTL canvas).
  *
  * Renders the spline in \a cr
  **/
diff --git a/goffice/utils/go-styled-object.c b/goffice/utils/go-styled-object.c
index a0977c6..a3c7767 100644
--- a/goffice/utils/go-styled-object.c
+++ b/goffice/utils/go-styled-object.c
@@ -23,6 +23,24 @@
 #include <goffice/goffice-config.h>
 #include <goffice/utils/go-styled-object.h>
 
+/**
+ * SECTION:go-styled-object
+ * @short_description: Objects with style
+ *
+ * The common GInterface for all objects owning a GOStyle.
+ **/
+
+
+/**
+ * GOStyledObjectClass :
+ * @set_style: sets the object style.
+ * @get_style: returns the object current style.
+ * @get_auto_style: returns the default style for the object.
+ * @style_changed: called when the style changed.
+ * @apply_theme: apply the current theme if any to the object style.
+ * @get_document: returns the #GODoc associated to the object if any.
+ **/
+
 GType
 go_styled_object_get_type (void)
 {
@@ -50,6 +68,41 @@ go_styled_object_get_type (void)
  * Sets a new style for @gso, and emits "style-changed" signal. This function
  * does not take ownership of @style.
  *
+ * The best way to change the style is to set the "style" property.
+ *
+ * This function will fail if the new style and the previous style are the same.
+ * In that case, the function will always return false:
+ * <informalexample>
+ *  <programlisting>
+ *      style = go_styled_object_go_styled_object_set_styleget_style (gso);
+ *      style->line.width = 2;
+ *      size_changed = go_styled_object_set_style (gso, style);
+ *  </programlisting>
+ * </informalexample>
+ * In this sample, the call to #go_styled_object_set_style() is just useless. You
+ * need to check yourself if you really change the size, call
+ * #go_styled_object_style_changed() to trigger the "style-changed" event.
+ * So the following code is much better:
+ * <informalexample>
+ *  <programlisting>
+ *      style = go_styled_object_go_styled_object_set_styleget_style (gso);
+ *      if (style->line.width != 2.) {
+ *	      style->line.width = 2;
+ *	      go_styled_object_style_changed (gso);
+ *	      size_changed = true;
+ *      } else
+ *	      size_changed = FALSE;
+ *  </programlisting>
+ * </informalexample>
+ * or even better:
+ * <informalexample>
+ *  <programlisting>
+ *      style = go_style_dup (go_styled_object_go_styled_object_set_styleget_style (gso));
+ *      style->line.width = 2;
+ *      size_changed = go_styled_object_set_style (gso, style);
+ *      g_object_unref (style);
+ *  </programlisting>
+ * </informalexample>
  * return value: %TRUE if new style may lead to change of object size, which
  * happens when changing font size for example.
  **/
@@ -130,6 +183,14 @@ go_styled_object_apply_theme (GOStyledObject *gso, GOStyle *style)
 	if (klass->apply_theme)
 		klass->apply_theme (gso, style);
 }
+/**
+ * go_styled_object_get_document:
+ * @gso: a #GOStyledObject
+ *
+ * A #GODoc is necessary to store images. If no GODoc is associated with the
+ * object, image filling will not be supported.
+ * return value: the #GODoc associated with the object if any.
+ **/
 
 GODoc*
 go_styled_object_get_document (GOStyledObject *gso)
@@ -140,6 +201,16 @@ go_styled_object_get_document (GOStyledObject *gso)
 		klass->get_document (gso): NULL;
 }
 
+/**
+ * go_styled_object_set_cairo_line :
+ * @so: #GOStyledItem
+ * @cr: #cairo_t
+ *
+ * Prepares the cairo context @cr to draw a line according to the
+ * item style and canvas scale.
+ *
+ * Returns: %TRUE if the line is not invisible
+ **/
 gboolean
 go_styled_object_set_cairo_line (GOStyledObject const *so, cairo_t *cr)
 {
@@ -150,6 +221,16 @@ go_styled_object_set_cairo_line (GOStyledObject const *so, cairo_t *cr)
 	return go_style_set_cairo_line (style, cr);
 }
 
+/**
+ * go_styled_object_set_cairo_fill :
+ * @so: #GOStyledItem
+ * @cr: #cairo_t
+ *
+ * Prepares the cairo context @cr to fill a shape according to the
+ * item style and canvas scale.
+ *
+ * Returns: %TRUE if the filling is not invisible
+ **/
 gboolean
 go_styled_object_set_cairo_fill (GOStyledObject const *so, cairo_t *cr)
 {
diff --git a/tests/shapes-demo.c b/tests/shapes-demo.c
index 9dfaad0..c7cbb3f 100644
--- a/tests/shapes-demo.c
+++ b/tests/shapes-demo.c
@@ -116,9 +116,8 @@ parse_line (GocCanvas *canvas, gchar *entry)
 	GocGroup	*group;
 	GOStyle		*style;
 	GOArrow		*arr;
-	double		x=0,y=0;
-	guint			i;
-	int			cmd = -1;
+	guint		i;
+	int		cmd = -1;
 	
 	/* check for "comment" */
 	if (g_str_has_prefix (entry, "#"))
@@ -218,7 +217,7 @@ parse_line (GocCanvas *canvas, gchar *entry)
 		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 = go_style_dup (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)
@@ -228,21 +227,23 @@ parse_line (GocCanvas *canvas, gchar *entry)
 			} 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]));
 			}
-			go_styled_object_style_changed (GO_STYLED_OBJECT (item));
+			goc_item_set (item, "style", style, NULL);
+			g_object_unref (style);
 		}
 		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)); 
+			style = go_style_dup (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]));
 			}
-			go_styled_object_style_changed (GO_STYLED_OBJECT (item));
+			goc_item_set (item, "style", style, NULL);
+			g_object_unref (style);
 		}
 		break;
 	case 22: /* ARROW */



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