[gnumeric] xlsx: improve gradient stop export.



commit 28ef0a995f971a097eccacf783e2183e3e987518
Author: Morten Welinder <terra gnome org>
Date:   Thu Feb 19 08:14:59 2015 -0500

    xlsx: improve gradient stop export.

 plugins/excel/ChangeLog            |    9 ++++++++
 plugins/excel/xlsx-read-drawing.c  |    2 +-
 plugins/excel/xlsx-read.c          |   39 ++++++++++++++++++++++++++++++++++++
 plugins/excel/xlsx-write-drawing.c |    6 +++-
 4 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 5561741..2bcbc23 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,12 @@
+2015-02-19  Morten Welinder  <terra gnome org>
+
+       * xlsx-write-drawing.c (xlsx_write_go_style_full): Write gradient
+       position as "50%", not "50000".  Excel understands either, but the
+       schemas wants the first.  Note, that online schemas seem to differ
+       and want the latter.
+
+       * xlsx-read.c (attr_percent): New function to read either syntax.
+
 2015-02-17  Morten Welinder  <terra gnome org>
 
        * ms-excel-write.c (excel_collect_validations): Plug leak.
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index aa85e50..08bf107 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -1716,7 +1716,7 @@ xlsx_chart_grad_stop (GsfXMLIn *xin, xmlChar const **attrs)
 
        g_return_if_fail (state->cur_style);
        for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
-               if (attr_int (xin, attrs, "pos", &pos))
+               if (attr_percent (xin, attrs, "pos", &pos))
                        ; /* Nothing */
        }
 
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index b91bd69..a8a7a77 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -585,6 +585,45 @@ attr_float (GsfXMLIn *xin, xmlChar const **attrs,
        return TRUE;
 }
 
+/*
+ * Either an integer scaled so 100000 means 100%, or something like "50%"
+ * which we'll return as 50*1000.
+ *
+ * The first seems off-spec, but is what Excel produces.
+ */
+static gboolean
+attr_percent (GsfXMLIn *xin, xmlChar const **attrs,
+             char const *target, int *res)
+{
+       char *end;
+       long tmp;
+
+       g_return_val_if_fail (attrs != NULL, FALSE);
+       g_return_val_if_fail (attrs[0] != NULL, FALSE);
+       g_return_val_if_fail (attrs[1] != NULL, FALSE);
+
+       if (strcmp (attrs[0], target))
+               return FALSE;
+
+       errno = 0;
+       tmp = strtol (attrs[1], &end, 10);
+       if (errno == ERANGE || tmp > G_MAXINT / 1000 || tmp < G_MININT / 1000)
+               return xlsx_warning (xin,
+                       _("Integer '%s' is out of range, for attribute %s"),
+                       attrs[1], target);
+       if (*end == 0)
+               *res = tmp;
+       else if (strcmp (end, "%") == 0)
+               *res = tmp * 1000;
+       else
+               return xlsx_warning (xin,
+                       _("Invalid integer '%s' for attribute %s"),
+                       attrs[1], target);
+
+       return TRUE;
+}
+
+
 static gboolean
 attr_pos (GsfXMLIn *xin, xmlChar const **attrs,
          char const *target,
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index f9e06d4..dc4cf27 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -336,9 +336,11 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
                                gboolean fore = rev ^ (i == 1);
                                unsigned pos = (i == 0)
                                        ? 0
-                                       : (i == N - 1 ? 100 * 1000 : 50 * 1000);
+                                       : (i == N - 1 ? 100 : 50);
+                               char *spos = g_strdup_printf ("%d%%", pos);
                                gsf_xml_out_start_element (xml, "a:gs");
-                               gsf_xml_out_add_uint (xml, "pos", pos);
+                               gsf_xml_out_add_cstr_unchecked (xml, "pos", spos);
+                               g_free (spos);
                                xlsx_write_rgbarea (xml,
                                                    fore
                                                    ? style->fill.pattern.fore


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