[gnumeric] xls: fix import of headers of footers.



commit 13356459342a6011d4b22564c147ece2462e27c3
Author: Morten Welinder <terra gnome org>
Date:   Sun Feb 23 22:21:11 2014 -0500

    xls: fix import of headers of footers.

 NEWS                          |    1 +
 plugins/excel/ChangeLog       |    6 ++-
 plugins/excel/ms-excel-read.c |   39 +----------------
 plugins/excel/ms-excel-util.c |   72 ++++++++++++++++++++++++++++++++
 plugins/excel/ms-excel-util.h |    1 +
 plugins/excel/xlsx-read.c     |   90 +++++------------------------------------
 6 files changed, 92 insertions(+), 117 deletions(-)
---
diff --git a/NEWS b/NEWS
index c4ba718..42bc15a 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ Morten:
        * Fix BIFF7 export of comments.
        * Improve style handling when expanding sheets. 
        * Fix xls export of headers and footers.  [Part of #724516]
+       * Fix xls import of headers and footers.  [Part of #724516]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.11
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 3df029d..f5dd2a7 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -2,7 +2,11 @@
 
        * ms-excel-util.c (xls_header_footer_export): New function
        extracted from...
-       * xlsx-write.c (xlsx_write_print_info_hf): ...here
+       * xlsx-write.c (xlsx_write_print_info_hf): ...here.
+
+       * ms-excel-util.c (xls_header_footer_import): New function
+       extracted from...
+       * xlsx-read.c (xlsx_CT_header_footer): ...here.
 
        * ms-excel-write.c (excel_write_HEADER_FOOTER): Properly translate
        magic codes.
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index f3b4bd1..e8a1c27 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -6280,29 +6280,6 @@ excel_read_BOOLERR (BiffQuery *q, ExcelReadSheet *esheet)
        excel_sheet_insert_val (esheet, q, v);
 }
 
-/* hands the peculiar ampersand escaping, and returns the string _after_
- * &<target> to the end of the buffer.  It also stores \0 in place
- * of &<target>.  If not found return NULL and do nothing */
-static char *
-xl_hf_strstr (char *buf, char target)
-{
-       if (buf == NULL)
-               return NULL;
-
-       for (; *buf ; buf++)
-               if (*buf == '&') {
-                       if (0 == buf[1])
-                               return NULL;
-                       if (target == buf[1]) {
-                               buf[0] = buf[1] = '\0';
-                               return buf + 2;
-                       }
-                       if ('&' == buf[1])
-                               buf++;
-               }
-       return NULL;
-}
-
 static void
 excel_read_HEADER_FOOTER (GnmXLImporter const *importer,
                          BiffQuery *q, ExcelReadSheet *esheet,
@@ -6311,7 +6288,7 @@ excel_read_HEADER_FOOTER (GnmXLImporter const *importer,
        PrintInformation *pi = esheet->sheet->print_info;
 
        if (q->length) {
-               char *l, *c, *r, *str;
+               char *str;
 
                if (importer->ver >= MS_BIFF_V8)
                        str = excel_biff_text_2 (importer, q, 0);
@@ -6320,18 +6297,8 @@ excel_read_HEADER_FOOTER (GnmXLImporter const *importer,
 
                d (2, g_printerr ("%s == '%s'\n", is_header ? "header" : "footer", str););
 
-               r = xl_hf_strstr (str, 'R'); /* order is important */
-               c = xl_hf_strstr (str, 'C');
-               l = xl_hf_strstr (str, 'L');
-               if (is_header) {
-                       if (pi->header != NULL)
-                               print_hf_free (pi->header);
-                       pi->header = print_hf_new (l, c, r);
-               } else {
-                       if (pi->footer != NULL)
-                               print_hf_free (pi->footer);
-                       pi->footer = print_hf_new (l, c, r);
-               }
+               xls_header_footer_import (is_header ? pi->header : pi->footer,
+                                         str);
 
                g_free (str);
        }
diff --git a/plugins/excel/ms-excel-util.c b/plugins/excel/ms-excel-util.c
index a0681e0..79d6e50 100644
--- a/plugins/excel/ms-excel-util.c
+++ b/plugins/excel/ms-excel-util.c
@@ -745,3 +745,75 @@ xls_header_footer_export (const PrintHF *hf)
 
        return g_string_free (res, FALSE);
 }
+
+void
+xls_header_footer_import (PrintHF *hf, const char *txt)
+{
+       char section = 'L';
+       GString *accum = g_string_new (NULL);
+
+       g_free (hf->left_format); hf->left_format = g_strdup ("");
+       g_free (hf->middle_format); hf->middle_format = g_strdup ("");
+       g_free (hf->right_format); hf->right_format = g_strdup ("");
+
+       while (1) {
+               if (txt[0] == 0 ||
+                   (txt[0] == '&' && strchr ("LCR", txt[1]))) {
+                       char **sp;
+                       switch (section) {
+                       case 'L': sp = &hf->left_format; break;
+                       case 'C': sp = &hf->middle_format; break;
+                       case 'R': sp = &hf->right_format; break;
+                       default: g_assert_not_reached ();
+                       }
+                       g_free (*sp);
+                       *sp = g_string_free (accum, FALSE);
+
+                       if (txt[0] == 0)
+                               break;
+
+                       accum = g_string_new (NULL);
+                       section = txt[1];
+                       txt += 2;
+                       continue;
+               }
+
+               if (txt[0] != '&') {
+                       g_string_append_c (accum, *txt++);
+                       continue;
+               }
+
+               txt++;
+               switch (txt[0]) {
+               case 0:
+                       continue;
+               case '&':
+                       g_string_append_c (accum, *txt);
+                       break;
+               case 'A':
+                       g_string_append (accum, "&[TAB]");
+                       break;
+               case 'P':
+                       g_string_append (accum, "&[PAGE]");
+                       break;
+               case 'N':
+                       g_string_append (accum, "&[PAGES]");
+                       break;
+               case 'D':
+                       g_string_append (accum, "&[DATE]");
+                       break;
+               case 'T':
+                       g_string_append (accum, "&[TIME]");
+                       break;
+               case 'F':
+                       g_string_append (accum, "&[FILE]");
+                       break;
+               case 'Z':
+                       g_string_append (accum, "&[PATH]");
+                       break;
+               default:
+                       break;
+               }
+               txt++;
+       }
+}
diff --git a/plugins/excel/ms-excel-util.h b/plugins/excel/ms-excel-util.h
index 78adb01..78d49db 100644
--- a/plugins/excel/ms-excel-util.h
+++ b/plugins/excel/ms-excel-util.h
@@ -103,6 +103,7 @@ unsigned xls_paper_size (GtkPaperSize *ps, gboolean rotated);
 /*****************************************************************************/
 
 char *xls_header_footer_export (const PrintHF *hf);
+void xls_header_footer_import (PrintHF *hf, const char *txt);
 
 /*****************************************************************************/
 
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 138eb08..29932c5 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -21,6 +21,7 @@
  */
 #include <gnumeric-config.h>
 #include "xlsx-utils.h"
+#include "ms-excel-write.h"
 
 #include "sheet-view.h"
 #include "sheet-style.h"
@@ -772,7 +773,7 @@ simple_enum (GsfXMLIn *xin, xmlChar const **attrs, EnumVal const *enums, int *re
  */
 static struct {
        guint8 r, g, b;
-} excel_default_palette_v8 [] = {
+} xlsx_default_palette_v8 [] = {
        {  0,  0,  0}, {255,255,255}, {255,  0,  0}, {  0,255,  0},
        {  0,  0,255}, {255,255,  0}, {255,  0,255}, {  0,255,255},
 
@@ -840,17 +841,18 @@ indexed_color (G_GNUC_UNUSED XLSXReadState *state, gint idx)
        }
 
        idx -= 8;
-       if (idx < 0 || (int) G_N_ELEMENTS (excel_default_palette_v8) <= idx) {
+       if (idx < 0 || (int) G_N_ELEMENTS (xlsx_default_palette_v8) <= idx) {
                g_warning ("EXCEL: color index (%d) is out of range (8..%d). Defaulting to black",
-                          idx + 8, (int)G_N_ELEMENTS (excel_default_palette_v8) + 8);
+                          idx + 8, (int)G_N_ELEMENTS (xlsx_default_palette_v8) + 8);
                return GO_COLOR_BLACK;
        }
 
        /* TODO cache and ref */
-       return GO_COLOR_FROM_RGB (excel_default_palette_v8[idx].r,
-                            excel_default_palette_v8[idx].g,
-                            excel_default_palette_v8[idx].b);
+       return GO_COLOR_FROM_RGB (xlsx_default_palette_v8[idx].r,
+                                 xlsx_default_palette_v8[idx].g,
+                                 xlsx_default_palette_v8[idx].b);
 }
+
 static GOColor
 themed_color (GsfXMLIn *xin, gint idx)
 {
@@ -1940,83 +1942,11 @@ xlsx_CT_PageMargins (GsfXMLIn *xin, xmlChar const **attrs)
 
 
 static void
-xlsx_CT_header_footer (XLSXReadState *state, PrintHF *hf, const char *txt)
-{
-       char section = 'L';
-       GString *accum = g_string_new (NULL);
-
-       g_free (hf->left_format); hf->left_format = g_strdup ("");
-       g_free (hf->middle_format); hf->middle_format = g_strdup ("");
-       g_free (hf->right_format); hf->right_format = g_strdup ("");
-
-       while (1) {
-               if (txt[0] == 0 ||
-                   (txt[0] == '&' && strchr ("LCR", txt[1]))) {
-                       char **sp;
-                       switch (section) {
-                       case 'L': sp = &hf->left_format; break;
-                       case 'C': sp = &hf->middle_format; break;
-                       case 'R': sp = &hf->right_format; break;
-                       default: g_assert_not_reached ();
-                       }
-                       g_free (*sp);
-                       *sp = g_string_free (accum, FALSE);
-
-                       if (txt[0] == 0)
-                               break;
-
-                       accum = g_string_new (NULL);
-                       section = txt[1];
-                       txt += 2;
-                       continue;
-               }
-
-               if (txt[0] != '&') {
-                       g_string_append_c (accum, *txt++);
-                       continue;
-               }
-
-               txt++;
-               switch (txt[0]) {
-               case 0:
-                       continue;
-               case '&':
-                       g_string_append_c (accum, *txt);
-                       break;
-               case 'A':
-                       g_string_append (accum, "&[TAB]");
-                       break;
-               case 'P':
-                       g_string_append (accum, "&[PAGE]");
-                       break;
-               case 'N':
-                       g_string_append (accum, "&[PAGES]");
-                       break;
-               case 'D':
-                       g_string_append (accum, "&[DATE]");
-                       break;
-               case 'T':
-                       g_string_append (accum, "&[TIME]");
-                       break;
-               case 'F':
-                       g_string_append (accum, "&[FILE]");
-                       break;
-               case 'Z':
-                       g_string_append (accum, "&[PATH]");
-                       break;
-               default:
-                       break;
-               }
-               txt++;
-       }
-}
-
-static void
 xlsx_CT_oddheader_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
        PrintInformation *pi = state->sheet->print_info;
-       xlsx_CT_header_footer (state, pi->header, xin->content->str);
+       xls_header_footer_import (pi->header, xin->content->str);
 }
 
 static void
@@ -2024,7 +1954,7 @@ xlsx_CT_oddfooter_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
        PrintInformation *pi = state->sheet->print_info;
-       xlsx_CT_header_footer (state, pi->footer, xin->content->str);
+       xls_header_footer_import (pi->footer, xin->content->str);
 }
 
 static void


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