[gnumeric] xls: fix export/import of arrow head styles and sizes.



commit 2ef99ef9191835c4f70c6867af94c2873d3e987c
Author: Morten Welinder <terra gnome org>
Date:   Thu Oct 15 14:30:23 2009 -0400

    xls: fix export/import of arrow head styles and sizes.

 plugins/excel/ms-escher.h      |   46 ++++++++++++----------
 plugins/excel/ms-excel-read.c  |    2 +
 plugins/excel/ms-excel-write.c |   81 +++++++++++++++++++++++++++++++++++-----
 3 files changed, 98 insertions(+), 31 deletions(-)
---
diff --git a/plugins/excel/ms-escher.h b/plugins/excel/ms-escher.h
index a516cc2..77c958b 100644
--- a/plugins/excel/ms-escher.h
+++ b/plugins/excel/ms-escher.h
@@ -18,27 +18,31 @@
 #include <sheet-object.h>
 
 enum {
-	MSEP_LOCKROTATION        = 0x0077,
-	MSEP_TXID                = 0x0080,
-	MSEP_WRAPTEXT            = 0x0085,
-	MSEP_TXDIR               = 0x008b,
-	MSEP_SELECTTEXT          = 0x00bb,
-	MSEP_AUTOTEXTMARGIN      = 0x00bc,
-	MSEP_SHAPEPATH           = 0x0144,
-	MSEP_SHADOWOK            = 0x017a,
-	MSEP_LINEOK              = 0x017c,
-	MSEP_FILLOK              = 0x017f,
-	MSEP_FILLCOLOR           = 0x0181,
-	MSEP_FILLED              = 0x01bb,
-	MSEP_NOFILLHITTEST       = 0x01bf,
-	MSEP_LINECOLOR           = 0x01c0,
-	MSEP_LINEWIDTH           = 0x01cb,
-	MSEP_LINESTARTARROWHEAD  = 0x01d0,
-	MSEP_LINEENDARROWHEAD    = 0x01d1,
-	MSEP_ARROWHEADSOK        = 0x01fb,
-	MSEP_LINE                = 0x01fc,
-	MSEP_NAME                = 0x0380,
-	MSEP_ISBUTTON            = 0x03bc
+	MSEP_LOCKROTATION         = 0x0077,
+	MSEP_TXID                 = 0x0080,
+	MSEP_WRAPTEXT             = 0x0085,
+	MSEP_TXDIR                = 0x008b,
+	MSEP_SELECTTEXT           = 0x00bb,
+	MSEP_AUTOTEXTMARGIN       = 0x00bc,
+	MSEP_SHAPEPATH            = 0x0144,
+	MSEP_SHADOWOK             = 0x017a,
+	MSEP_LINEOK               = 0x017c,
+	MSEP_FILLOK               = 0x017f,
+	MSEP_FILLCOLOR            = 0x0181,
+	MSEP_FILLED               = 0x01bb,
+	MSEP_NOFILLHITTEST        = 0x01bf,
+	MSEP_LINECOLOR            = 0x01c0,
+	MSEP_LINEWIDTH            = 0x01cb,
+	MSEP_LINESTARTARROWHEAD   = 0x01d0,
+	MSEP_LINEENDARROWHEAD     = 0x01d1,
+	MSEP_LINESTARTARROWWIDTH  = 0x01d2,
+	MSEP_LINESTARTARROWLENGTH = 0x01d3,
+	MSEP_LINEENDARROWWIDTH    = 0x01d4,
+	MSEP_LINEENDARROWLENGTH   = 0x01d5,
+	MSEP_ARROWHEADSOK         = 0x01fb,
+	MSEP_LINE                 = 0x01fc,
+	MSEP_NAME                 = 0x0380,
+	MSEP_ISBUTTON             = 0x03bc
 };
 
 
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index 806234c..4a559f7 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -449,6 +449,8 @@ handle_arrow_head (SheetObject *so, const char *prop_name,
 	int w = ms_obj_attr_get_int (attrs, wid, 1);
 	int l = ms_obj_attr_get_int (attrs, lid, 1);
 
+	/* NOTE: This mess should match code in ms-excel-write.c  */
+
 	int typ = ms_obj_attr_get_int (attrs, typid, 0);
 	switch (typ) {
 	case 0:
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 6624f3d..43f355b 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -4542,6 +4542,68 @@ excel_write_widget_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 						 pspec != NULL, TRUE);
 }
 
+static void
+write_arrow (GOArrow const *arrow, GString *escher, gsize optmark,
+	     MSObjAttrID id)
+{
+	int typ = 0;
+	int l = 0, w = 0;
+
+	/* NOTE: This mess should match code in ms-excel-read.c  */
+
+	switch (arrow->typ) {
+	case GO_ARROW_NONE:
+		typ = 0;
+		break;
+	case GO_ARROW_TRIANGLE:
+		if (fabs (arrow->a - arrow->b) < 0.01) {
+			typ = 1;
+			l = (int)CLAMP ((arrow->a / 3.5) - 1, 0.0, 2.0);
+			w = (int)CLAMP ((arrow->c / 2.5) - 1, 0.0, 2.0);
+		} else if (arrow->a > arrow->b) {
+			typ = 3;
+			l = (int)CLAMP ((arrow->a / 5.0) - 1, 0.0, 2.0);
+			w = (int)CLAMP ((arrow->c / 2.5) - 1, 0.0, 2.0);
+		} else if (arrow->a < 0.5 * arrow->b) {
+			typ = 5;
+			l = (int)CLAMP ((arrow->a / 1.0) - 1, 0.0, 2.0);
+			w = (int)CLAMP ((arrow->c / 1.5) - 1, 0.0, 2.0);
+		} else {
+			typ = 2;
+			l = (int)CLAMP ((arrow->b / 4.0) - 1, 0.0, 2.0);
+			w = (int)CLAMP ((arrow->c / 2.0) - 1, 0.0, 2.0);
+		}
+		break;
+	case GO_ARROW_OVAL:
+		typ = 4;
+		l = (int)CLAMP ((arrow->a / 2.5) - 1, 0.0, 2.0);
+		w = (int)CLAMP ((arrow->b / 2.5) - 1, 0.0, 2.0);
+		break;
+	default:
+		g_assert_not_reached ();
+	}
+
+	switch (id) {
+	case MSEP_LINESTARTARROWHEAD:
+	case MSEP_LINEENDARROWHEAD:
+		ms_escher_opt_add_simple (escher, optmark, id, typ);
+		break;
+	case MSEP_LINESTARTARROWWIDTH:
+	case MSEP_LINEENDARROWWIDTH:
+		if (typ && w != 1)
+			ms_escher_opt_add_simple (escher, optmark, id, w);
+		break;
+	case MSEP_LINESTARTARROWLENGTH:
+	case MSEP_LINEENDARROWLENGTH:
+		if (typ && l != 1)
+			ms_escher_opt_add_simple (escher, optmark, id, l);
+		break;
+	default:
+		g_assert_not_reached ();
+	}
+}
+
+
 static gsize
 excel_write_line_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 {
@@ -4593,17 +4655,16 @@ excel_write_line_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 		gint32 w = CLAMP (12700 * style->line.width, 0, G_MAXINT32);
 		ms_escher_opt_add_simple (escher, optmark, MSEP_LINEWIDTH, w);
 	}
-	if (start_arrow->typ) {
-		ms_escher_opt_add_simple (escher, optmark,
-					  MSEP_LINESTARTARROWHEAD,
-					  start_arrow->typ);
-	}
-	if (end_arrow->typ) {
-		ms_escher_opt_add_simple (escher, optmark,
-					  MSEP_LINEENDARROWHEAD,
-					  end_arrow->typ);
-	}
+
+	/* The two arrows' attributes are interleaved.  */
+	write_arrow (start_arrow, escher, optmark, MSEP_LINESTARTARROWHEAD);
+	write_arrow (end_arrow, escher, optmark, MSEP_LINEENDARROWHEAD);
+	write_arrow (start_arrow, escher, optmark, MSEP_LINESTARTARROWWIDTH);
+	write_arrow (start_arrow, escher, optmark, MSEP_LINESTARTARROWLENGTH);
+	write_arrow (end_arrow, escher, optmark, MSEP_LINEENDARROWWIDTH);
+	write_arrow (end_arrow, escher, optmark, MSEP_LINEENDARROWLENGTH);
 	ms_escher_opt_add_bool (escher, optmark, MSEP_ARROWHEADSOK, TRUE);
+
 	if (name)
 		ms_escher_opt_add_str_wchar (escher, optmark, extra,
 					     MSEP_NAME, name);



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