Postscript: know what I need, no clue how to do it

189 views Asked by At

We create printfiles by gluing ps and eps files together and overlay data to print customer forms.. and then send those files to the printer.

As printers have changed we have had to adjust the scripts.. We are now looking at XEROX printers and they are very different animals..

We've built a procedure that sets the tray to print from and it needs a change..

 /stray 
{   
/Pagedv exch def
 #ifdef :OK431   
/DriverOps /ProcSet 2 copy resourcestatus{pop pop findresource Pagedv exch /setinputslot get exec}{pop pop}ifelse globaldict /OK@_CustTray 0 put
 #elif :O4600   
 /PageSub Pagedv 1 sub def   currentpagedevice /InputAttributes get PageSub known{ Pagedv statusdict /setpapertray 2 copy known{ get {exec}stopped {pop}{globaldict /OK@_CustTray PageSub put}ifelse (<<) cvx exec /Policies (<<) cvx exec /PageSize 7 (>>) cvx
 exec (>>) cvx exec setpagedevice }{pop pop pop}ifelse }if
 #elif :HPPRO   
  currentpagedevice /InputAttributes get Pagedv  <</MediaPosition Pagedv >> setpagedevice
 #else   
 <<currentpagedevice /InputAttributes get Pagedv get {}forall /InputAttributes << /Priority [Pagedv] >> >> setpagedevice

Xerox doesn't use a number according to the PPD it uses a string (ie Tray-1)

Pagedv is an integer so I need to append (concatenate) the literal "Tray-" onto it before we return it to the caller

> #elif :XRX   
>  currentpagedevice /InputAttributes get Pagedv  << (Tray-Pagedv) xerox$MediaInputTray >> setpagedevice

I have a concatenate procedure I'm just not sure how to use it in this case.

/concatstrings % (a) (b) -> (ab)     
{ exch dup length    
    2 index length add string    
    dup dup 4 2 roll copy length
    4 -1 roll putinterval    
} bind def
1

There are 1 answers

0
KenS On

Well if you want to concatenate two strings to produce a new string, and what you have is a string and an integer (Pagedv), then the first thing you need to do is turn the integer into a string.

To do that you'll need an empty string big enough to hold the result, and then pass that and the integer to the cvs operator. So a PostScript fragment like this:

Pagedv      % The operand to convert to string
256 string  % A 256 element string to receive the result
            % stack is now - integer string
cvs         % consumes integer and string and returns a substring
            % stack is now - substring

So if you had a value of 1 for Pagedv then you would now have a PostScript string (1) of length 1.

If you've already defined your /concatstrings function, and are certain it will be available (ie in a dictionary on the dictionary stack and not concealed by another function of the same name) then you would just do:

(Tray-) exch concatstrings

Which would result in a string of (Tray-1). You might find it simpler to avoid calling a function and just do the whole thing at once locally.

Pagedv 256 string cvs         % convert integer to string
dup length 5 add string       % copy new string, get length, create final string big enough to hold Tray-result
                              % The above is probably overkill, very few printers have more than 9 trays! But best to be safe
dup 0 (Tray-) putinterval     % copy final string, put Tray- at start of final string
dup 5 4 -1 roll putinterval   % copy final string, put converted integer string into final result, starting at position 5.