summaryrefslogtreecommitdiff
path: root/src
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 /src
parent3150546e30af97ed08626b35f8d2ee176412676a (diff)
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
Diffstat (limited to 'src')
-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 ba9aa06e5..ee672c24c 100644
--- a/src/bin/e_xsettings.c
+++ b/src/bin/e_xsettings.c
@@ -509,6 +509,44 @@ _e_xsettings_theme_set(void)
509 _e_xsettings_string_set(_setting_theme_name, NULL); 509 _e_xsettings_string_set(_setting_theme_name, NULL);
510} 510}
511 511
512static int
513_dbl_to_str(char *buf, size_t buf_size, double val, int decimals)
514{
515 int ival;
516 size_t l = 0;
517
518 if (val < 0)
519 {
520 if (buf_size < 2) return -1;
521 val = -val;
522 buf[0] = '-';
523 buf[1] = 0;
524 l++;
525 }
526 ival = val;
527 snprintf(buf + l, buf_size - l, "%i", ival);
528 if (decimals <= 0) return 0;
529 l = strlen(buf);
530 if (l >= (buf_size - 2)) return -1;
531 buf[l] = '.';
532 buf[l + 1] = 0;
533 l++;
534
535 while (decimals > 0)
536 {
537 if (l >= (buf_size - 1)) return -1;
538 val *= 10.0;
539 ival = val;
540 val = val - ival;
541 buf[l] = '0' + (ival % 10);
542 buf[l + 1] = 0;
543 l++;
544 if (l >= (buf_size - 1)) return -1;
545 decimals--;
546 }
547 return 0;
548}
549
512static void 550static void
513_e_xsettings_font_set(void) 551_e_xsettings_font_set(void)
514{ 552{
@@ -525,17 +563,18 @@ _e_xsettings_font_set(void)
525 Eina_Strbuf *buf; 563 Eina_Strbuf *buf;
526 Eina_List *l; 564 Eina_List *l;
527 int size = efd->size; 565 int size = efd->size;
528 char size_buf[12]; 566 char size_buf[32];
529 const char *p; 567 const char *p;
530 568
531 /* TODO better way to convert evas font sizes? */ 569 /* TODO better way to convert evas font sizes? */
532 if (!size) size = 12; 570 if (!size) size = 10; // default if not set
533 else if (size < 0) size /= -10; 571 else if (size < 0) size /= -10; // in 1/10th units
534 else if (size < 5) size = 5; 572
535 else if (size > 25) size = 25; 573 // limit sizes
574 if (size < 5) size = 5; // don't allow too small
575 else if (size > 100) size = 100; // don't allow silly sizes
536 576
537 /* Convert from pixels to point. */ 577 _dbl_to_str(size_buf, sizeof(size_buf), (double)size * 0.75, 3);
538 snprintf(size_buf, sizeof(size_buf), "%1.1f", (float) size * 0.75);
539 578
540 buf = eina_strbuf_new(); 579 buf = eina_strbuf_new();
541 eina_strbuf_append(buf, efp->name); 580 eina_strbuf_append(buf, efp->name);