summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-06-05 11:21:20 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-06-05 11:21:20 +0100
commit71b5cb3e7c963f10af9be66df958ac98e92f8042 (patch)
tree0e05d2cde19f26c566268d355c47d1614e42d93a
parent3150546e30af97ed08626b35f8d2ee176412676a (diff)
downloadenlightenment-71b5cb3e7c963f10af9be66df958ac98e92f8042.tar.gz
xsettings - always use decimal for format for float prints
snprintf will use locale and maybe print 10,24 instead of 10.24 ... thus use a custom routine to specially do this always by hand without mssing with locale. @fix
-rw-r--r--src/bin/e_xsettings.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/src/bin/e_xsettings.c b/src/bin/e_xsettings.c
index ba9aa06e52..ee672c24c0 100644
--- a/src/bin/e_xsettings.c
+++ b/src/bin/e_xsettings.c
@@ -509,6 +509,44 @@ _e_xsettings_theme_set(void)
_e_xsettings_string_set(_setting_theme_name, NULL);
}
+static int
+_dbl_to_str(char *buf, size_t buf_size, double val, int decimals)
+{
+ int ival;
+ size_t l = 0;
+
+ if (val < 0)
+ {
+ if (buf_size < 2) return -1;
+ val = -val;
+ buf[0] = '-';
+ buf[1] = 0;
+ l++;
+ }
+ ival = val;
+ snprintf(buf + l, buf_size - l, "%i", ival);
+ if (decimals <= 0) return 0;
+ l = strlen(buf);
+ if (l >= (buf_size - 2)) return -1;
+ buf[l] = '.';
+ buf[l + 1] = 0;
+ l++;
+
+ while (decimals > 0)
+ {
+ if (l >= (buf_size - 1)) return -1;
+ val *= 10.0;
+ ival = val;
+ val = val - ival;
+ buf[l] = '0' + (ival % 10);
+ buf[l + 1] = 0;
+ l++;
+ if (l >= (buf_size - 1)) return -1;
+ decimals--;
+ }
+ return 0;
+}
+
static void
_e_xsettings_font_set(void)
{
@@ -525,17 +563,18 @@ _e_xsettings_font_set(void)
Eina_Strbuf *buf;
Eina_List *l;
int size = efd->size;
- char size_buf[12];
+ char size_buf[32];
const char *p;
/* TODO better way to convert evas font sizes? */
- if (!size) size = 12;
- else if (size < 0) size /= -10;
- else if (size < 5) size = 5;
- else if (size > 25) size = 25;
+ if (!size) size = 10; // default if not set
+ else if (size < 0) size /= -10; // in 1/10th units
+
+ // limit sizes
+ if (size < 5) size = 5; // don't allow too small
+ else if (size > 100) size = 100; // don't allow silly sizes
- /* Convert from pixels to point. */
- snprintf(size_buf, sizeof(size_buf), "%1.1f", (float) size * 0.75);
+ _dbl_to_str(size_buf, sizeof(size_buf), (double)size * 0.75, 3);
buf = eina_strbuf_new();
eina_strbuf_append(buf, efp->name);