[gnumeric] Lotus: read more formatting.



commit 52edf1cf0ffeddf7ea354b3f7fb9d30d4450dde0
Author: Morten Welinder <terra gnome org>
Date:   Wed Dec 31 21:27:28 2014 -0500

    Lotus: read more formatting.

 plugins/lotus-123/ChangeLog       |    1 +
 plugins/lotus-123/lotus-formula.c |   21 +++---------
 plugins/lotus-123/lotus-types.h   |    1 +
 plugins/lotus-123/lotus.c         |   68 ++++++++++++++++++++++++++++++++++--
 4 files changed, 71 insertions(+), 20 deletions(-)
---
diff --git a/plugins/lotus-123/ChangeLog b/plugins/lotus-123/ChangeLog
index 8b087d8..33aa712 100644
--- a/plugins/lotus-123/ChangeLog
+++ b/plugins/lotus-123/ChangeLog
@@ -2,6 +2,7 @@
 
        * lotus.c (lotus_treal): Base this on lotus_extfloat thus giving
        it a chance of working.
+       (lotus_read_new): Read more formatting.
 
 2014-11-06  Morten Welinder  <terra gnome org>
 
diff --git a/plugins/lotus-123/lotus-formula.c b/plugins/lotus-123/lotus-formula.c
index ec80bbb..ad5ee32 100644
--- a/plugins/lotus-123/lotus-formula.c
+++ b/plugins/lotus-123/lotus-formula.c
@@ -525,8 +525,7 @@ make_function (LotusState *state, GnmExprList **stack, guint8 const *data, const
 static gint16
 sign_extend (guint16 num)
 {
-       gint16 i = (num << 3);
-       return (i / 8);
+       return (gint16)(num << 3) / 8;
 }
 
 /* FIXME: dodgy stuff, hacked for now */
@@ -538,22 +537,12 @@ get_cellref (GnmCellRef *ref, guint8 const *dataa, guint8 const *datab,
 
        ref->sheet = NULL;
        i = GSF_LE_GET_GUINT16 (dataa);
-       if (i & 0x8000) {
-               ref->col_relative = TRUE;
-               ref->col = sign_extend (i & 0x3fff);
-       } else {
-               ref->col_relative = FALSE;
-               ref->col = i & 0x3fff;
-       }
+       ref->col = sign_extend (i & 0x1fff);
+       ref->col_relative = (i & 0x8000) != 0;
 
        i = GSF_LE_GET_GUINT16 (datab);
-       if (i & 0x8000) {
-               ref->row_relative = TRUE;
-               ref->row = sign_extend (i & 0x3fff);
-       } else {
-               ref->row_relative = FALSE;
-               ref->row = i & 0x3fff;
-       }
+       ref->row = sign_extend (i & 0x1fff);
+       ref->row_relative = (i & 0x8000) != 0;
 
 #if FORMULA_DEBUG > 0
        g_printerr ("0x%x 0x%x -> (%d, %d)\n",
diff --git a/plugins/lotus-123/lotus-types.h b/plugins/lotus-123/lotus-types.h
index a5af4ae..c719d3e 100644
--- a/plugins/lotus-123/lotus-types.h
+++ b/plugins/lotus-123/lotus-types.h
@@ -44,6 +44,7 @@
 #define LOTUS_SYSTEMRANGE            0xa
 #define LOTUS_ZEROFORCE              0xb
 #define LOTUS_SORTKEY_DIR            0xc
+#define LOTUS_FORMAT                 0x13
 #define LOTUS_ERRCELL                0x14
 #define LOTUS_NACELL                 0x15
 #define LOTUS_LABEL2                 0x16
diff --git a/plugins/lotus-123/lotus.c b/plugins/lotus-123/lotus.c
index 6cb6b77..81b80aa 100644
--- a/plugins/lotus-123/lotus.c
+++ b/plugins/lotus-123/lotus.c
@@ -19,10 +19,12 @@
 #include <expr.h>
 #include <value.h>
 #include <gutils.h>
+#include <ranges.h>
 #include <mstyle.h>
 #include <style-color.h>
 #include <style-font.h>
 #include <parse-util.h>
+#include <sheet-style.h>
 #include <sheet-object-cell-comment.h>
 
 #include <gsf/gsf-input.h>
@@ -30,7 +32,7 @@
 #include <gsf/gsf-msole-utils.h>
 #include <string.h>
 
-#define LOTUS_DEBUG 1
+#define LOTUS_DEBUG 0
 #undef DEBUG_RLDB
 #undef DEBUG_STYLE
 #undef DEBUG_FORMAT
@@ -740,17 +742,29 @@ lotus_format_string (guint fmt)
 }
 
 static void
-cell_set_format_from_lotus_format (GnmCell *cell, guint fmt)
+cellpos_set_format_from_lotus_format (Sheet *sheet, int col, int row, guint fmt)
 {
        char *fmt_string = lotus_format_string (fmt);
-       if (fmt_string[0])
-               gnm_cell_set_format (cell, fmt_string);
+       if (fmt_string[0]) {
+               GnmStyle *mstyle = gnm_style_new ();
+               gnm_style_set_format_text (mstyle, fmt_string);
+               sheet_style_apply_pos (sheet, col, row, mstyle);
+       }
 #ifdef DEBUG_FORMAT
        g_printerr ("Format: %s\n", fmt_string);
 #endif
        g_free (fmt_string);
 }
 
+static void
+cell_set_format_from_lotus_format (GnmCell *cell, guint frmt)
+{
+       cellpos_set_format_from_lotus_format (cell->base.sheet,
+                                             cell->pos.col,
+                                             cell->pos.row,
+                                             frmt);
+}
+
 /* ------------------------------------------------------------------------- */
 
 static double
@@ -1926,6 +1940,52 @@ lotus_read_new (LotusState *state, record_t *r)
                case LOTUS_EOF:
                        goto done;
 
+               case LOTUS_FORMAT: CHECK_RECORD_SIZE (>= 2) {
+                       Sheet *sheet = lotus_get_sheet (state->wb, r->data[0]);
+                       guint8 subtype = GSF_LE_GET_GUINT8 (r->data + 1);
+                       switch (subtype) {
+                       case 0: CHECK_RECORD_SIZE (>= 4) { // FORMAT
+                               int row = GSF_LE_GET_GUINT16 (r->data + 2);
+                               int i, n = (r->len - 4) / 4;
+                               for (i = 0; i < n; i++) {
+                                       guint32 frmt = GSF_LE_GET_GUINT32 (r->data + 4 + 4 * i);
+                                       cellpos_set_format_from_lotus_format (sheet, i, row, frmt);
+                               }
+                               break;
+                       }
+                       case 2: CHECK_RECORD_SIZE (>= 8) { // DUPFMT
+                               int row = GSF_LE_GET_GUINT16 (r->data + 2);
+                               Sheet *src_sheet = lotus_get_sheet (state->wb, GSF_LE_GET_GUINT16 (r->data + 
4));
+                               int src_row = GSF_LE_GET_GUINT16 (r->data + 6);
+                               GnmRange r;
+                               GnmStyleList *styles;
+                               GnmCellPos cp;
+
+                               range_init_rows (&r, src_sheet, src_row, src_row);
+                               styles = sheet_style_get_range (src_sheet, &r);
+
+                               cp.col = 0;
+                               cp.row = row;
+                               sheet_style_set_list  (sheet, &cp, styles, NULL, NULL);
+                               style_list_free (styles);
+
+#if 0
+                               g_printerr ("%s's row %d copies style from %s's row %d\n",
+                                           sheet->name_unquoted, row + 1,
+                                           src_sheet->name_unquoted, src_row + 1);
+#endif
+
+                               break;
+                       }
+
+                       case 1: // GBLFMT
+                       default:
+                               g_printerr ("Unknown format record 0x%x/%02x of length %d.\n",
+                                        r->type, subtype, r->len);
+                       }
+                       break;
+               }
+
                case LOTUS_ERRCELL: CHECK_RECORD_SIZE (>= 4) {
                        int row = GSF_LE_GET_GUINT16 (r->data);
                        Sheet *sheet = lotus_get_sheet (state->wb, r->data[2]);


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