[gnumeric] xlsx: fix round trip of sheet tab colour.



commit e7904a4e0b691fc4a0e20479627cd5c2724f32dd
Author: Morten Welinder <terra gnome org>
Date:   Mon Apr 13 15:53:17 2015 -0400

    xlsx: fix round trip of sheet tab colour.

 NEWS                       |    1 +
 plugins/excel/ChangeLog    |    3 +++
 plugins/excel/xlsx-read.c  |   31 +++++++++++++++++--------------
 plugins/excel/xlsx-write.c |   20 ++++++++++++++++++++
 4 files changed, 41 insertions(+), 14 deletions(-)
---
diff --git a/NEWS b/NEWS
index 5608a04..40df9c8 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ Morten:
        * Fix xlsx import of multiple axes.
        * Fix xlsx title export problem.
        * Fix xlsx export problem with series' style.
+       * Fix xlsx import/export of sheet tab text colour.
        * Improve test suite.
        * Actually implement DECIMAL.
        * Fix BETA problem with special case.
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 9049e52..4252ce4 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
 2015-04-13  Morten Welinder  <terra gnome org>
 
+       * xlsx-read.c (xlsx_ext_tabtextcolor): New function for round trip
+       of tab text color.
+
        * xlsx-write-drawing.c (xlsx_write_one_plot): Move c:holeSize to
        where the schema says it should be.
 
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index d0005f6..7b857bf 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -1650,29 +1650,31 @@ xlsx_CT_SheetPr (G_GNUC_UNUSED GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attr
 }
 
 static void
-xlsx_sheet_tabcolor (GsfXMLIn *xin, xmlChar const **attrs)
+xlsx_sheet_tab_fgbg (GsfXMLIn *xin, xmlChar const **attrs, gboolean fg)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
-       GnmColor *text_color, *color = elem_color (xin, attrs, TRUE);
-       if (NULL != color) {
-               int contrast =
-                       GO_COLOR_UINT_R (color->go_color) +
-                       GO_COLOR_UINT_G (color->go_color) +
-                       GO_COLOR_UINT_B (color->go_color);
-               if (contrast >= 0x180)
-                       text_color = style_color_black ();
-               else
-                       text_color = style_color_white ();
+       GnmColor *color = elem_color (xin, attrs, TRUE);
+       if (color) {
                g_object_set (state->sheet,
-                             "tab-foreground", text_color,
-                             "tab-background", color,
+                             (fg ? "tab-foreground" : "tab-background"), color,
                              NULL);
-               style_color_unref (text_color);
                style_color_unref (color);
        }
 }
 
 static void
+xlsx_sheet_tabcolor (GsfXMLIn *xin, xmlChar const **attrs)
+{
+       xlsx_sheet_tab_fgbg (xin, attrs, FALSE);
+}
+
+static void
+xlsx_ext_tabtextcolor (GsfXMLIn *xin, xmlChar const **attrs)
+{
+       xlsx_sheet_tab_fgbg (xin, attrs, TRUE);
+}
+
+static void
 xlsx_sheet_page_setup (G_GNUC_UNUSED GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attrs)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
@@ -3325,6 +3327,7 @@ GSF_XML_IN_NODE_FULL (START, START, -1, NULL, GSF_XML_NO_CONTENT, FALSE, TRUE, N
 GSF_XML_IN_NODE_FULL (START, SHEET, XL_NS_SS, "worksheet", GSF_XML_NO_CONTENT, FALSE, TRUE, NULL, 
&xlsx_CT_worksheet, 0),
   GSF_XML_IN_NODE (SHEET, EXTLST, XL_NS_SS, "extLst", GSF_XML_NO_CONTENT, NULL, NULL),
     GSF_XML_IN_NODE (EXTLST, EXTITEM, XL_NS_SS, "ext", GSF_XML_NO_CONTENT, &xlsx_ext_begin, &xlsx_ext_end),
+      GSF_XML_IN_NODE (EXTITEM, EXT_TABTEXTCOLOR, XL_NS_GNM_EXT, "tabTextColor", GSF_XML_NO_CONTENT, 
&xlsx_ext_tabtextcolor, NULL),
   GSF_XML_IN_NODE (SHEET, PROPS, XL_NS_SS, "sheetPr", GSF_XML_NO_CONTENT, &xlsx_CT_SheetPr, NULL),
     GSF_XML_IN_NODE (PROPS, OUTLINE_PROPS, XL_NS_SS, "outlinePr", GSF_XML_NO_CONTENT, NULL, NULL),
     GSF_XML_IN_NODE (PROPS, TAB_COLOR, XL_NS_SS, "tabColor", GSF_XML_NO_CONTENT, &xlsx_sheet_tabcolor, NULL),
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index bf88e34..f623b0a 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -2746,6 +2746,7 @@ xlsx_write_sheet (XLSXWriteState *state, GsfOutfile *wb_part, Sheet *sheet)
        GnmPrintInformation *pi = NULL;
        GHashTable *zorder;
        int z;
+       gboolean ext_tab_textcolor = FALSE;
 
        state->sheet = sheet;
        col_styles = sheet_style_most_common (state->sheet, TRUE);
@@ -2821,6 +2822,8 @@ xlsx_write_sheet (XLSXWriteState *state, GsfOutfile *wb_part, Sheet *sheet)
        gsf_xml_out_start_element (xml, "worksheet");
        gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_ss);
        gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel);
+       if (state->with_extension)
+               gsf_xml_out_add_cstr_unchecked (xml, "xmlns:gnmx", ns_gnm_ext);
 
        /*   element sheetPr { CT_SheetPr }?,     */
        gsf_xml_out_start_element (xml, "sheetPr");
@@ -2837,6 +2840,9 @@ xlsx_write_sheet (XLSXWriteState *state, GsfOutfile *wb_part, Sheet *sheet)
                xlsx_add_rgb (xml, "rgb", state->sheet->tab_color->go_color);
                gsf_xml_out_end_element (xml); /* </tabColor> */
        }
+       if (NULL != state->sheet->tab_text_color)
+               ext_tab_textcolor = TRUE;
+
        gsf_xml_out_end_element (xml); /* </sheetPr> */
 
 /*   element dimension { CT_SheetDimension }?,     */
@@ -2910,6 +2916,20 @@ xlsx_write_sheet (XLSXWriteState *state, GsfOutfile *wb_part, Sheet *sheet)
 /*   element controls { CT_Controls }?,     */
 /*   element webPublishItems { CT_WebPublishItems }?,     */
 /*   element tableParts { CT_TableParts }?,     */
+
+       if (state->with_extension && ext_tab_textcolor) {
+               gsf_xml_out_start_element (xml, "extLst");
+               gsf_xml_out_start_element (xml, "ext");
+               gsf_xml_out_add_cstr_unchecked (xml, "uri", ns_gnm_ext);
+
+               gsf_xml_out_start_element (xml, "gnmx:tabTextColor");
+               xlsx_add_rgb (xml, "rgb", state->sheet->tab_text_color->go_color);
+               gsf_xml_out_end_element (xml); /* </gnmx:tabTextColor> */
+
+               gsf_xml_out_end_element (xml);  /* "ext" */
+               gsf_xml_out_end_element (xml);  /* "extLst" */
+       }
+
 /*   element extLst { CT_ExtensionList }?     */
        gsf_xml_out_end_element (xml); /* </worksheet> */
 


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