[gnumeric] read percentage values in dash specifications during ODF import



commit 1ed1836db5c7c1c9d78743f0f3f3e7df6701e347
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sun Sep 4 13:57:54 2011 -0600

    read percentage values in dash specifications during ODF import
    
    2011-09-04  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_attr_percent_or_distance): new
    	(oo_dash): use oo_attr_percent_or_distance

 plugins/openoffice/ChangeLog         |    5 ++++
 plugins/openoffice/openoffice-read.c |   45 ++++++++++++++++++++++++++-------
 2 files changed, 40 insertions(+), 10 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 0bc2d72..9c91ad9 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,8 @@
+2011-09-04  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (oo_attr_percent_or_distance): new
+	(oo_dash): use oo_attr_percent_or_distance
+
 2011-08-29  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-read.c (odf_attr_range): new
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 97dbd94..73d9f45 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -616,6 +616,7 @@ oo_attr_percent (GsfXMLIn *xin, xmlChar const * const *attrs,
 	*res = tmp/100.;
 	return TRUE;
 }
+
 static GnmColor *magic_transparent;
 
 static GnmColor *
@@ -1010,7 +1011,33 @@ oo_attr_distance (GsfXMLIn *xin, xmlChar const * const *attrs,
 	return oo_parse_distance (xin, attrs[1], name, pts);
 }
 
-/* returns pts */
+static gboolean
+oo_attr_percent_or_distance (GsfXMLIn *xin, xmlChar const * const *attrs,
+			     int ns_id, char const *name, gnm_float *res, 
+			     gboolean *found_percent)
+{
+	char *end;
+	double tmp;
+
+	g_return_val_if_fail (attrs != NULL, FALSE);
+	g_return_val_if_fail (attrs[0] != NULL, FALSE);
+	g_return_val_if_fail (attrs[1] != NULL, FALSE);
+	g_return_val_if_fail (res != NULL, FALSE);
+	g_return_val_if_fail (found_percent != NULL, FALSE);
+
+	if (!gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), ns_id, name))
+		return FALSE;
+
+	tmp = gnm_strto (CXML2C (attrs[1]), &end);
+	if (*end != '%' || *(end + 1)) {
+		*found_percent = FALSE;
+		return (NULL != oo_parse_distance (xin, attrs[1], name, res));
+	}
+	*res = tmp/100.;
+	*found_percent = TRUE;
+	return TRUE;
+}
+
 static char const *
 oo_parse_angle (GsfXMLIn *xin, xmlChar const *str,
 		  char const *name, int *angle)
@@ -3153,21 +3180,19 @@ oo_dash (GsfXMLIn *xin, xmlChar const **attrs)
 	char const *name = NULL;
 	gnm_float distance = 0., len_dot1 = 0., len_dot2 = 0.;
 	int n_dots1 = 0, n_dots2 = 2;
+	gboolean found_percent;
 
 	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
 		if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_DRAW, "name"))
 			name = CXML2C (attrs[1]);
 		else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_DRAW, "style"))
 			/* rect or round, ignored */;
-		else if (NULL != oo_attr_distance (xin, attrs, OO_NS_DRAW, "distance",
-						   &distance))
-			/* FIXME: this could be a percentage in 1.2 */;
-		else if (NULL != oo_attr_distance (xin, attrs, OO_NS_DRAW, "dots1-length",
-						   &len_dot1))
-			/* FIXME: this could be a percentage in 1.2 */;
-		else if (NULL != oo_attr_distance (xin, attrs, OO_NS_DRAW, "dots2-length",
-						   &len_dot2))
-			/* FIXME: this could be a percentage in 1.2 */;
+		else if (oo_attr_percent_or_distance (xin, attrs, OO_NS_DRAW, "distance",
+							      &distance, &found_percent));
+		else if (oo_attr_percent_or_distance (xin, attrs, OO_NS_DRAW, "dots1-length",
+							      &len_dot1, &found_percent));
+		else if (oo_attr_percent_or_distance (xin, attrs, OO_NS_DRAW, "dots2-length",
+							      &len_dot2, &found_percent));
 		else if (oo_attr_int_range (xin, attrs, OO_NS_DRAW,
 					    "dots1", &n_dots1, 0, 10));
 		else if (oo_attr_int_range (xin, attrs, OO_NS_DRAW,



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