[gnumeric] xls: extract arrow translation code into its own function.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xls: extract arrow translation code into its own function.
- Date: Thu, 12 Feb 2015 21:27:32 +0000 (UTC)
commit 6cc05ffb568c0af17b16dc1d51bd810d22be3eca
Author: Morten Welinder <terra gnome org>
Date: Thu Feb 12 16:26:44 2015 -0500
xls: extract arrow translation code into its own function.
plugins/excel/ChangeLog | 3 +++
plugins/excel/ms-excel-util.c | 40 ++++++++++++++++++++++++++++++++++++++++
plugins/excel/ms-excel-util.h | 12 ++++++++++++
plugins/excel/ms-excel-write.c | 38 +++-----------------------------------
4 files changed, 58 insertions(+), 35 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 13c611c..b4166d6 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
2015-02-12 Morten Welinder <terra gnome org>
+ * ms-excel-util.c (xls_arrow_to_xl): New function extraced from...
+ * ms-excel-write.c (write_arrow): ...here
+
* xlsx-write.c (xlsx_write_col): Always write column width.
Otherwise Excel might see zero.
diff --git a/plugins/excel/ms-excel-util.c b/plugins/excel/ms-excel-util.c
index 4bb9160..15d396a 100644
--- a/plugins/excel/ms-excel-util.c
+++ b/plugins/excel/ms-excel-util.c
@@ -821,3 +821,43 @@ xls_header_footer_import (PrintHF *hf, const char *txt)
txt++;
}
}
+
+/*****************************************************************************/
+
+void
+xls_arrow_to_xl (GOArrow const *arrow, XLArrowType *ptyp, int *pl, int *pw)
+{
+ switch (arrow->typ) {
+ case GO_ARROW_NONE:
+ *ptyp = XL_ARROW_NONE;
+ *pl = 0;
+ *pw = 0;
+ break;
+ case GO_ARROW_KITE:
+ if (fabs (arrow->a - arrow->b) < 0.01) {
+ *ptyp = XL_ARROW_REGULAR;
+ *pl = (int)CLAMP ((arrow->a / 3.5) - 1, 0.0, 2.0);
+ *pw = (int)CLAMP ((arrow->c / 2.5) - 1, 0.0, 2.0);
+ } else if (arrow->a > arrow->b) {
+ *ptyp = XL_ARROW_DIAMOND;
+ *pl = (int)CLAMP ((arrow->a / 5.0) - 1, 0.0, 2.0);
+ *pw = (int)CLAMP ((arrow->c / 2.5) - 1, 0.0, 2.0);
+ } else if (arrow->a < 0.5 * arrow->b) {
+ *ptyp = XL_ARROW_OPEN;
+ *pl = (int)CLAMP ((arrow->a / 1.0) - 1, 0.0, 2.0);
+ *pw = (int)CLAMP ((arrow->c / 1.5) - 1, 0.0, 2.0);
+ } else {
+ *ptyp = XL_ARROW_STEALTH;
+ *pl = (int)CLAMP ((arrow->b / 4.0) - 1, 0.0, 2.0);
+ *pw = (int)CLAMP ((arrow->c / 2.0) - 1, 0.0, 2.0);
+ }
+ break;
+ case GO_ARROW_OVAL:
+ *ptyp = XL_ARROW_OVAL;
+ *pl = (int)CLAMP ((arrow->a / 2.5) - 1, 0.0, 2.0);
+ *pw = (int)CLAMP ((arrow->b / 2.5) - 1, 0.0, 2.0);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
diff --git a/plugins/excel/ms-excel-util.h b/plugins/excel/ms-excel-util.h
index 78d49db..1eb91cb 100644
--- a/plugins/excel/ms-excel-util.h
+++ b/plugins/excel/ms-excel-util.h
@@ -107,5 +107,17 @@ void xls_header_footer_import (PrintHF *hf, const char *txt);
/*****************************************************************************/
+typedef enum {
+ XL_ARROW_NONE = 0,
+ XL_ARROW_REGULAR = 1,
+ XL_ARROW_STEALTH = 2,
+ XL_ARROW_DIAMOND = 3,
+ XL_ARROW_OVAL = 4,
+ XL_ARROW_OPEN = 5
+} XLArrowType;
+
+void xls_arrow_to_xl (GOArrow const *arrow, XLArrowType *ptyp, int *pl, int *pw);
+
+/*****************************************************************************/
#endif /* GNM_MS_EXCEL_UTIL_H */
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 77d47ff..a84e06d 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -4884,42 +4884,10 @@ static void
write_arrow (GOArrow const *arrow, GString *escher, gsize optmark,
guint id)
{
- int typ = 0;
- int l = 0, w = 0;
+ XLArrowType typ;
+ int l, w;
- /* NOTE: This mess should match code in ms-excel-read.c */
-
- switch (arrow->typ) {
- case GO_ARROW_NONE:
- typ = 0;
- break;
- case GO_ARROW_KITE:
- 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 ();
- }
+ xls_arrow_to_xl (arrow, &typ, &l, &w);
switch (id) {
case MSEP_LINESTARTARROWHEAD:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]