From 18a22b2f08cff079eb32289a69a9c5ce49469cca Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 24 Feb 2026 12:48:41 -0300 Subject: [PATCH] [vector] Use xlocale-guarded decimal separator lookup --- src/hb-vector-svg.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/hb-vector-svg.cc b/src/hb-vector-svg.cc index af4d48207..26c3334d4 100644 --- a/src/hb-vector-svg.cc +++ b/src/hb-vector-svg.cc @@ -32,6 +32,10 @@ #include "hb-map.hh" #include +#include +#ifdef HAVE_XLOCALE_H +#include +#endif #include #include #include @@ -114,11 +118,41 @@ hb_svg_append_num (hb_vector_t *buf, if (fabsf (v) < rounded_zero_threshold) v = 0.f; + if (!(v == v) || !isfinite (v)) + { + hb_svg_append_c (buf, '0'); + return; + } + char fmt[20]; snprintf (fmt, sizeof (fmt), "%%.%uf", effective_precision); char out[128]; snprintf (out, sizeof (out), fmt, (double) v); + const char *decimal_point = "."; + lconv *lc = nullptr; +#if defined(HAVE_XLOCALE_H) && !defined(HB_NO_SETLOCALE) + hb_locale_t current_locale = hb_uselocale ((hb_locale_t) 0); + if (current_locale) + lc = localeconv_l (current_locale); +#endif + if (!lc) + lc = localeconv (); + if (lc && lc->decimal_point && lc->decimal_point[0]) + decimal_point = lc->decimal_point; + + if (decimal_point[0] != '.' || decimal_point[1] != '\0') + { + char *p = strstr (out, decimal_point); + if (p) + { + unsigned dp_len = (unsigned) strlen (decimal_point); + unsigned tail_len = (unsigned) strlen (p + dp_len); + memmove (p + 1, p + dp_len, tail_len + 1); + *p = '.'; + } + } + char *dot = strchr (out, '.'); if (dot) {