Commit 13cae3eb authored by Albert Astals Cid's avatar Albert Astals Cid

Force C locale in LC_NUMERIC when calling cmsGetPostScriptCSA

Use uselocale if available so we only change the current thread, if not
available (i.e. non posix, we hope the process is not doing anything
numeric related in a different thread)

Otherwise we get brokenly formatted PS
parent c290052d
Pipeline #172452 failed with stage
in 3 minutes and 9 seconds
......@@ -41,6 +41,7 @@ check_function_exists(mkstemp HAVE_MKSTEMP)
check_function_exists(strcpy_s HAVE_STRCPY_S)
check_function_exists(strcat_s HAVE_STRCAT_S)
check_function_exists(strtok_r HAVE_STRTOK_R)
check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE)
macro(CHECK_FOR_DIR include var)
check_c_source_compiles(
......
......@@ -91,6 +91,9 @@
/* Defines if strtok_r is available on your system */
#cmakedefine HAVE_STRTOK_R 1
/* Defines if strtok_r is available on your system */
#cmakedefine HAVE_USELOCALE 1
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#cmakedefine HAVE_NDIR_H 1
......
......@@ -45,6 +45,7 @@
#include <algorithm>
#include <memory>
#include <clocale>
#include <cstddef>
#include <cmath>
#include <cstring>
......@@ -2201,6 +2202,32 @@ void GfxICCBasedColorSpace::getDefaultRanges(double *decodeLow, double *decodeRa
}
#ifdef USE_CMS
static int call_cmsGetPostScriptCSA(cmsContext ContextID, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags, void *Buffer, cmsUInt32Number dwBufferLen)
{
// We need to switch the locale
// until we can depend on https://github.com/mm2/Little-CMS/issues/223 being fixed
# ifdef HAVE_USELOCALE
locale_t oldLocale = uselocale(NULL);
locale_t nLocale = duplocale(oldLocale);
nLocale = newlocale(LC_NUMERIC_MASK, "C", nLocale);
uselocale(nLocale);
# else
const char *old = setlocale(LC_NUMERIC, "C");
# endif
const int size = cmsGetPostScriptCSA(ContextID, hProfile, Intent, dwFlags, Buffer, dwBufferLen);
# ifdef HAVE_USELOCALE
uselocale(oldLocale);
freelocale(nLocale);
# else
setlocale(LC_NUMERIC, old);
# endif
return size;
}
char *GfxICCBasedColorSpace::getPostScriptCSA()
{
# if LCMS_VERSION >= 2070
......@@ -2212,8 +2239,6 @@ char *GfxICCBasedColorSpace::getPostScriptCSA()
if (cmsGetEncodedCMMversion() < 2100)
return nullptr;
int size;
if (psCSA)
return psCSA;
......@@ -2223,14 +2248,14 @@ char *GfxICCBasedColorSpace::getPostScriptCSA()
}
void *rawprofile = profile.get();
size = cmsGetPostScriptCSA(cmsGetProfileContextID(rawprofile), rawprofile, getIntent(), 0, nullptr, 0);
const int size = call_cmsGetPostScriptCSA(cmsGetProfileContextID(rawprofile), rawprofile, getIntent(), 0, nullptr, 0);
if (size == 0) {
error(errSyntaxWarning, -1, "PostScript CSA is nullptr");
return nullptr;
}
psCSA = (char *)gmalloc(size + 1);
cmsGetPostScriptCSA(cmsGetProfileContextID(rawprofile), rawprofile, getIntent(), 0, psCSA, size);
call_cmsGetPostScriptCSA(cmsGetProfileContextID(rawprofile), rawprofile, getIntent(), 0, psCSA, size);
psCSA[size] = 0;
return psCSA;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment