Commit 8e21424a 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 #172455 passed with stage
in 3 minutes and 41 seconds
...@@ -41,6 +41,7 @@ check_function_exists(mkstemp HAVE_MKSTEMP) ...@@ -41,6 +41,7 @@ check_function_exists(mkstemp HAVE_MKSTEMP)
check_function_exists(strcpy_s HAVE_STRCPY_S) check_function_exists(strcpy_s HAVE_STRCPY_S)
check_function_exists(strcat_s HAVE_STRCAT_S) check_function_exists(strcat_s HAVE_STRCAT_S)
check_function_exists(strtok_r HAVE_STRTOK_R) check_function_exists(strtok_r HAVE_STRTOK_R)
check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE)
macro(CHECK_FOR_DIR include var) macro(CHECK_FOR_DIR include var)
check_c_source_compiles( check_c_source_compiles(
......
...@@ -91,6 +91,9 @@ ...@@ -91,6 +91,9 @@
/* Defines if strtok_r is available on your system */ /* Defines if strtok_r is available on your system */
#cmakedefine HAVE_STRTOK_R 1 #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'. */ /* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#cmakedefine HAVE_NDIR_H 1 #cmakedefine HAVE_NDIR_H 1
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <clocale>
#include <cstddef> #include <cstddef>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
...@@ -2201,6 +2202,32 @@ void GfxICCBasedColorSpace::getDefaultRanges(double *decodeLow, double *decodeRa ...@@ -2201,6 +2202,32 @@ void GfxICCBasedColorSpace::getDefaultRanges(double *decodeLow, double *decodeRa
} }
#ifdef USE_CMS #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(nullptr);
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() char *GfxICCBasedColorSpace::getPostScriptCSA()
{ {
# if LCMS_VERSION >= 2070 # if LCMS_VERSION >= 2070
...@@ -2212,8 +2239,6 @@ char *GfxICCBasedColorSpace::getPostScriptCSA() ...@@ -2212,8 +2239,6 @@ char *GfxICCBasedColorSpace::getPostScriptCSA()
if (cmsGetEncodedCMMversion() < 2100) if (cmsGetEncodedCMMversion() < 2100)
return nullptr; return nullptr;
int size;
if (psCSA) if (psCSA)
return psCSA; return psCSA;
...@@ -2223,14 +2248,14 @@ char *GfxICCBasedColorSpace::getPostScriptCSA() ...@@ -2223,14 +2248,14 @@ char *GfxICCBasedColorSpace::getPostScriptCSA()
} }
void *rawprofile = profile.get(); 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) { if (size == 0) {
error(errSyntaxWarning, -1, "PostScript CSA is nullptr"); error(errSyntaxWarning, -1, "PostScript CSA is nullptr");
return nullptr; return nullptr;
} }
psCSA = (char *)gmalloc(size + 1); 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; psCSA[size] = 0;
return psCSA; 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