[goffice] handle fractions in go_format_get_details



commit 097ec3bf33e08fd8a3077028c8af4472ce1f4dc1
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Wed Aug 24 17:12:39 2011 -0600

    handle fractions in go_format_get_details
    
    2011-08-24  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* goffice/utils/go-format.c (go_format_get_details): handle fractions

 ChangeLog                 |    4 +++
 goffice/utils/go-format.c |   52 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d33e93c..909c654 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-08-24  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* goffice/utils/go-format.c (go_format_get_details): handle fractions
+
+2011-08-24  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* goffice/gtk/go-format-sel.c (FormatWidget): add widgets for fraction
 	formatting
 	(cb_denominator_changed): new
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 28a6da2..4603801 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -5713,6 +5713,58 @@ go_format_get_details (GOFormat const *fmt,
 		break;
 	}
 
+	case GO_FORMAT_FRACTION: {
+ 		gchar **tokens = g_strsplit_set (str, " /", 3);
+		int numerator_base;
+		char const *integer;
+		int d;
+
+		/* Since it is a fraction we get at least 2 tokens */
+		g_return_if_fail (tokens + 1 != NULL);
+
+		dst->split_fraction = (tokens[2] != NULL && strlen (tokens[0]) > 0);
+		if (dst->split_fraction) {
+			integer = tokens[0];
+			dst->min_digits = 0;
+			while (*integer != 0)
+				if (*integer++ == '0')
+					dst->min_digits++;
+			numerator_base = 1;
+		} else
+			numerator_base = 0;
+		
+		integer = tokens[numerator_base];
+		dst->numerator_min_digits = 0;
+		while (*integer != 0)
+			if (*integer++ == '0')
+				dst->numerator_min_digits++;
+
+		integer = tokens[numerator_base + 1];
+		d = atoi (integer);
+		if (d > 1) {
+			dst->denominator = d;
+			dst->automatic_denominator = FALSE;
+		} else {
+			dst->automatic_denominator = TRUE;
+			dst->denominator_min_digits = 0;
+			dst->denominator_max_digits = 0;
+			while (*integer != 0) {
+				dst->denominator_max_digits++;
+				if (*integer++ == '0')
+					dst->denominator_min_digits++;
+			}
+		}
+
+		g_strfreev (tokens);	
+
+		if (exact != NULL) {
+			newstr = g_string_new (NULL);
+			go_format_generate_str (newstr, dst);
+		}
+
+		break;
+	}
+
 	default:
 		break;
 	}



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