Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locale for aperture filter #16044

Merged
merged 7 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/common/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ guint dt_util_str_occurence(const gchar *haystack, const gchar *needle)
return o;
}

gchar *dt_util_float_to_str(const gchar *format, const double value)
{
#if defined(WIN32)
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
setlocale (LC_NUMERIC, "C");
#else
locale_t nlocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
locale_t locale = uselocale(nlocale);
#endif

gchar *txt = g_strdup_printf(format, value);

#if defined(WIN32)
_configthreadlocale(_DISABLE_PER_THREAD_LOCALE);
#else
uselocale(locale);
freelocale(nlocale);
#endif
return txt;
}

gchar *dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute)
{
const gint occurrences = dt_util_str_occurence(string, pattern);
Expand Down
2 changes: 2 additions & 0 deletions src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ gchar *dt_util_dstrcat(gchar *str, const gchar *format, ...) __attribute__((form
gchar *dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute);
/** count the number of occurrences of needle in haystack */
guint dt_util_str_occurence(const gchar *haystack, const gchar *needle);
/** format a floating point number string with dot separator locale independent */
gchar *dt_util_float_to_str(const gchar *format, const double value);
/** generate a string from the elements of the list, separated by separator. the result has to be freed. */
gchar *dt_util_glist_to_str(const gchar *separator, GList *items);
/** generate a GList from the elements of a string, separated by separator. the result has to be freed. */
Expand Down
10 changes: 9 additions & 1 deletion src/libs/filters/aperture.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
This file contains the necessary routines to implement a filter for the filtering module
*/

#include "common/utility.h"

static gboolean _aperture_update(dt_lib_filtering_rule_t *rule)
{
Expand Down Expand Up @@ -67,7 +68,14 @@ static gboolean _aperture_update(dt_lib_filtering_rule_t *rule)

static gchar *_aperture_print_func(const double value, const gboolean detailled)
{
return g_strdup_printf("%s%.1lf", detailled ? "f/" : "", value);
if(detailled)
{
return g_strdup_printf("f/%.1lf", value);
}
else
{
return dt_util_float_to_str("%.1f", value);
}
}

static void _aperture_widget_init(dt_lib_filtering_rule_t *rule, const dt_collection_properties_t prop,
Expand Down
10 changes: 3 additions & 7 deletions src/libs/filters/exposure.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
This file contains the necessary routines to implement a filter for the filtering module
*/

#include "common/utility.h"

static gboolean _exposure_update(dt_lib_filtering_rule_t *rule)
{
Expand Down Expand Up @@ -84,12 +85,7 @@ static gchar *_exposure_print_func(const double value, const gboolean detailled)
}
else
{
gchar *locale = g_strdup(setlocale(LC_ALL, NULL));
setlocale(LC_NUMERIC, "C");
gchar *txt = g_strdup_printf("%.6lf", value);
setlocale(LC_NUMERIC, locale);
g_free(locale);
return txt;
return dt_util_float_to_str("%.6lf", value);
}
}

Expand Down Expand Up @@ -139,4 +135,4 @@ static void _exposure_widget_init(dt_lib_filtering_rule_t *rule, const dt_collec
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on
// clang-format on
10 changes: 3 additions & 7 deletions src/libs/filters/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
This file contains the necessary routines to implement a filter for the filtering module
*/

#include "common/utility.h"

static gboolean _iso_update(dt_lib_filtering_rule_t *rule)
{
Expand Down Expand Up @@ -91,12 +92,7 @@ static gchar *_iso_print_func(const double value, const gboolean detailled)
}
else
{
gchar *locale = g_strdup(setlocale(LC_ALL, NULL));
setlocale(LC_NUMERIC, "C");
gchar *txt = g_strdup_printf("%.0lf", value);
setlocale(LC_NUMERIC, locale);
g_free(locale);
return txt;
return dt_util_float_to_str("%.0lf", value);
}
}

Expand Down Expand Up @@ -140,4 +136,4 @@ static void _iso_widget_init(dt_lib_filtering_rule_t *rule, const dt_collection_
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on
// clang-format on
10 changes: 4 additions & 6 deletions src/libs/filters/ratio.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
This file contains the necessary routines to implement a filter for the filtering module
*/

#include "common/utility.h"

static gboolean _ratio_update(dt_lib_filtering_rule_t *rule)
{
if(!rule->w_specific) return FALSE;
Expand Down Expand Up @@ -110,11 +112,7 @@ static double _ratio_value_from_band_func(const double value)

static gchar *_ratio_print_func(const double value, const gboolean detailled)
{
gchar *locale = g_strdup(setlocale(LC_ALL, NULL));
setlocale(LC_NUMERIC, "C");
gchar *txt = g_strdup_printf("%.2lf", value);
setlocale(LC_NUMERIC, locale);
g_free(locale);
gchar *txt = dt_util_float_to_str("%.2lf", value);

if(detailled)
{
Expand Down Expand Up @@ -169,4 +167,4 @@ static void _ratio_widget_init(dt_lib_filtering_rule_t *rule, const dt_collectio
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on
// clang-format on