From: Jim Evins Date: Sat, 13 Mar 2010 19:14:12 +0000 (-0500) Subject: Make fractions more readable X-Git-Tag: glabels-2_3_0~67 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7c7efdf6f7d84030b13761f460eeef61ae0c2fc3;p=glabels Make fractions more readable Use Unicode superscripts and subscripts to format fractions. Should be more readable than the uggly 1_5/8. --- diff --git a/libglabels/str.c b/libglabels/str.c index 0f0339ba..a3236275 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]); } }