[gnumeric] xlsx: don't use xml:space in shared string table.



commit 5cc99b4b9a17f2d4b75a241f60936db5a52b0677
Author: Morten Welinder <terra gnome org>
Date:   Thu Jun 5 15:41:08 2014 -0400

    xlsx: don't use xml:space in shared string table.
    
    The schema doesn't allow it.  (But Excel writes it.)

 plugins/excel/ChangeLog    |    2 ++
 plugins/excel/xlsx-write.c |   29 ++++++++++++++++-------------
 2 files changed, 18 insertions(+), 13 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 8df4e10..9afe7ba 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -2,6 +2,8 @@
 
        * xlsx-write.c (xlsx_write_rich_text): Fix color attribute.  Only
        write xml:space attribute when text has spaces.
+       (xlsx_write_rich_text): Only write xml:space in contexts where the
+       schema allow it.  The shared strings table does not allow it.
 
 2014-06-03  Morten Welinder  <terra gnome org>
 
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index b2e28a5..22e10aa 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -264,7 +264,8 @@ xlsx_find_predefined_fill (GnmStyle const *style)
 /****************************************************************************/
 
 static void
-xlsx_write_rich_text (GsfXMLOut *xml, char const *text, PangoAttrList *attrs)
+xlsx_write_rich_text (GsfXMLOut *xml, char const *text, PangoAttrList *attrs,
+                     gboolean allow_xml_space)
 {
        PangoAttrIterator *iter;
        int start, end, max;
@@ -377,17 +378,19 @@ xlsx_write_rich_text (GsfXMLOut *xml, char const *text, PangoAttrList *attrs)
                    end = max;
                if (start < end) {
                        char *buf = g_strndup (text + start, end - start);
-                       const char *p;
-                       gboolean has_space = FALSE;
-                       for (p = buf; *p; p = g_utf8_next_char (p)) {
-                               if (g_unichar_isspace (g_utf8_get_char (p))) {
-                                       has_space = TRUE;
-                                       break;
+                       if (allow_xml_space) {
+                               const char *p;
+                               gboolean has_space = FALSE;
+                               for (p = buf; *p; p = g_utf8_next_char (p)) {
+                                       if (g_unichar_isspace (g_utf8_get_char (p))) {
+                                               has_space = TRUE;
+                                               break;
+                                       }
                                }
+                               if (has_space)
+                                       gsf_xml_out_add_cstr_unchecked
+                                               (xml, "xml:space", "preserve");
                        }
-                       if (has_space)
-                               gsf_xml_out_add_cstr_unchecked
-                                       (xml, "xml:space", "preserve");
                        gsf_xml_out_add_cstr (xml, NULL, buf);
                        g_free (buf);
                }
@@ -443,7 +446,6 @@ xlsx_write_shared_strings (XLSXWriteState *state, GsfOutfile *wb_part)
 
        gsf_xml_out_start_element (xml, "sst");
        gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_ss);
-       /* Note the schema does not allow the attribute xml:space */
        gsf_xml_out_add_int (xml, "uniqueCount", N);
        gsf_xml_out_add_int (xml, "count", N);
 
@@ -456,7 +458,8 @@ xlsx_write_shared_strings (XLSXWriteState *state, GsfOutfile *wb_part)
                gsf_xml_out_start_element (xml, "si");
                xlsx_write_rich_text (xml,
                                      value_peek_string (val),
-                                     attrs);
+                                     attrs,
+                                     FALSE);
                gsf_xml_out_end_element (xml); /* </si> */
        }
 
@@ -2630,7 +2633,7 @@ xlsx_write_comments (XLSXWriteState *state, GsfOutput *sheet_part, GSList *objec
                /* Save text as rich text */
                g_object_get (ptr->data, "text", &name, "markup", &attrs, NULL);
                if (name && *name)
-                       xlsx_write_rich_text (xml, name, attrs);
+                       xlsx_write_rich_text (xml, name, attrs, TRUE);
                g_free (name);
                pango_attr_list_unref (attrs);
                gsf_xml_out_end_element (xml); /* </text> */


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