[gnumeric] odf: use new goffice support for format colour palette.



commit 5fb606b1eab938c164fef3b12eb2a48d3033833e
Author: Morten Welinder <terra gnome org>
Date:   Sun Mar 30 09:24:57 2014 -0400

    odf: use new goffice support for format colour palette.

 plugins/openoffice/ChangeLog         |    5 ++
 plugins/openoffice/openoffice-read.c |   74 +++-------------------------------
 samples/format-tests.gnumeric        |  Bin 5098 -> 5152 bytes
 3 files changed, 11 insertions(+), 68 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 6864e75..b9b7958 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-30  Morten Welinder  <terra gnome org>
+
+       * openoffice-read.c (odf_number_color): Use new go_format_palette_
+       functions.  This also handles approximate matches.
+
 2014-03-29  Morten Welinder  <terra gnome org>
 
        * openoffice-read.c (oo_rangeref_parse): Handle parse failures (of
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 6b59924..51012bc 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -403,7 +403,6 @@ struct  _OOParseState {
        GHashTable      *controls;
        GHashTable      *validations;
        GHashTable      *strings;
-       GHashTable      *format_colors;
 
        odf_validation_t *cur_validation;
 
@@ -5228,66 +5227,6 @@ odf_number_invisible_text (GsfXMLIn *xin, xmlChar const **attrs)
        }
 }
 
-static GHashTable *
-setup_format_colors (void)
-{
-       GHashTable *h = g_hash_table_new_full
-               (g_direct_hash, g_direct_equal,
-               NULL, (GDestroyNotify)g_strdup);
-       int i;
-       GString *accum = g_string_new (NULL);
-
-       g_hash_table_insert (h,
-                            GUINT_TO_POINTER (GO_COLOR_BLACK),
-                            g_strdup ("[Black]"));
-       g_hash_table_insert (h,
-                            GUINT_TO_POINTER (GO_COLOR_WHITE),
-                            g_strdup ("[White]"));
-       g_hash_table_insert (h,
-                            GUINT_TO_POINTER (GO_COLOR_RED),
-                            g_strdup ("[Red]"));
-       g_hash_table_insert (h,
-                            GUINT_TO_POINTER (GO_COLOR_GREEN),
-                            g_strdup ("[Green]"));
-       g_hash_table_insert (h,
-                            GUINT_TO_POINTER (GO_COLOR_BLUE),
-                            g_strdup ("[Blue]"));
-       g_hash_table_insert (h,
-                            GUINT_TO_POINTER (GO_COLOR_YELLOW),
-                            g_strdup ("[Yellow]"));
-       g_hash_table_insert (h,
-                            GUINT_TO_POINTER (GO_COLOR_VIOLET),
-                            g_strdup ("[Magenta]"));
-       g_hash_table_insert (h,
-                            GUINT_TO_POINTER (GO_COLOR_CYAN),
-                            g_strdup ("[Cyan]"));
-
-       for (i = 9; i <= 56; i++) {
-               char *str = g_strdup_printf ("[Color%d]0", i);
-               GOFormat *fmt = go_format_new_from_XL (str);
-               GOColor color;
-
-               go_format_value_gstring
-                       (NULL, accum,
-                        go_format_measure_zero,
-                        go_font_metrics_unit,
-                        fmt,
-                        0.0, 'F', NULL,
-                        &color, -1, NULL, FALSE);
-               go_format_unref (fmt);
-               g_free (str);
-
-               if (!g_hash_table_lookup (h, GUINT_TO_POINTER (color)))
-                       g_hash_table_insert (h,
-                                            GUINT_TO_POINTER (color),
-                                            g_strdup_printf ("[Color%d]", i));
-       }
-       g_string_free (accum, TRUE);
-
-       return h;
-}
-
-
 static void
 odf_number_color (GsfXMLIn *xin, xmlChar const **attrs)
 {
@@ -5298,11 +5237,12 @@ odf_number_color (GsfXMLIn *xin, xmlChar const **attrs)
                        int r, b, g;
                        if (3 == sscanf (CXML2C (attrs[1]), "#%2x%2x%2x", &r, &g, &b)) {
                                GOColor col = GO_COLOR_FROM_RGB (r, g, b);
-                               char const *color =
-                                       g_hash_table_lookup (state->format_colors,
-                                                            GUINT_TO_POINTER (col));
-                               if (color != NULL)
-                                       g_string_append (state->cur_format.accum, color);
+                               int i = go_format_palette_index_from_color (col, NULL);
+                               char *color = go_format_palette_name_of_index (i);
+                               g_string_append_c (state->cur_format.accum, '[');
+                               g_string_append (state->cur_format.accum, color);
+                               g_string_append_c (state->cur_format.accum, ']');
+                               g_free (color);
                        }
                }
        }
@@ -12730,7 +12670,6 @@ openoffice_file_open (G_GNUC_UNUSED GOFileOpener const *fo, GOIOContext *io_cont
        state.validations = g_hash_table_new_full (g_str_hash, g_str_equal,
                (GDestroyNotify) g_free,
                (GDestroyNotify) odf_validation_free);
-       state.format_colors = setup_format_colors ();
        state.chart.so = NULL;
        state.chart.saved_graph_styles = NULL;
        state.chart.saved_hatches = NULL;
@@ -12935,7 +12874,6 @@ openoffice_file_open (G_GNUC_UNUSED GOFileOpener const *fo, GOIOContext *io_cont
        g_hash_table_destroy (state.controls);
        g_hash_table_destroy (state.validations);
        g_hash_table_destroy (state.strings);
-       g_hash_table_destroy (state.format_colors);
        g_hash_table_destroy (state.chart.arrow_markers);
        if (state.openformula_namemap)
                g_hash_table_destroy (state.openformula_namemap);
diff --git a/samples/format-tests.gnumeric b/samples/format-tests.gnumeric
index 0a859fe..3551d5d 100644
Binary files a/samples/format-tests.gnumeric and b/samples/format-tests.gnumeric differ


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