[gnumeric] xlsx: fix reading marker color.



commit ba01619f2ea4424241e2d57670223c55e7b00a71
Author: Morten Welinder <terra gnome org>
Date:   Sat Jan 17 10:16:41 2015 -0500

    xlsx: fix reading marker color.

 NEWS                              |    2 +-
 plugins/excel/ChangeLog           |    3 +
 plugins/excel/xlsx-read-drawing.c |   78 +++++++++++++++++++-----------------
 3 files changed, 45 insertions(+), 38 deletions(-)
---
diff --git a/NEWS b/NEWS
index 8c1a604..91ed85a 100644
--- a/NEWS
+++ b/NEWS
@@ -25,7 +25,7 @@ Morten:
        * Fix ADDRESS problem.
        * Fix sheet-filter problem with errors.  [#742601]
        * Improve error handling for .gnumeric a bit.
-       * Improve xlsx graph import: line colour; marker size.
+       * Improve xlsx graph import: line colour; marker size; marker color.
        * Improve xlsx graph export: line style; bar/col direction; marker shape; marker size.
        * Improve xlsx export: default col widths.
 
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index f946cd8..9736c73 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
 2015-01-17  Morten Welinder  <terra gnome org>
 
+       * xlsx-read-drawing.c (xlsx_chart_solid_fill): Fix reading marker
+       colors.
+
        * xlsx-write-drawing.c (xlsx_write_go_style): Write marker size.
 
        * xlsx-read-drawing.c (xlsx_chart_marker_size): Read marker size.
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 42b5fad..7f6e623 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -1320,9 +1320,13 @@ xlsx_chart_solid_fill (GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attrs)
                if (!(state->sp_type & GO_STYLE_LINE)) {
                        state->color_setter = (void (*) (gpointer data, GOColor color)) 
go_marker_set_fill_color;
                        state->color_data = state->marker;
+                       state->gocolor = NULL;
+                       state->auto_color = &state->cur_style->marker.auto_fill_color;
                } else {
                        state->color_setter = (void (*) (gpointer data, GOColor color)) 
go_marker_set_outline_color;
                        state->color_data = state->marker;
+                       state->gocolor = NULL;
+                       state->auto_color = &state->cur_style->marker.auto_outline_color;
                }
        } else if ((NULL != state->cur_style) && (state->gocolor == NULL)) {
                if (state->sp_type & GO_STYLE_LINE) {
@@ -1343,6 +1347,25 @@ xlsx_chart_solid_fill (GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attrs)
 }
 
 static void
+color_set_helper (XLSXReadState *state)
+{
+       if (state->gocolor) {
+               if (*state->gocolor != state->color) {
+                       *state->gocolor = state->color;
+                       if (state->auto_color)
+                               *state->auto_color = FALSE;
+               }
+               state->gocolor = NULL;
+               state->auto_color = NULL;
+       } else if (state->color_setter) {
+               state->color_setter (state->color_data, state->color);
+               state->color_setter = NULL;
+               if (state->auto_color)
+                       *state->auto_color = FALSE;
+       }
+}
+
+static void
 xlsx_draw_color_themed (GsfXMLIn *xin, xmlChar const **attrs)
 {
 #if 0
@@ -1369,68 +1392,49 @@ xlsx_draw_color_themed (GsfXMLIn *xin, xmlChar const **attrs)
 #endif
 
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
-       gpointer val = NULL;
-       for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
+       for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
                if (0 == strcmp (attrs[0], "val")) {
-                       val = g_hash_table_lookup (state->theme_colors_by_name, attrs[1]);
+                       gpointer val =
+                               g_hash_table_lookup (state->theme_colors_by_name, attrs[1]);
                        if (NULL == val)
                                xlsx_warning (xin, _("Unknown color '%s'"), attrs[1]);
+                       else {
+                               state->color = GPOINTER_TO_UINT (val);
+                               color_set_helper (state);
+                       }
                }
-
-       state->color = GPOINTER_TO_UINT (val);
-       if (state->gocolor) {
-               if (*state->gocolor != state->color) {
-                       *state->gocolor = state->color;
-                       if (state->auto_color)
-                               *state->auto_color = FALSE;
-               }
-               state->gocolor = NULL;
-               state->auto_color = NULL;
-       } else if (state->color_setter) {
-               state->color_setter (state->color_data, state->color);
-               state->color_setter = NULL;
        }
 }
 
 static void
 xlsx_draw_color_rgb (GsfXMLIn *xin, xmlChar const **attrs)
 {
-       XLSXReadState   *state = (XLSXReadState *)xin->user_state;
-       for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
+       XLSXReadState *state = (XLSXReadState *)xin->user_state;
+       for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
                if (attr_gocolor (xin, attrs, "val", &state->color))
-                       if (state->auto_color)
-                               *state->auto_color = FALSE;
+                       color_set_helper (state);
+       }
 }
 
 static void
 xlsx_draw_color_alpha (GsfXMLIn *xin, xmlChar const **attrs)
 {
-       XLSXReadState   *state = (XLSXReadState *)xin->user_state;
+       XLSXReadState *state = (XLSXReadState *)xin->user_state;
        int val;
        if (simple_int (xin, attrs, &val)) {
                int level = 255 * val / 100000;
                state->color = GO_COLOR_CHANGE_A (state->color, level);
-               if (state->auto_color)
-                       state->auto_color = FALSE;
+               color_set_helper (state);
        }
 }
 
 static void
 xlsx_draw_color_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 {
-       XLSXReadState   *state = (XLSXReadState *)xin->user_state;
-       if (state->gocolor) {
-               if (*state->gocolor != state->color) {
-                       *state->gocolor = state->color;
-                       if (state->auto_color)
-                               *state->auto_color = FALSE;
-               }
-               state->gocolor = NULL;
-               state->auto_color = NULL;
-       } else if (state->color_setter) {
-               state->color_setter (state->color_data, state->color);
-               state->color_setter = NULL;
-       }
+       XLSXReadState *state = (XLSXReadState *)xin->user_state;
+       state->gocolor = NULL;
+       state->auto_color = NULL;
+       state->color_setter = NULL;
 }
 
 static void
@@ -1505,7 +1509,7 @@ xlsx_chart_marker_size (GsfXMLIn *xin, xmlChar const **attrs)
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
        for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
                int sz;
-               if (attr_int (xin, attrs, "val", &sz))
+               if (simple_int (xin, attrs, &sz))
                        go_marker_set_size (state->marker, sz);
        }
 }


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