[gnumeric] xlsx: finish conditional styles writing.



commit ccbb34a24c01ce3d8bb156f49df69bcafe32220b
Author: Morten Welinder <terra gnome org>
Date:   Wed Mar 19 21:43:34 2014 -0400

    xlsx: finish conditional styles writing.

 plugins/excel/ChangeLog    |    3 ++
 plugins/excel/xlsx-write.c |   60 +++++++++++++++++++++++++++-----------------
 test/t6515-cond-format.pl  |    3 +-
 3 files changed, 41 insertions(+), 25 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 04358f4..e4789f5 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
 2014-03-19  Morten Welinder  <terra gnome org>
 
+       * xlsx-write.c (xlsx_find_predefined_fill): Take care not to drop
+       a background colour even if we have a "none" fill.
+
        * xlsx-read.c (xlsx_cond_fmt_rule_end): Reverse the
        alternate-expression uses for certain conditions.
 
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 9892727..4f9d99f 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -239,15 +239,23 @@ xlsx_write_predefined_fills (GsfXMLOut *xml)
 static gint
 xlsx_find_predefined_fill (GnmStyle const *style)
 {
+       gboolean pattern_is_std =
+               (!gnm_style_is_element_set (style, MSTYLE_COLOR_PATTERN) ||
+                gnm_style_get_pattern_color (style)->go_color == GO_COLOR_BLACK);
+       gboolean back_is_std =
+               (!gnm_style_is_element_set (style, MSTYLE_COLOR_BACK) ||
+                gnm_style_get_back_color (style)->go_color == GO_COLOR_WHITE);
+
        if (gnm_style_is_element_set (style, MSTYLE_PATTERN) &&
-           gnm_style_get_pattern (style) == 0 )
+           gnm_style_get_pattern (style) == 0 &&
+           pattern_is_std &&
+           back_is_std)
                return 0;
        if (gnm_style_is_element_set (style, MSTYLE_PATTERN) &&
            gnm_style_get_pattern (style) == 5 &&
-           (!gnm_style_is_element_set (style, MSTYLE_COLOR_PATTERN) ||
-            gnm_style_get_pattern_color (style)->go_color == GO_COLOR_BLACK) &&
-           (!gnm_style_is_element_set (style, MSTYLE_COLOR_BACK) ||
-            gnm_style_get_back_color (style)->go_color == GO_COLOR_WHITE))
+           pattern_is_std &&
+           back_is_std
+           )
                return 1;
 
        return -1;
@@ -623,33 +631,39 @@ static void
 xlsx_write_background (XLSXWriteState *state, GsfXMLOut *xml,
                       GnmStyle const *style, gboolean invert_solid)
 {
-       /* MAGIC :
-        * Looks like pattern background and forground colours are inverted for
-        * dxfs with solid fills for no apparent reason. */
+       /*
+        * MAGIC:
+        * Looks like pattern background and forground colours are inverted
+        * for dxfs with solid fills for no apparent reason.
+        */
+       gboolean invert = FALSE;
 
        gsf_xml_out_start_element (xml, "fill");
        gsf_xml_out_start_element (xml, "patternFill");
        if (gnm_style_is_element_set (style, MSTYLE_PATTERN)) {
                gint pattern = gnm_style_get_pattern (style);
+               const char *type;
                if (pattern <= 0 || pattern > (gint)G_N_ELEMENTS (pats)) {
-                       gsf_xml_out_add_cstr_unchecked (xml, "patternType",
-                                                       "none");
+                       type = "none";
                } else {
-                       gboolean invert = (pattern == 1 && invert_solid);
-                       gsf_xml_out_add_cstr_unchecked (xml, "patternType",
-                                                       pats[pattern - 1]);
-                       if (gnm_style_is_element_set (style, MSTYLE_COLOR_BACK))
-                               xlsx_write_color_element
-                                       (xml,
-                                        invert ? "bgColor" : "fgColor",
-                                        gnm_style_get_back_color (style)->go_color);
-                       if (gnm_style_is_element_set (style, MSTYLE_COLOR_PATTERN))
-                               xlsx_write_color_element
-                                       (xml,
-                                        invert ? "fgColor" : "bgColor",
-                                        gnm_style_get_pattern_color (style)->go_color);
+                       invert = (pattern == 1 && invert_solid);
+                       type = pats[pattern - 1];
                }
+               gsf_xml_out_add_cstr_unchecked (xml, "patternType", type);
        }
+
+       if (gnm_style_is_element_set (style, MSTYLE_COLOR_BACK))
+               xlsx_write_color_element
+                       (xml,
+                        invert ? "bgColor" : "fgColor",
+                        gnm_style_get_back_color (style)->go_color);
+
+       if (gnm_style_is_element_set (style, MSTYLE_COLOR_PATTERN))
+               xlsx_write_color_element
+                       (xml,
+                        invert ? "fgColor" : "bgColor",
+                        gnm_style_get_pattern_color (style)->go_color);
+
        gsf_xml_out_end_element (xml);
        gsf_xml_out_end_element (xml);
 }
diff --git a/test/t6515-cond-format.pl b/test/t6515-cond-format.pl
index 971c2be..f761d3e 100755
--- a/test/t6515-cond-format.pl
+++ b/test/t6515-cond-format.pl
@@ -42,5 +42,4 @@ my $xls_cond_format_filter = "$PERL -p -e 'if (m{<gnm:Condition\\b} ... m{</gnm:
 &test_roundtrip ($file,
                 'format' => 'Gnumeric_Excel:xlsx',
                 'ext' => "xlsx",
-                'resize' => '1048576x16384',
-                'ignore_failure' => 1);
+                'resize' => '1048576x16384');


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