[gnumeric] ods: fix style export problem.



commit 03746d56868601ef7bccb717e6037cad7d5f1efb
Author: Morten Welinder <terra gnome org>
Date:   Sun Aug 30 22:51:30 2020 -0400

    ods: fix style export problem.
    
    This is fallout from conditional style changes.

 plugins/openoffice/ChangeLog          |  6 ++++++
 plugins/openoffice/openoffice-write.c | 20 ++++++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index c9532a3c5..ccc86379d 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,9 @@
+2020-08-30  Morten Welinder  <terra gnome org>
+
+       * openoffice-write.c (odf_store_this_named_style): Handle the same
+       style showing up more than once.  (Fallout from conditional
+       formatting changes.)
+
 2020-08-29  Morten Welinder  <terra gnome org>
 
        * openoffice-write.c (odf_xml_end_element_check): New function to
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index d7c03b958..e2d90cfb6 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1792,20 +1792,28 @@ odf_save_this_style_with_name (GnmStyleRegion *sr, char const *name, GnmOOExport
 static void
 odf_store_this_named_style (GnmStyle *style, char const *name, GnmRange *r, GnmOOExport *state)
 {
-       char *real_name;
+       char *real_name = NULL;
+       const char *old_name;
        GnmStyleConditions const *sc;
 
-       if (name == NULL) {
+       old_name = g_hash_table_lookup (state->named_cell_styles, style);
+
+       if (name) {
+               if (old_name)
+                       g_warning ("Unexpected style name reuse.");
+               real_name = g_strdup (name);
+       } else if (!old_name) {
                int i = g_hash_table_size (state->named_cell_styles);
                 /* All styles referenced by a style:map need to be named, so in that case */
                /* we make up a name, that ought to look nice */
                real_name = g_strdup_printf ("Gnumeric-%i", i);
-       } else
-               real_name = g_strdup (name);
+       }
+
+       if (!old_name)
+               g_hash_table_insert (state->named_cell_styles, style, real_name);
 
-       g_hash_table_insert (state->named_cell_styles, style, real_name);
        g_hash_table_insert (state->named_cell_style_regions, gnm_style_region_new (r, style),
-                            g_strdup (real_name));
+                            g_strdup (old_name ? old_name : real_name));
 
        if (gnm_style_is_element_set (style, MSTYLE_CONDITIONS) &&
            NULL != (sc = gnm_style_get_conditions (style))) {


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