[goffice] Improve conditional format roundtrip through ODF. [part of 725852]



commit af931adcc6da60a40394e16ae323ee3e109c2d5a
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Thu Mar 20 22:44:54 2014 -0600

    Improve conditional format roundtrip through ODF. [part of 725852]
    
    2014-03-20 Andreas J. Guelzow <aguelzow pyrshep ca>
    
        * goffice/utils/go-format.c (go_format_odf_style_map): figure
        out the correct number of digits to use for condition values

 ChangeLog                 |    5 +++++
 NEWS                      |    3 +++
 goffice/utils/go-format.c |   16 +++++++++++++---
 3 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6726eeb..f2413bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-20 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+       * goffice/utils/go-format.c (go_format_odf_style_map): figure
+       out the correct number of digits to use for condition values
+
 2014-03-18  Morten Welinder <terra gnome org>
 
        * Release 0.10.13
diff --git a/NEWS b/NEWS
index 443a386..3574601 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 goffice 0.10.14:
 
+Andreas:
+       * Improve conditional format roundtrip through ODF. [part of 725852]
+
 --------------------------------------------------------------------------
 goffice 0.10.13:
 
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 2e0d694..629df49 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -7379,6 +7379,9 @@ char *
 go_format_odf_style_map (GOFormat const *fmt, int cond_part)
 {
        char const *format_string = NULL;
+       GString *gstr;
+       int digits;
+       double l10;
 
        g_return_val_if_fail (fmt != NULL, NULL);
        g_return_val_if_fail (fmt->typ == GO_FMT_COND, NULL);
@@ -7386,6 +7389,9 @@ go_format_odf_style_map (GOFormat const *fmt, int cond_part)
        if (cond_part >= fmt->u.cond.n)
                return NULL;
 
+       l10 = log10 (FLT_RADIX);
+       digits = (int)ceil (DBL_MANT_DIG * l10) + (l10 == (int)l10 ? 0 : 1);
+
        switch (fmt->u.cond.conditions[cond_part].op) {
        case GO_FMT_COND_EQ:
                format_string = "value()=%g";
@@ -7410,9 +7416,13 @@ go_format_odf_style_map (GOFormat const *fmt, int cond_part)
        default:
                return NULL;
        }
-       return g_strdup_printf (format_string,
-                               fmt->u.cond.conditions[cond_part].val);
-
+       
+       gstr = g_string_new (format_string);
+       g_string_append_printf (gstr, "%.*g",
+                               digits,
+                               fmt->u.cond.conditions[cond_part].val);
+ 
+       return g_string_free (gstr, FALSE);
 }
 #endif
 


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