postscripteps

Overriding postscript /setcmykcolor


I'm trying to change the color from EPS files that contain only vectors (no rasters). Currently, I convert them to SVG, manipulate the colors, and convert them back to PDF or EPS with Inkscape. This works perfectly but doesn't allow me to apply CMYK coloring, only RGB. After investigating a little bit and finding answers like this or this I'm trying to override the /setcmykcolor function my EPS file uses. You can download it from here.

The EPS looks like this:

enter image description here

And I want to convert the color to CMYK = 0 1 1 0 so it looks like this:

enter image description here

In this case, the EPS file is black but it could be any other color. I tried adding this after %%BeginProlog which should override the /setcmykcolor to always apply 0 1 1 0 as the CMYK color:

/osetcmykcolor {/setcmykcolor} bind def /setcmykcolor {pop [0 1 1 0] osetcmykcolor} def

Or this:

/osetcmykcolor {/setcmykcolor} bind def /setcmykcolor {0 1 1 0 osetcmykcolor} def

But everything is still black. I know /setcmykcolor is the right function because using 0 1 1 0 setcmykcolor just before drawing the path makes it red. I went through postscript programming manuals but I'm having a hard time trying to figure out what's wrong here!

Any help would be greatly appreciated!


Solution

  • If I start Ghostscript then do :

    GS> /osetcmykcolor /setcmykcolor load def
    GS> /setcmykcolor {pop pop pop pop 0 1 1 0 osetcmykcolor} bind def
    GS> (color.eps) run
    

    then the EPS is rendered in 'orange' as you expect.

    Note that setcmykcolor takes 4 arguments so you have to pop all 4 (though this won't be causing a lack of colour, it's just leaving junk on the stack).

    Editing the EPS file:

    %!PS-Adobe-3.0 EPSF-3.0
    %%BoundingBox: 0 0 564 454
    %%HiResBoundingBox: 0.00 0.00 564.00 453.20
    %%Creator: GPL Ghostscript 921 (eps2write)
    %%LanguageLevel: 2
    %%CreationDate: D:20200616000003-03'00'
    %%Pages: 1
    %%EndComments
    %%BeginProlog
    /osetcmykcolor /setcmykcolor load def
    /setcmykcolor {pop pop pop pop 0 1 1 0 osetcmykcolor} bind def
    /DSC_OPDFREAD true def
    

    and then running it with:

    gs color1.eps
    

    also produces orange text. So how are you testing it ?