template: don't localize floats in the edje editor
Summary: Enventor live edit would generate invalid code with the french locale. Indeed, french uses a comma (",") as the decimal point, instead of the dot. With localization enabled, printf() would automatically localized the floating point, introducing a comma in the edje code where a dot is expected... To avoid this, we now enclose the floats we don't want to be localized (use the implicit POSIX local: with a dot) in a function that looks the current locale and replace the decimal point with a dot. Test Plan: (1) Without the patch, call LC_ALL=C enventor and see live edit if correct. (2) Without the patch, call LC_ALL=fr_FR.UTF-8 envetor and see live edit generate invalid edje code. (3) Apply the patch, and repeat steps (1) and (2) and observe that both cases now success. Reviewers: Hermet Differential Revision: https://phab.enlightenment.org/D4146
This commit is contained in:
parent
bc3a11dbb8
commit
e910826ade
|
@ -178,6 +178,32 @@ select_random_name(Evas_Object *entry, const char* first_line,
|
|||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
_posix_fp(double fp, const char *fmt)
|
||||
{
|
||||
static Eina_Strbuf *strbuf = NULL;
|
||||
static char storage[16];
|
||||
struct lconv *lconv;
|
||||
|
||||
if (EINA_UNLIKELY(strbuf == NULL))
|
||||
{
|
||||
strbuf = eina_strbuf_manage_new_length(storage, sizeof(storage));
|
||||
if (EINA_UNLIKELY(!strbuf))
|
||||
{
|
||||
storage[0] = '\0';
|
||||
return storage;
|
||||
}
|
||||
}
|
||||
|
||||
lconv = localeconv();
|
||||
|
||||
eina_strbuf_reset(strbuf);
|
||||
eina_strbuf_append_printf(strbuf, fmt, fp);
|
||||
eina_strbuf_replace_first(strbuf, lconv->decimal_point, ".");
|
||||
|
||||
return eina_strbuf_string_get(strbuf);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Externally accessible calls */
|
||||
/*****************************************************************************/
|
||||
|
@ -289,7 +315,8 @@ template_part_insert(edit_data *ed, Edje_Part_Type part_type,
|
|||
|
||||
//Apply align values
|
||||
elm_entry_entry_insert(edit_entry, p);
|
||||
snprintf(buf, sizeof(buf), " align: %.1f %.1f;<br/>", align_x, align_y);
|
||||
snprintf(buf, sizeof(buf), " align: %s %s;<br/>",
|
||||
_posix_fp(align_x, "%.1f"), _posix_fp(align_y, "%1.f"));
|
||||
elm_entry_entry_insert(edit_entry, buf);
|
||||
line_cnt++;
|
||||
|
||||
|
@ -346,22 +373,22 @@ template_part_insert(edit_data *ed, Edje_Part_Type part_type,
|
|||
(int)(rel2_y * 10000 + 0.5) % 100)
|
||||
{
|
||||
|
||||
snprintf(buf, sizeof(buf), " rel1.relative: %.4f %.4f;<br/>",
|
||||
rel1_x, rel1_y);
|
||||
snprintf(buf, sizeof(buf), " rel1.relative: %s %s;<br/>",
|
||||
_posix_fp(rel1_x, "%.4f"), _posix_fp(rel1_y, "%.4f"));
|
||||
elm_entry_entry_insert(edit_entry, buf);
|
||||
elm_entry_entry_insert(edit_entry, p);
|
||||
snprintf(buf, sizeof(buf), " rel2.relative: %.4f %.4f;<br/>",
|
||||
rel2_x, rel2_y);
|
||||
snprintf(buf, sizeof(buf), " rel2.relative: %s %s;<br/>",
|
||||
_posix_fp(rel2_x, "%.4f"), _posix_fp(rel2_y, "%.4f"));
|
||||
}
|
||||
//Condition 2: relative values are 2 places of decimals
|
||||
else
|
||||
{
|
||||
snprintf(buf, sizeof(buf), " rel1.relative: %.2f %.2f;<br/>",
|
||||
rel1_x, rel1_y);
|
||||
snprintf(buf, sizeof(buf), " rel1.relative: %s %s;<br/>",
|
||||
_posix_fp(rel1_x, "%.2f"), _posix_fp(rel1_y, "%.2f"));
|
||||
elm_entry_entry_insert(edit_entry, buf);
|
||||
elm_entry_entry_insert(edit_entry, p);
|
||||
snprintf(buf, sizeof(buf), " rel2.relative: %.2f %.2f;<br/>",
|
||||
rel2_x, rel2_y);
|
||||
snprintf(buf, sizeof(buf), " rel2.relative: %s %s;<br/>",
|
||||
_posix_fp(rel2_x, "%.2f"), _posix_fp(rel2_y, "%.2f"));
|
||||
}
|
||||
|
||||
elm_entry_entry_insert(edit_entry, buf);
|
||||
|
|
Loading…
Reference in New Issue