[goffice] GogObject: properly serialize float/double properties.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] GogObject: properly serialize float/double properties.
- Date: Wed, 23 Apr 2014 00:27:38 +0000 (UTC)
commit 6525619ea9053ec33b9e0f57bbc53955c6d3da18
Author: Morten Welinder <terra gnome org>
Date: Tue Apr 22 20:26:15 2014 -0400
GogObject: properly serialize float/double properties.
g_value_transform specifically says not to use to-string conversions
for serialization. It loses precision.
ChangeLog | 3 +++
goffice/graph/gog-object-xml.c | 22 +++++++++++++++++++---
2 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c119576..1e24497 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2014-04-22 Morten Welinder <terra gnome org>
+ * goffice/graph/gog-object-xml.c (gog_object_write_property_sax):
+ Properly handle float/double properties.
+
* goffice/utils/go-format.c (go_format_output_number_to_odf):
Handle TOK_REPEATED_CHAR.
diff --git a/goffice/graph/gog-object-xml.c b/goffice/graph/gog-object-xml.c
index 78665b2..6f55a98 100644
--- a/goffice/graph/gog-object-xml.c
+++ b/goffice/graph/gog-object-xml.c
@@ -72,7 +72,7 @@ gog_object_write_property_sax (GogObject const *obj, GParamSpec *pspec, GsfXMLOu
GValue value = { 0 };
g_value_init (&value, prop_type);
- g_object_get_property (G_OBJECT (obj), pspec->name, &value);
+ g_object_get_property (G_OBJECT (obj), pspec->name, &value);
/* No need to save default values */
if (((pspec->flags & GOG_PARAM_POSITION) &&
@@ -92,8 +92,6 @@ gog_object_write_property_sax (GogObject const *obj, GParamSpec *pspec, GsfXMLOu
case G_TYPE_UINT:
case G_TYPE_LONG:
case G_TYPE_ULONG:
- case G_TYPE_FLOAT:
- case G_TYPE_DOUBLE:
case G_TYPE_ENUM:
case G_TYPE_FLAGS: {
GValue str = { 0 };
@@ -107,6 +105,24 @@ gog_object_write_property_sax (GogObject const *obj, GParamSpec *pspec, GsfXMLOu
break;
}
+ case G_TYPE_FLOAT:
+ case G_TYPE_DOUBLE: {
+ GValue vd = { 0 };
+ GString *str = g_string_new (NULL);
+
+ g_value_init (&vd, G_TYPE_DOUBLE);
+ g_value_transform (&value, &vd);
+ go_dtoa (str, "!g", g_value_get_double (&vd));
+ g_value_unset (&vd);
+
+ gsf_xml_out_start_element (output, "property");
+ gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
+ gsf_xml_out_add_cstr (output, NULL, str->str);
+ gsf_xml_out_end_element (output); /* </property> */
+ g_string_free (str, TRUE);
+ break;
+ }
+
case G_TYPE_STRING: {
char const *str = g_value_get_string (&value);
if (str != NULL) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]