[gnumeric] xlsx: handle import of aliased colours tx1 and tx2.



commit 81faa4caedf2afc1235fc49249594298d306f33b
Author: Morten Welinder <terra gnome org>
Date:   Tue Feb 14 19:08:57 2017 -0500

    xlsx: handle import of aliased colours tx1 and tx2.

 NEWS                              |    1 +
 plugins/excel/ChangeLog           |    7 ++++++
 plugins/excel/xlsx-read-drawing.c |    7 +----
 plugins/excel/xlsx-read.c         |   38 +++++++++++++++++++++++++++++++++---
 4 files changed, 44 insertions(+), 9 deletions(-)
---
diff --git a/NEWS b/NEWS
index 1490710..237b24d 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Gnumeric 1.12.34
 Morten:
        * Doc fixes.
        * Fix xlsx import with missing header/footer. [#778292]
+       * Minor xlsx import improvements with alias colors.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.33
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index f69f386..a0a0315 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,10 @@
+2017-02-14  Morten Welinder  <terra gnome org>
+
+       * xlsx-read.c (themed_color_from_name): New function to handle
+       alias colours tx1 and tx2.
+       (themed_color): Use themed_color_from_name.
+       * xlsx-read-drawing.c (xlsx_draw_color_themed): Ditto.
+
 2017-02-07  Morten Welinder  <terra gnome org>
 
        * xlsx-read.c (wrap_sheet_new): New function to ensure we start
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index c6e3a60..611e208 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -461,16 +461,13 @@ xlsx_draw_color_themed (GsfXMLIn *xin, xmlChar const **attrs)
                { NULL, 0 }
        };
 #endif
-
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
        const char *colname = simple_string (xin, attrs);
 
        if (colname) {
-               gpointer val;
-               if (g_hash_table_lookup_extended (state->theme_colors_by_name, colname, NULL, &val)) {
-                       state->color = GPOINTER_TO_UINT (val);
+               if (themed_color_from_name (state, colname, &state->color))
                        color_set_helper (state);
-               } else
+               else
                        xlsx_warning (xin, _("Unknown color '%s'"), colname);
        }
 }
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index afc5f7d..4bbd2e6 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -971,6 +971,37 @@ indexed_color (G_GNUC_UNUSED XLSXReadState *state, gint idx)
                                  xlsx_default_palette_v8[idx].b);
 }
 
+static gboolean
+themed_color_from_name (XLSXReadState *state, const char *name, GOColor *color)
+{
+       gpointer val;
+       gboolean dark = FALSE; // FIXME: from where?
+       static const struct {
+               const char *name;
+               const char *dark;
+               const char *light;
+       } aliases[] = {
+               { "tx1", "dk1", "lt1" },
+               { "tx2", "dk2", "lt2" }
+       };
+       unsigned ui;
+
+       if (g_hash_table_lookup_extended (state->theme_colors_by_name, name, NULL, &val)) {
+               *color = GPOINTER_TO_UINT (val);
+               return TRUE;
+       }
+
+       for (ui = 0; ui < G_N_ELEMENTS (aliases); ui++) {
+               if (strcmp (name, aliases[ui].name) == 0) {
+                       name = dark ? aliases[ui].dark : aliases[ui].light;
+                       return themed_color_from_name (state, name, color);
+               }
+       }
+
+       return FALSE;
+}
+
+
 static GOColor
 themed_color (GsfXMLIn *xin, gint idx)
 {
@@ -992,10 +1023,9 @@ themed_color (GsfXMLIn *xin, gint idx)
         * I'll make the assumption we should work by name rather than
         * index. */
        if (idx >= 0 && idx < (int) G_N_ELEMENTS (theme_elements)) {
-               gpointer color = g_hash_table_lookup (state->theme_colors_by_name,
-                                                     theme_elements [idx]);
-               if (NULL != color)
-                       return GPOINTER_TO_UINT (color);
+               GOColor color;
+               if (themed_color_from_name (state, theme_elements[idx], &color))
+                       return color;
 
                xlsx_warning (xin, _("Unknown theme color %d"), idx);
        } else {


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