[subset-cff] Make BCD writing locale-independent

This commit is contained in:
Behdad Esfahbod 2023-02-19 20:30:38 -07:00
parent 4a735b30c4
commit 5b50b07717
3 changed files with 39 additions and 28 deletions

View File

@ -29,32 +29,6 @@
#include "hb.hh"
#include "hb-machinery.hh"
#if !defined(HB_NO_SETLOCALE) && (!defined(HAVE_NEWLOCALE) || !defined(HAVE_USELOCALE))
#define HB_NO_SETLOCALE 1
#endif
#ifndef HB_NO_SETLOCALE
#include <locale.h>
#ifdef HAVE_XLOCALE_H
#include <xlocale.h> // Needed on BSD/OS X for uselocale
#endif
#ifdef WIN32
#define hb_locale_t _locale_t
#else
#define hb_locale_t locale_t
#endif
#define hb_setlocale setlocale
#define hb_uselocale uselocale
#else
#define hb_locale_t void *
#define hb_setlocale(Category, Locale) "C"
#define hb_uselocale(Locale) ((hb_locale_t) 0)
#endif
/**
* SECTION:hb-common

View File

@ -125,7 +125,13 @@ struct str_encoder_t
*
* We use 8 here to match FontTools X-).
*/
snprintf (buf, sizeof (buf), "%.8G", v); // XXX This is locale-sensitive; Ugh
hb_locale_t clocale HB_UNUSED;
hb_locale_t oldlocale HB_UNUSED;
oldlocale = hb_uselocale (clocale = newlocale (LC_ALL_MASK, "C", NULL));
snprintf (buf, sizeof (buf), "%.8G", v);
(void) hb_uselocale (((void) freelocale (clocale), oldlocale));
char *s = buf;
if (s[0] == '0' && s[1] == '.')
s++;
@ -157,7 +163,7 @@ struct str_encoder_t
continue;
}
case '.': case ',': // Comma for some European locales!!!
case '.': case ',': // Comma for some European locales in case no uselocale available.
nibbles.push (0x0A); // .
continue;

View File

@ -463,6 +463,37 @@ static int HB_UNUSED _hb_errno = 0;
#endif
#endif
// Locale business
#if !defined(HB_NO_SETLOCALE) && (!defined(HAVE_NEWLOCALE) || !defined(HAVE_USELOCALE))
#define HB_NO_SETLOCALE 1
#endif
#ifndef HB_NO_SETLOCALE
#include <locale.h>
#ifdef HAVE_XLOCALE_H
#include <xlocale.h> // Needed on BSD/OS X for uselocale
#endif
#ifdef WIN32
#define hb_locale_t _locale_t
#else
#define hb_locale_t locale_t
#endif
#define hb_setlocale setlocale
#define hb_uselocale uselocale
#else
#define hb_locale_t void *
#define hb_setlocale(Category, Locale) "C"
#define hb_uselocale(Locale) ((hb_locale_t) 0)
#endif
/* Lets assert int types. Saves trouble down the road. */
static_assert ((sizeof (hb_codepoint_t) == 4), "");
static_assert ((sizeof (hb_position_t) == 4), "");