[gnumeric] xls/biff8: fix export of long strings in cell comments.



commit 70d0b0de60e0043a48bdf11fe5fc5baf5c05d888
Author: Morten Welinder <terra gnome org>
Date:   Tue Feb 25 19:43:15 2014 -0500

    xls/biff8: fix export of long strings in cell comments.
    
    and, should they ever occur, in other sheet objects too.

 NEWS                           |    1 +
 plugins/excel/ChangeLog        |    3 ++
 plugins/excel/ms-excel-write.c |   51 +++++++++++++++++++++++++++++++++++++--
 3 files changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index 12d2b5b..d7041fc 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,7 @@ Morten:
        * Make window geometry round-trip through xlsx.
        * Fix xlsx import of comments.
        * Work around gtk+ criticals.  [#725142]
+       * Fix xls/biff8 export of long comments.  [#725168]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.11
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 298d07b..2ba64d7 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
 2014-02-25  Morten Welinder  <terra gnome org>
 
+       * ms-excel-write.c (excel_write_string_in_chunks): BIFF_TXO uses
+       BIFF_CONTINUE records in a non-standard way.
+
        * ms-biff.c (ms_biff_query_dump, ms_biff_put_len_next)
        (ms_biff_put_var_write): Write symbolic opcode name too.
 
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 2cc6c80..2e07ad0 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -4258,6 +4258,53 @@ blipinf_free (BlipInf *blip)
        }
 }
 
+static void
+excel_write_string_in_chunks (BiffPut *bp, const char *label)
+{
+       size_t maxlen_ascii = ms_biff_max_record_len (bp) - 1;
+       size_t maxlen_nonascii = maxlen_ascii / 2;
+
+       do {
+               const char *s = label;
+               size_t thislen = 0;
+               gboolean ascii = TRUE;
+               const char *cut = NULL;
+               char *copy = NULL;
+
+               while (*s) {
+                       thislen++;
+                       if ((guchar)*s < 0x80) {
+                               s++;
+                       } else {
+                               ascii = FALSE;
+                               s = g_utf8_next_char (s);
+                       }
+
+                       if (thislen == maxlen_nonascii)
+                               cut = s;
+
+                       if (thislen >= (ascii ? maxlen_ascii : maxlen_nonascii))
+                               break;
+               }
+
+               if (ascii || !cut)
+                       cut = s;
+
+               if (*cut) {
+                       copy = g_malloc (cut - label + 1);
+                       memcpy (copy, label, cut - label);
+                       copy[cut - label] = 0;
+               }
+
+               ms_biff_put_var_next (bp, BIFF_CONTINUE);
+               excel_write_string (bp, STR_NO_LENGTH, copy ? copy : label);
+               ms_biff_put_commit (bp);
+
+               g_free (copy);
+               label = cut;
+       } while (*label);
+}
+
 static gsize
 excel_write_ClientTextbox (ExcelWriteState *ewb, SheetObject *so,
                           const char *label)
@@ -4299,9 +4346,7 @@ excel_write_ClientTextbox (ExcelWriteState *ewb, SheetObject *so,
        ms_biff_put_var_write (bp, buf, txo_len);
        ms_biff_put_commit (bp);
 
-       ms_biff_put_var_next (bp, BIFF_CONTINUE);
-       excel_write_string(bp, STR_NO_LENGTH, label);
-       ms_biff_put_commit (bp);
+       excel_write_string_in_chunks (bp, label);
 
        ms_biff_put_var_next (bp, BIFF_CONTINUE);
        memset (buf, 0, 8);


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