@@ -329,6 +329,32 @@ char* RemoveCR(const char* txt)
329329
330330}
331331
332+ // Writes the body of a PostScript string literal, escaping the metacharacters
333+ // '\\', '(' and ')' and emitting non-printable / high-bit bytes as octal
334+ // triples per PLRM 3.3.4.1. The caller is responsible for the surrounding
335+ // '(' and ')' delimiters.
336+ static
337+ void EmitPSEscaped (cmsIOHANDLER * m , const char * txt )
338+ {
339+ const unsigned char * p ;
340+
341+ if (txt == NULL ) return ;
342+
343+ for (p = (const unsigned char * )txt ; * p != 0 ; p ++ ) {
344+ unsigned char c = * p ;
345+
346+ if (c == '\\' || c == '(' || c == ')' ) {
347+ _cmsIOPrintf (m , "\\%c" , c );
348+ }
349+ else if (c < 0x20 || c >= 0x7F ) {
350+ _cmsIOPrintf (m , "\\%03o" , c );
351+ }
352+ else {
353+ _cmsIOPrintf (m , "%c" , c );
354+ }
355+ }
356+ }
357+
332358static
333359void EmitHeader (cmsIOHANDLER * m , const char * Title , cmsHPROFILE hProfile )
334360{
@@ -1019,7 +1045,10 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number
10191045 continue ;
10201046
10211047 cmsDoTransform (xform , In , & Lab , 1 );
1022- _cmsIOPrintf (m , " (%s) [ %.3f %.3f %.3f ]\n" , ColorName , Lab .L , Lab .a , Lab .b );
1048+
1049+ _cmsIOPrintf (m , " (" );
1050+ EmitPSEscaped (m , ColorName );
1051+ _cmsIOPrintf (m , ") [ %.3f %.3f %.3f ]\n" , Lab .L , Lab .a , Lab .b );
10231052 }
10241053
10251054 _cmsIOPrintf (m , ">>\n" );
@@ -1454,7 +1483,10 @@ int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number
14541483
14551484 cmsDoTransform (xform , In , Out , 1 );
14561485 BuildColorantList (Colorant , nColorant , Out );
1457- _cmsIOPrintf (m , " (%s) [ %s ]\n" , ColorName , Colorant );
1486+
1487+ _cmsIOPrintf (m , " (" );
1488+ EmitPSEscaped (m , ColorName );
1489+ _cmsIOPrintf (m , ") [ %s ]\n" , Colorant );
14581490 }
14591491
14601492 _cmsIOPrintf (m , " >>" );
0 commit comments