[glabels] Make fractions more readable



commit 7c7efdf6f7d84030b13761f460eeef61ae0c2fc3
Author: Jim Evins <evins snaught com>
Date:   Sat Mar 13 14:14:12 2010 -0500

    Make fractions more readable
    
    Use Unicode superscripts and subscripts to format fractions.  Should be
    more readable than the uggly 1_5/8.

 libglabels/str.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/libglabels/str.c b/libglabels/str.c
index 0f0339b..a323627 100644
--- a/libglabels/str.c
+++ b/libglabels/str.c
@@ -227,7 +227,12 @@ span_non_digits (gchar **p)
 gchar *
 lgl_str_format_fraction (gdouble x)
 {
-	static gdouble denom[] = { 1., 2., 3., 4., 8., 16., 32., 0. };
+	static gdouble denom[]        = {  1.,  2., 3.,  4.,  8.,  16.,  32.,  0. };
+        static gchar  *denom_string[] = { "1", "â??", "â??", "â??", "â??", "â??â??", "â??â??", NULL };
+        static gchar  *num_string[]   = {  "�",  "¹",  "²",  "³",  "�",  "�",  "�",  "�",  "�",  "�",
+                                          "¹�", "¹¹", "¹²", "¹³", "¹�", "¹�", "¹�", "¹�", "¹�", "¹�",
+                                          "²�", "²¹", "²²", "²³", "²�", "²�", "²�", "²�", "²�", "²�",
+                                          "³�", "³¹" };
 	gint i;
 	gdouble product, remainder;
 	gint n, d;
@@ -249,9 +254,9 @@ lgl_str_format_fraction (gdouble x)
 	n = (gint)( x * denom[i] + 0.5 );
 	d = (gint)denom[i];
 	if ( n > d ) {
-		return g_strdup_printf ("%d_%d/%d", (n/d), (n%d), d);
+		return g_strdup_printf ("%d%s/%s", (n/d), num_string[n%d], denom_string[i]);
 	} else {
-		return g_strdup_printf ("%d/%d", (n%d), d);
+		return g_strdup_printf ("%s/%s", num_string[n%d], denom_string[i]);
 	}
 }
 



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