[gnumeric] translation of angles to go_gradient_directions is needed more generally...



commit cf703d0553edc03e61cb01cd710281aadcf1e065
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Tue Jun 14 14:39:57 2011 -0600

    translation of angles to go_gradient_directions is needed more generally...
    
    2011-06-14  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* xlsx-utils.h (xlsx_get_gradient_direction): new
    	* xlsx-utils.c (xlsx_get_gradient_direction): new
    	* xlsx-read-drawing.c (xlsx_chart_grad_linear): use
    	xlsx_get_gradient_direction

 plugins/excel/ChangeLog           |    7 ++++++
 plugins/excel/xlsx-read-drawing.c |   32 ++--------------------------
 plugins/excel/xlsx-utils.c        |   40 +++++++++++++++++++++++++++++++++++++
 plugins/excel/xlsx-utils.h        |    2 +
 4 files changed, 52 insertions(+), 29 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 97f279c..9f4c7ef 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,12 @@
 2011-06-14  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* xlsx-utils.h (xlsx_get_gradient_direction): new
+	* xlsx-utils.c (xlsx_get_gradient_direction): new
+	* xlsx-read-drawing.c (xlsx_chart_grad_linear): use
+	xlsx_get_gradient_direction
+
+2011-06-14  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* xlsx-read.c (xlsx_cell_begin): don't overwrite an existing row style
 	(xlsx_CT_Row): the row style should only be used if customFormat == 1
 	(xlsx_CT_GradientFill): consider this a solid colour fill until we
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index dc50d44..cf5c5c4 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -964,35 +964,9 @@ xlsx_chart_grad_linear (GsfXMLIn *xin, xmlChar const **attrs)
 	int ang;
 	g_return_if_fail (state->cur_style);
 	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
-		if (attr_int (xin, attrs, "ang", &ang)) {
-			ang = ((ang / 60000) + 22) / 45; /* now ang is between 0 and 8 */
-			switch (ang) {
-			case 1:
-				state->cur_style->fill.gradient.dir = GO_GRADIENT_NW_TO_SE;
-				break;
-			case 2:
-				state->cur_style->fill.gradient.dir = GO_GRADIENT_W_TO_E;
-				break;
-			case 3:
-				state->cur_style->fill.gradient.dir = GO_GRADIENT_SW_TO_NE;
-				break;
-			case 4:
-				state->cur_style->fill.gradient.dir = GO_GRADIENT_S_TO_N;
-				break;
-			case 5:
-				state->cur_style->fill.gradient.dir = GO_GRADIENT_SE_TO_NW;
-				break;
-			case 6:
-				state->cur_style->fill.gradient.dir = GO_GRADIENT_E_TO_W;
-				break;
-			case 7:
-				state->cur_style->fill.gradient.dir = GO_GRADIENT_NE_TO_SW;
-				break;
-			default:
-				state->cur_style->fill.gradient.dir = GO_GRADIENT_N_TO_S;
-				break;
-			}
-		}
+		if (attr_int (xin, attrs, "ang", &ang))
+			state->cur_style->fill.gradient.dir 
+				= xlsx_get_gradient_direction (ang / 60000.);
 	/* FIXME: we do not support the "scaled" attribute */
 }
 
diff --git a/plugins/excel/xlsx-utils.c b/plugins/excel/xlsx-utils.c
index 7a4f463..15b67eb 100644
--- a/plugins/excel/xlsx-utils.c
+++ b/plugins/excel/xlsx-utils.c
@@ -166,3 +166,43 @@ xlsx_pivot_date_fmt (void)
 	return go_format_new_from_XL ("yyyy-mm-dd\"T\"hh:mm:ss");
 }
 
+/**
+ * xlsx_get_direction :
+ *
+ * Returns a GOGradientDirection corresponding to the angle ang (0...360)
+ **/
+GOGradientDirection 
+xlsx_get_gradient_direction (double ang)
+{
+	int ang_i;
+	g_return_val_if_fail (ang >=-360. && ang <= 360., GO_GRADIENT_N_TO_S);
+	
+	ang_i = ang;
+	while (ang_i < 0)
+		ang_i += 360;
+	while (ang_i >= 360)
+		ang_i -= 360;
+
+	ang_i = (ang_i + 22) / 45; /* now ang is between 0 and 8 */
+
+	switch (ang_i) {
+	case 1:
+		return GO_GRADIENT_NW_TO_SE;
+	case 2:
+		return GO_GRADIENT_W_TO_E;
+	case 3:
+		return GO_GRADIENT_SW_TO_NE;
+	case 4:
+		return GO_GRADIENT_S_TO_N;
+	case 5:
+		return GO_GRADIENT_SE_TO_NW;
+	case 6:
+		return GO_GRADIENT_E_TO_W;
+	case 7:
+		return GO_GRADIENT_NE_TO_SW;
+	case 0:
+	case 8:
+	default:
+		return GO_GRADIENT_N_TO_S;
+	}
+}
diff --git a/plugins/excel/xlsx-utils.h b/plugins/excel/xlsx-utils.h
index 4c271e1..016fdb5 100644
--- a/plugins/excel/xlsx-utils.h
+++ b/plugins/excel/xlsx-utils.h
@@ -51,4 +51,6 @@ void		xlsx_conventions_free (GnmConventions *conv);
 
 GOFormat       *xlsx_pivot_date_fmt   (void);
 
+GOGradientDirection xlsx_get_gradient_direction (double ang);
+
 #endif /* GNM_XLSX_UTILS_H */



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