[gnumeric] ODF: import/export interpolation



commit d92c0fcae3977cf6df70936a7f13a9be0ed226e4
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Wed Aug 18 12:23:19 2010 -0600

    ODF: import/export interpolation
    
    2010-08-18  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* samples/chart-tests.gnumeric: test plot types separately from our
    	  ability to combine them.
    
    2010-08-18  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_prop_list_to_series): also set properties
    	(oo_prop_list_has): new
    	(oo_prop_list_has_three_dimensional): replace with oo_prop_list_has
    	(oo_prop_list_has_multi_series): replace with oo_prop_list_has
    	(od_style_prop_chart): handle interpolation attribute
    	* openoffice-write.c (odf_write_interpolation_attribute): new
    	(odf_write_scatter_chart_style): use odf_write_interpolation_attribute
    	(odf_write_scatter_series_style): ditto

 ChangeLog                             |    5 ++
 plugins/openoffice/ChangeLog          |   11 ++++
 plugins/openoffice/openoffice-read.c  |   99 ++++++++++++++++++++-------------
 plugins/openoffice/openoffice-write.c |   36 ++++++++++++
 samples/chart-tests.gnumeric          |  Bin 2125851 -> 807197 bytes
 5 files changed, 113 insertions(+), 38 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 114e73e..be688c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-08-18  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* samples/chart-tests.gnumeric: test plot types separately from our
+	  ability to combine them.
+
 2010-08-16  Morten Welinder <terra gnome org>
 
 	* configure.in: Post-release bump.
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index ee153d0..35c556d 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,16 @@
 2010-08-18  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* openoffice-read.c (oo_prop_list_to_series): also set properties
+	(oo_prop_list_has): new
+	(oo_prop_list_has_three_dimensional): replace with oo_prop_list_has
+	(oo_prop_list_has_multi_series): replace with oo_prop_list_has
+	(od_style_prop_chart): handle interpolation attribute
+	* openoffice-write.c (odf_write_interpolation_attribute): new
+	(odf_write_scatter_chart_style): use odf_write_interpolation_attribute
+	(odf_write_scatter_series_style): ditto
+
+2010-08-18  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* openoffice-write.c (odf_write_line_chart_style): check the plot
 	(odf_write_scatter_chart_style): ditto
 	(odf_get_marker): new
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index d87511b..c80e602 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -3014,6 +3014,24 @@ oo_prop_list_free (GSList *props)
 }
 
 static void
+oo_prop_list_apply (GSList *props, GObject *obj)
+{
+	GSList *ptr;
+	OOProp *prop;
+	GObjectClass *klass;
+
+	if (NULL == obj)
+		return;
+	klass = G_OBJECT_GET_CLASS (obj);
+
+	for (ptr = props; ptr; ptr = ptr->next) {
+		prop = ptr->data;
+		if (NULL != g_object_class_find_property (klass, prop->name))
+			g_object_set_property (obj, prop->name, &prop->value);
+	}
+}
+
+static void
 oo_prop_list_to_series (GSList *props, GObject *obj)
 {
 	GOStyle *style = NULL;
@@ -3021,6 +3039,10 @@ oo_prop_list_to_series (GSList *props, GObject *obj)
 	int symbol_type = -1, symbol_name = GO_MARKER_DIAMOND;
 	GOMarker *m;
 
+	oo_prop_list_apply (props, obj);
+
+	/* There are properties that apply to subitems: */
+
 	g_object_get (obj, "style", &style, NULL);
 
 	if (style != NULL)
@@ -3065,30 +3087,13 @@ oo_prop_list_to_series (GSList *props, GObject *obj)
 }
 
 static void
-oo_prop_list_apply (GSList *props, GObject *obj)
-{
-	GSList *ptr;
-	OOProp *prop;
-	GObjectClass *klass;
-
-	if (NULL == obj)
-		return;
-	klass = G_OBJECT_GET_CLASS (obj);
-
-	for (ptr = props; ptr; ptr = ptr->next) {
-		prop = ptr->data;
-		if (NULL != g_object_class_find_property (klass, prop->name))
-			g_object_set_property (obj, prop->name, &prop->value);
-	}
-}
-
-static void
-oo_prop_list_has_three_dimensional (GSList *props, gboolean *threed)
+oo_prop_list_has (GSList *props, gboolean *threed, char const *tag)
 {
 	GSList *ptr;
 	for (ptr = props; ptr; ptr = ptr->next) {
 		OOProp *prop = ptr->data;
-		if (0 == strcmp (prop->name, "three-dimensional") && g_value_get_boolean (&prop->value))
+		if (0 == strcmp (prop->name, tag) && 
+		    g_value_get_boolean (&prop->value))
 			*threed = TRUE;
 	}
 }
@@ -3100,23 +3105,13 @@ oo_style_have_three_dimensional (GSList *styles)
 	gboolean is_three_dimensional = FALSE;
 	for (l = styles; l != NULL; l = l->next) {
 		OOChartStyle *style = l->data;
-		oo_prop_list_has_three_dimensional (style->other_props,
-						    &is_three_dimensional);
+		oo_prop_list_has (style->other_props,
+				   &is_three_dimensional,
+				   "three-dimensional");
 	}
 	return is_three_dimensional;
 }
 
-static void
-oo_prop_list_has_multi_series (GSList *props, gboolean *threed)
-{
-	GSList *ptr;
-	for (ptr = props; ptr; ptr = ptr->next) {
-		OOProp *prop = ptr->data;
-		if (0 == strcmp (prop->name, "multi-series") && g_value_get_boolean (&prop->value))
-			*threed = TRUE;
-	}
-}
-
 static gboolean
 oo_style_have_multi_series (GSList *styles)
 {
@@ -3124,8 +3119,9 @@ oo_style_have_multi_series (GSList *styles)
 	gboolean is_multi_series = FALSE;
 	for (l = styles; l != NULL; l = l->next) {
 		OOChartStyle *style = l->data;
-		oo_prop_list_has_multi_series (style->other_props,
-						    &is_multi_series);
+		oo_prop_list_has (style->other_props,
+				  &is_multi_series,
+				  "multi-series");
 	}
 	return is_multi_series;
 }
@@ -3225,17 +3221,44 @@ od_style_prop_chart (GsfXMLIn *xin, xmlChar const **attrs)
 				(style->series_props,
 				 oo_prop_new_int ("symbol-type", tmp));
 		} else if (oo_attr_enum (xin, attrs, OO_NS_CHART, "symbol-name", 
-				       named_symbols, &tmp)) {
+					 named_symbols, &tmp)) {
 			style->series_props = g_slist_prepend
 				(style->series_props,
 				 oo_prop_new_int ("symbol-name", tmp));
-		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_DRAW, "stroke")) {
+		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					       OO_NS_CHART, "interpolation")) {
+			char const *interpolation = NULL; 
+
+			if (attr_eq (attrs[1], "none"))
+				interpolation = "linear";
+			else if (attr_eq (attrs[1], "b-spline"))
+				interpolation = "spline";
+			else if (attr_eq (attrs[1], "cubic-spline"))
+				interpolation = "cspline";
+			else if (g_str_has_prefix (CXML2C(attrs[1]), "gnm:"))
+				interpolation = CXML2C(attrs[1]) + 4;
+			else oo_warning 
+				     (xin, _("Unknown interpolation type "
+					     "encountered: %s"), CXML2C(attrs[1]));
+
+			if (interpolation != NULL) {
+				style->series_props = g_slist_prepend
+					(style->series_props,
+					 oo_prop_new_string 
+					 ("interpolation", interpolation));
+				style->plot_props = g_slist_prepend
+					(style->plot_props,
+					 oo_prop_new_string 
+					 ("interpolation", interpolation));
+			}
+		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					       OO_NS_DRAW, "stroke")) {
 			draw_stroke = !attr_eq (attrs[1], "none");
 			draw_stroke_set = TRUE;
 			style->series_props = g_slist_prepend
 				(style->series_props,
 				 oo_prop_new_string ("stroke",
-						     attrs[1]));
+						     CXML2C(attrs[1])));
 		} else if (oo_attr_bool (xin, attrs, OO_NS_CHART, "lines", &btmp)) {
 			style->series_props = g_slist_prepend
 				(style->series_props,
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index cc238a7..f6a6772 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3646,6 +3646,38 @@ odf_write_line_chart_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *c
 }
 
 static void
+odf_write_interpolation_attribute (GnmOOExport *state, GogObject const *series) 
+{
+	gchar *interpolation = NULL;
+
+	g_object_get (G_OBJECT (series), "interpolation", 
+		      &interpolation, NULL);
+
+	if (interpolation != NULL) {
+		if (0 == strcmp (interpolation, "linear"))
+			gsf_xml_out_add_cstr 
+				(state->xml, CHART "interpolation", "none");
+		else if (0 == strcmp (interpolation, "spline"))
+			gsf_xml_out_add_cstr 
+				(state->xml, CHART "interpolation", "b-spline");
+		else if (0 == strcmp (interpolation, "cspline"))
+			gsf_xml_out_add_cstr 
+				(state->xml, CHART "interpolation", 
+				 "cubic-spline");
+		else {
+			char *tag = g_strdup_printf ("gnm:%s", interpolation);
+			gsf_xml_out_add_cstr 
+				(state->xml, CHART "interpolation", tag);
+			g_free (tag);
+		}
+	}
+
+	g_free (interpolation);
+}
+
+
+
+static void
 odf_write_scatter_chart_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *chart, GogObject const *plot)
 {
 	gboolean has_marker = TRUE;
@@ -3655,6 +3687,8 @@ odf_write_scatter_chart_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const
 	gsf_xml_out_add_cstr (state->xml, CHART "symbol-type", 
 			      has_marker ? "automatic" : "none");
 
+	odf_write_interpolation_attribute (state, plot);
+
 	gsf_xml_out_add_cstr (state->xml, DRAW "stroke", "none");
 	odf_add_bool (state->xml, CHART "lines", FALSE);
 }
@@ -3718,6 +3752,8 @@ odf_write_scatter_series_style (GnmOOExport *state, GogObject const *plot, GogOb
 {
 	GOStyle *style = NULL;
 
+	odf_write_interpolation_attribute (state, series);
+
 	g_object_get (G_OBJECT (series), "style", &style, NULL);
 
 	if (go_style_is_line_visible (style)) {
diff --git a/samples/chart-tests.gnumeric b/samples/chart-tests.gnumeric
index 8b5b640..52d6dc0 100644
Binary files a/samples/chart-tests.gnumeric and b/samples/chart-tests.gnumeric differ



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