Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #1767 > unrolled thread

How to pass parameter in resource files?

Started byWolfgang Büchel <wolfgang.buechel@gmx.de>
First post2014-01-05 11:18 +0100
Last post2014-01-05 03:55 -0800
Articles 2 — 2 participants

Back to article view | Back to comp.lang.postscript


Contents

  How to pass parameter in resource files? Wolfgang Büchel <wolfgang.buechel@gmx.de> - 2014-01-05 11:18 +0100
    Re: How to pass parameter in resource files? luser- -droog <mijoryx@yahoo.com> - 2014-01-05 03:55 -0800

#1767 — How to pass parameter in resource files?

FromWolfgang Büchel <wolfgang.buechel@gmx.de>
Date2014-01-05 11:18 +0100
SubjectHow to pass parameter in resource files?
Message-ID<op.w87llwynhytalj@zenon.fritz.box>
I have some postscript resource files for drawing objects (flags) in any  
postscript file
(inspired by Terry Burton's postscriptbarcode,  
https://code.google.com/p/postscriptbarcode/).

The files for drawing the flags are in subfolder Flags (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 Flags with code:

     100 600 moveto
     100 /square /Flags findresource exec   % draw a square of size 100
     showpage

File square has code:

     1 dict
     dup /sethexcolor dup /Flags findresource put
     begin
     /square {
         /size exch def
         currentpoint translate
         /red (ff0000) def
         red sethexcolor
         % 1 0 0 setrgbcolor
     } bind def
     /square dup load /Flags defineresource pop
     end

I'm working in Windows 7 with ghostscript 9.10, ghostview 5.0. Ghostscript  
is called with command line parameter -P to search 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 //sethexcolor, there's  
no error message, and a square is drawn - but in black, not in red.

What's wrong with this postscript code?

Wolfgang

[toc] | [next] | [standalone]


#1768

Fromluser- -droog <mijoryx@yahoo.com>
Date2014-01-05 03:55 -0800
Message-ID<c024eb26-c902-4a20-af1f-7ea492690ab2@googlegroups.com>
In reply to#1767
On Sunday, January 5, 2014 4:18:58 AM UTC-6, Wolfgang Büchel wrote:
> I have some postscript resource files for drawing objects (flags) in any  
> postscript file
> (inspired by Terry Burton's postscriptbarcode,  
> 
> https://code.google.com/p/postscriptbarcode/).
> 
> The files for drawing the flags are in subfolder Flags (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 Flags with code:
> 
>      100 600 moveto
>      100 /square /Flags findresource exec   % draw a square of size 100
>      showpage
> 
> File square has code:
> 
>      1 dict
>      dup /sethexcolor dup /Flags findresource put
>      begin
>      /square {
>          /size exch def
>          currentpoint translate
>          /red (ff0000) def
>          red sethexcolor
>          % 1 0 0 setrgbcolor
>      } bind def
>      /square dup load /Flags defineresource pop
>      end
> 
> I'm working in Windows 7 with ghostscript 9.10, ghostview 5.0. Ghostscript  
> is called with command line parameter -P to search 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 //sethexcolor, there's  
> no error message, and a square is drawn - but in black, not in red.
> 
> What's wrong with this postscript code?
> 
> Wolfgang

I've answered this over on stackoverflow, too.
You need to use the //immediate-name syntax and also 
use `exec` to call the procedure.

    red //sethexcolor exec

You've tried lots of things, but each ran into different trouble.

Calling normally

    red sethexcolor

fails because the name is not available because the dict is not 
there at the time this code executes.

Using a literal name

    red /sethexcolor

fails because a literal name doesn't do anything. The stuff just 
sits there on the stack.

Using an immediate name

    red //sethexcolor

fails because although we've looked-up the name and loaded the 
procedure, procedures directly encountered by the interpreter
are not executed but deferred. This is because directly-
encountered procedure bodies are usually used as arguments to
looping or control operators, and so the language is optimized
for this common case. The "normal" way to call a procedure is
by name. Otherwise, if you're doing something tricky, you may
need to use `exec`.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web