I have some postscript resource files for drawing objects (flaggs) in any postscript file (inspired from Terry Burton's postscriptbarcode).
The files for drawing the flaggs are in subfolder Flaggs (without extension .ps), together with some helper files,
especially sethexcolor
, defining a function sethexcolor
, to set RGB color from a hexstring.
I have a file sample.ps
above the subfolder Flaggs with code:
100 600 moveto
100 /square /Flaggs findresource exec % draw a square of size 100
showpage
File square
has code:
1 dict
dup /sethexcolor dup /Flaggs findresource put
begin
/square {
/size exch def
currentpoint translate
/red (ff0000) def
red sethexcolor
% 1 0 0 setrgbcolor
} bind def
/square dup load /Flaggs defineresource pop
end
I'm working in Windows 7 with ghostscript 9.10.
Ghostscript is called with command line parameter -P
to look for files in current folder first.
(Search path can be seen with gswin32c [-P] -h in command shell). Normally this works fine (e.g. with postscriptbarcode, see above).
But here it doesn't work: Starting sample.ps
, I get an error message:
Error: /undefined in sethexcolor
Operand stack:
(ff0000)
(After setting RGB color with 1 0 0 setrgbcolor
, it works.)
If I change red sethexcolor
to red /sethexcolor
or red //sethexcolor
, there's no error message, and a square is drawn -
but in black, not in red.
What's wrong with this postscript code?
Why can't function square
call function sethexcolor
in the same folder?
Wolfgang
Try
Using an immediate name (with
//
) will load the current definition while thesquare
procedure body is being constructed. Sincesethexcolor
is (presumably) a procedure, you must explicitlyexec
it in order to execute.