[gnumeric] Conditional formats: fix xls' handling of bold and number format.



commit 704a1d443f67d0d27a75bc8dbeb2bcc9dcc895e1
Author: Morten Welinder <terra gnome org>
Date:   Mon Mar 17 10:53:42 2014 -0400

    Conditional formats: fix xls' handling of bold and number format.
    
    Excel still does not act on number format, but it reads it correctly.

 plugins/excel/ChangeLog            |    5 +++++
 plugins/excel/ms-excel-read.c      |   25 ++++++++++++++-----------
 plugins/excel/ms-excel-write.c     |   28 +++++++++++++---------------
 samples/cond-format-tests.gnumeric |  Bin 4946 -> 4947 bytes
 test/t6515-cond-format.pl          |    5 ++---
 5 files changed, 34 insertions(+), 29 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 3e090a4..36e9105 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-17  Morten Welinder  <terra gnome org>
+
+       * ms-excel-write.c (cb_write_condition): Fix handling of font
+       weight.
+
 2014-03-16  Andreas J. Guelzow <aguelzow pyrshep ca>
 
        * xlsx-read.c (xlsx_styles_dtd): add stubs
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index f37585c..522919a 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -5247,13 +5247,13 @@ excel_read_CF (BiffQuery *q, ExcelReadSheet *esheet, GnmStyleConditions *sc,
 
        offset =  6  /* CF record header */ + 6; /* format header */
 
-       if (FALSE && (flags & 0x02000000)) { /* number format */
+       if (flags & 0x02000000) { /* number format */
                XL_CHECK_CONDITION (q->length >= offset + 2);
 
                /*
-                * This is documented in MS-XLS, but Excel does not read it.
-                * (Setting both a number format and Bold does not result in
-                * bold, so Excel does not account for the size of this field.)
+                * This is documented in MS-XLS and Excel does read it, i.e.,
+                * it accounts for the size of the field when reading.  Excel
+                * does not appear to act on it, though.
                 */
 
                if (flags2 & 1) {
@@ -5278,7 +5278,7 @@ excel_read_CF (BiffQuery *q, ExcelReadSheet *esheet, GnmStyleConditions *sc,
 
                XL_CHECK_CONDITION (q->length >= offset + 64 + 54);
 
-               if (data[0]) {
+               if (data[0] && GSF_LE_GET_GUINT16 (data + 116) > 0) {
                        char *font = excel_biff_text_1
                                (importer, q, offset);
                        gnm_style_set_font_name (overlay, font);
@@ -5294,17 +5294,20 @@ excel_read_CF (BiffQuery *q, ExcelReadSheet *esheet, GnmStyleConditions *sc,
                                                  excel_palette_get (esheet->container.importer,
                                                                     colour));
 
-               tmp8  = GSF_LE_GET_GUINT8  (data + 4);
+               if (0 == GSF_LE_GET_GUINT8  (data + 36)) {
+                       gnm_style_set_font_bold (overlay,
+                                                GSF_LE_GET_GUINT16 (data + 8) >= 0x2bc);
+               }
+
+               tmp8 = GSF_LE_GET_GUINT8  (data + 4);
                font_flags = GSF_LE_GET_GUINT8  (data + 24);
-               if (0 == (font_flags & 2)) {
+               if (0 == (font_flags & 2))
                        gnm_style_set_font_italic (overlay, 0 != (tmp8 & 2));
-                       gnm_style_set_font_bold   (overlay,
-                                                  GSF_LE_GET_GUINT16 (data + 8) >= 0x2bc);
-               }
+
                if (0 == (font_flags & 0x80))
                        gnm_style_set_font_strike (overlay, 0 != (tmp8 & 0x80));
 
-               if (0 == GSF_LE_GET_GUINT8  (data + 28)) {
+               if (0 == GSF_LE_GET_GUINT8 (data + 28)) {
                        switch (GSF_LE_GET_GUINT8  (data + 10)) {
                        default : g_printerr ("Unknown script %d\n", GSF_LE_GET_GUINT8 (data));
                                /* fall through */
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 947cbf1..ecd8b4c 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -1115,11 +1115,11 @@ cb_write_condition (GnmStyleConditions const *sc, CondDetails *cd,
                ms_biff_put_var_seekto (bp, header_pos+12);
 
                /*
-                * This is documented in MS-XLS, but Excel does not read it.
-                * (Setting both a number format and Bold does not result in
-                * bold, so Excel does not account for the size of this field.)
+                * This is documented in MS-XLS and Excel does read it, i.e.,
+                * it accounts for the size of the field when reading.  Excel
+                * does not appear to act on it, though.
                 */
-               if (FALSE && gnm_style_is_element_set (s, MSTYLE_FORMAT)) {
+               if (gnm_style_is_element_set (s, MSTYLE_FORMAT)) {
                        GOFormat const *fmt = gnm_style_get_format (s);
                        const char *xlfmt = go_format_as_XL (fmt);
                        guint16 bytes;
@@ -1166,6 +1166,7 @@ cb_write_condition (GnmStyleConditions const *sc, CondDetails *cd,
                                written = excel_write_string
                                        (bp, STR_ONE_BYTE_LENGTH, font);
                                g_free (font);
+                               GSF_LE_SET_GUINT16 (fbuf+116, 1);
                        }
 
                        if (gnm_style_is_element_set (s, MSTYLE_FONT_SIZE))
@@ -1174,16 +1175,15 @@ cb_write_condition (GnmStyleConditions const *sc, CondDetails *cd,
                                tmp = 0xFFFFFFFF;
                        GSF_LE_SET_GUINT32 (fbuf+64, tmp);
 
+                       if (gnm_style_is_element_set (s, MSTYLE_FONT_BOLD)) {
+                               guint16 weight = gnm_style_get_font_bold (s) ? 0x2bc : 0x190;
+                               GSF_LE_SET_GUINT16 (fbuf+72, weight);
+                       } else
+                               GSF_LE_SET_GUINT32 (fbuf+100, 1);
+
                        tmp = 0;
-                       if (gnm_style_is_element_set (s, MSTYLE_FONT_BOLD) ||
-                           gnm_style_is_element_set (s, MSTYLE_FONT_ITALIC)) {
-                               if (gnm_style_is_element_set (s, MSTYLE_FONT_BOLD) &&
-                                   gnm_style_get_font_bold (s))
-                                       GSF_LE_SET_GUINT16 (fbuf+72, 0x2bc);
-                               else
-                                       GSF_LE_SET_GUINT16 (fbuf+72, 0x190);
-                               if (gnm_style_is_element_set (s, MSTYLE_FONT_ITALIC) &&
-                                   gnm_style_get_font_italic (s))
+                       if (gnm_style_is_element_set (s, MSTYLE_FONT_ITALIC)) {
+                               if (gnm_style_get_font_italic (s))
                                        tmp |= 2;
                                else
                                        tmp |= 0;
@@ -1209,9 +1209,7 @@ cb_write_condition (GnmStyleConditions const *sc, CondDetails *cd,
                        } else
                                GSF_LE_SET_GUINT32 (fbuf+92, 1); /* flag as unused */
 
-                       GSF_LE_SET_GUINT32 (fbuf+100, 1); /*always 1 */
                        GSF_LE_SET_GUINT32 (fbuf+104, 1); /*always 1 */
-                       GSF_LE_SET_GUINT16 (fbuf+116, 1); /*always 1 */
 
                        if (gnm_style_is_element_set (s, MSTYLE_FONT_COLOR))
                                tmp = map_color_to_palette (&esheet->ewb->base,
diff --git a/samples/cond-format-tests.gnumeric b/samples/cond-format-tests.gnumeric
index 4381fd5..6510b1b 100644
Binary files a/samples/cond-format-tests.gnumeric and b/samples/cond-format-tests.gnumeric differ
diff --git a/test/t6515-cond-format.pl b/test/t6515-cond-format.pl
index 2344f33..65bdaa9 100755
--- a/test/t6515-cond-format.pl
+++ b/test/t6515-cond-format.pl
@@ -23,14 +23,13 @@ my $xls_codepage_filter = "$PERL -p -e '\$_ = \"\" if m{<meta:user-defined meta:
 
 # xls/biff cannot handle format in conditional formats.
 my $xls_cond_format_filter = "$PERL -p -e 'if (m{<gnm:Condition\\b} ... m{</gnm:Condition\\b}) { 
s{\\s+Format=\"[^\"\"]*\"}{}; }'";
-print STDERR "$xls_cond_format_filter\n";
 
 &message ("Check conditional format xls/BIFF7 roundtrip.");
 &test_roundtrip ($file,
                 'format' => 'Gnumeric_Excel:excel_biff7',
                 'ext' => "xls",
                 'resize' => '16384x256',
-                'filter1' => $xls_cond_format_filter,
+                # 'filter1' => $xls_cond_format_filter,
                 'filter2' => $xls_codepage_filter,
                 'ignore_failure' => 1);
 
@@ -38,7 +37,7 @@ print STDERR "$xls_cond_format_filter\n";
 &test_roundtrip ($file,
                 'format' => 'Gnumeric_Excel:excel_biff8',
                 'ext' => "xls",
-                'filter1' => $xls_cond_format_filter,
+                '# filter1' => $xls_cond_format_filter,
                 'filter2' => $xls_codepage_filter,
                 'ignore_failure' => 1);
 


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