home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m051 / 5.img / PROLOG.PS_ / PROLOG.bin
Encoding:
Text File  |  1992-05-15  |  54.9 KB  |  1,981 lines

  1. % -------------- POSTSCRIPT PROLOG FOR CORELDRAW 3.X ------
  2. % Copyright 1992 Corel Corporation.  All rights reserved.
  3.  
  4. /wCorelDict 300 dict def    % define our own dictionary
  5. wCorelDict begin                % everything is defined in our own dictionary
  6.  
  7. % -- general definition operators
  8. /bd {bind def} bind def
  9. /ld {load def} bd
  10. /xd {exch def} bd
  11. /_ null def                            % null object
  12.  
  13.  
  14. % ----- Global Color variables ---------
  15. % Current object's Fill color
  16. /$c 0 def         % Cyan component
  17. /$m 0 def        % Magenta component
  18. /$y 0 def        % yellow component
  19. /$k 0 def        % Black component
  20. /$t 1 def        % color Tint
  21. /$n _ def        % Color name(non-null for special colors only)
  22. /$o 0 def        % fill overprint flag
  23. /$fil 0 def        % current fill type: 0: solid, 1:pattern, 2: fountain, 3:PS-fill
  24.  
  25. /$bkg false def
  26.  
  27. % Current object's outline color
  28. /$C 0 def         % Cyan component
  29. /$M 0 def        % Magenta component
  30. /$Y 0 def        % yellow component
  31. /$K 0 def        % Black component
  32. /$T 1 def        % color Tint
  33. /$N _ def        % Color name(non-null for special colors only)
  34. /$O 0 def        % stroke overprint flag
  35. /$PF false def    % pattern stroke flag(0 no pattern, 1 pattern)
  36.  
  37. %--current transfo matrices--
  38. /$ctm matrix currentmatrix def    % initial general transfo matrix
  39. /$ptm matrix def                        % pen stroking matrix(defaults identity)
  40. /$ttm matrix def                        % text transfo matrix(Corel extensions)
  41. /$stm matrix def                        % "save" matrix in extended text(Corel extensions)
  42.  
  43. %--pattern parameters --
  44. % fill pattern:
  45. %/$pn () def                        % current fill pattern name
  46. %/$pm matrix def                % current pattern matrix
  47. %/$px 0 def                        % pattern x pos 
  48. %/$py 0 def                        % pattern y pos
  49. %/$pxf 0 def                        % pattern x offset 
  50. %/$pyf 0 def                        % pattern y offset
  51. %/$psx 10 def                     % current X shift between rows or tiles
  52. %/$psy 0 def                      % current Y shift between columns or tiles
  53. %/$pd [] def                        % current pattern description array
  54. %/$tx 0 def                        % current tile x pos 
  55. %/$ty 0 def                        % current tile y pos
  56.  
  57. %-- info about current path when painting the pattern    
  58. %/$llx 0 def                        % current path's bbox(used by patterns only)
  59. %/$lly 0 def                        % also used for each fountain stripes
  60. %/$urx 0 def
  61. %/$ury 0 def
  62.  
  63. %/Bbllx 0 def                    % current object's bbox(in absolute space)
  64. %/Bblly 0 def
  65. %/Bburx 0 def
  66. %/Bbury 0 def
  67.  
  68. %/$tllx 0 def                    % current OBJECT's bbox(in current Pattern space)
  69. %/$tlly 0 def
  70. %/$turx 0 def
  71. %/$tury 0 def
  72.  
  73. %-- Postscript fill variables
  74. %/$Psn null def                    % current PS-fill function name(literal)
  75. %/$Prm null def                    % current PS-fill parms(array of n params)
  76.  
  77. %-- fountain fill variables
  78. /$fst 128 def             % default # of steps in a fountain fill(can be redefined later)
  79. %/$fty 0 def             % current fountain type:0 linear, 1 radial
  80. %/$fan 0 def             % current fountain angle(if linear)
  81. /$pad 0 def                % edge pad around fountain (between 0 & 1.0)
  82. /$rox 0 def                % radial center x offset relative to bbox width
  83. /$roy 0 def                % radial center y offset relative to bbox height
  84.  
  85. %/$toc 0 def                    % TO anf FROM color components
  86. %/$tom 0 def
  87. %/$toy 0 def
  88. %/$tok 0 def
  89. %/$ton _ def                    % TO color name
  90. %/$tot    0 def                    % TO tint
  91. %/$frc 0 def
  92. %/$frm 0 def
  93. %/$fry 0 def
  94. %/$frk 0 def
  95. %/$frn _ def                    % FROM color name
  96. %/$frt    0 def                    % FROM tint
  97.  
  98. %/$dc 0 def                    % delta colors between fountain steps
  99. %/$dm 0 def 
  100. %/$dy 0 def
  101. %/$dk 0 def
  102.  
  103. % ---- Halftone screen support (black only)----------------------
  104. % NOTE: Unless modified later in the setup(generated code)section, the
  105. %           default halftone screens for fill & outline will be the    
  106. %          current device's setting.
  107. currentscreen             % establish document's default halftone screen
  108. /@dsp xd                    % default spot func
  109. /$dsp /@dsp def        % default spot func name
  110. /$dsa xd                    % default screen angle
  111. /$dsf xd                    % default screen frequency function
  112. %-- and other screen-related vars
  113. /$sdf    false def        % FLAG: non-default halftone screen for fill when true
  114. /$SDF    false def        % FLAG: non-defaul halftone screen for stroke when true
  115. %/$scp /$dsp def            % Current spot func for fill
  116. %/$sca $dsa def            % Current screen angle for fill
  117. %/$scf $dsf def            % Current screen frequency for fill
  118. %/$SCP /$dsp def            % Current spot func for stroke
  119. %/$SCA $dsa def            % Current screen angle for stroke
  120. %/$SCF $dsf def            % Current screen frequency for stroke
  121. /$Scra 0.0 def             % screen adjustment (-90 if printing landscape)
  122.  
  123. % ---- Internal operators ----------------------
  124. /$sv 0 def                % variable for save snapshots
  125. /@cp /closepath ld
  126. /@gs /gsave ld
  127. /@gr /grestore ld
  128. /@np /newpath ld
  129. /@sv {/$sv save def}bd
  130. /@rs {$sv restore}bd
  131. /@ss
  132. {
  133.     % Increment screen angle by $Scra which is 0 for portrait printing,
  134.     % -90 for landscape printing.
  135.  
  136.     exch $Scra add exch load setscreen
  137. } bd
  138.  
  139. %-- ERROR Handling  : Autoflatness for paths too complex
  140. % The next section is to avoid the limitcheck error of typesetters.
  141. % The painting operators of PostScript are rewritten to increase
  142. % flatness until either the object can be printed, or a flatness
  143. % of 10 more than the initial flatness setting has been reached.
  144. % In this case an error message is displayed and printing continues with
  145. % the next object.
  146.  
  147. % The auto-flatness will be enabled only if the value of the "AutoFlatness"
  148. % variable is true.  The code to set this variable is output by WALDO.
  149.  
  150. AutoFlatness
  151. {
  152.         % error message if path can really not be printed
  153.     /$cpx ([Error: PathTooComplex; OffendingCommand: AnyPaintingOperator]\n) def
  154.     %-- @cpx Path too complex error message function     - @cpx -
  155.     %%%%%%%%%/@err1 {$cpx print flush stop}bd % displays message and stops program
  156.  
  157.     /@err1 {$cpx print flush newpath} bd % displays message and stops program
  158.  
  159.     %-- @ifl Increase flatness             initial_flatness @ifl initial_flatness
  160.     /@ifl
  161.     {
  162.         dup currentflat exch sub 10 gt        % Is current flatness increase > 10?
  163.         {
  164.             @err1 exit
  165.         }
  166.         {
  167.             currentflat 2 add setflat
  168.         } ifelse
  169.     } bd 
  170.  
  171.     % --- Then redefine fill, eofill, clip, eoclip, & stroke
  172.     /@fill /fill ld
  173.     /fill
  174.     {
  175.         currentflat
  176.         {
  177.             {@fill}
  178.             stopped
  179.             {
  180.                 @ifl
  181.             }
  182.             {
  183.                 exit
  184.             } ifelse
  185.         } bind loop
  186.         setflat
  187.     } bd
  188.  
  189.     /@eofill /eofill ld
  190.     /eofill
  191.     {
  192.         currentflat
  193.         {
  194.             {@eofill}
  195.             stopped
  196.             {
  197.                 @ifl
  198.             }
  199.             {
  200.                 exit
  201.             } ifelse
  202.         } bind loop
  203.         setflat
  204.     } bd
  205.  
  206.     /@clip /clip ld
  207.     /clip
  208.     {
  209.         currentflat
  210.         {
  211.             {@clip}
  212.             stopped
  213.             {
  214.                 initclip @ifl
  215.             }
  216.             {
  217.                 exit
  218.             } ifelse
  219.         } bind loop
  220.         setflat
  221.     } bd
  222.  
  223.     /@eoclip /eoclip ld
  224.     /eoclip
  225.     {
  226.         currentflat
  227.         {
  228.             {@eoclip}
  229.             stopped
  230.             {
  231.                 initclip @ifl
  232.             }
  233.             {
  234.                 exit
  235.             } ifelse
  236.         } bind loop
  237.         setflat
  238.     } bd
  239.  
  240.     /@stroke /stroke ld
  241.     /stroke
  242.     {
  243.         currentflat
  244.         {
  245.             {@stroke}
  246.             stopped
  247.             {
  248.                 @ifl
  249.             }
  250.             {
  251.                 exit
  252.             } ifelse
  253.         } bind loop
  254.         setflat
  255.     } bd
  256. } if
  257.  
  258. /InRange
  259. { %def -- FORCE VALUE BETWEEN TWO LIMITS -- STACK: value minimum maximum
  260.     % if value not in range, modifies the value to be between min and max
  261.     3 -1 roll                                % get value on top
  262.     2 copy le {pop}{exch pop}ifelse    % val = min(val,MAXVAL)
  263.     2 copy ge {pop}{exch pop}ifelse    % val = max(val,MINVAL)
  264. } bd  % --- NEEDED by functions in USERPROC.TXT
  265.  
  266. /wDstChck
  267. { % RETURN THE MAXVALUE CHANGE OR UNCHANGE. MORE DOC. IN USERPROC.TXT FILE. 
  268.   2 1 roll dup 3 -1 roll
  269.   eq { 1 add } if
  270.  } bd    % --- NEEDED by functions in USERPROC.TXT
  271.  
  272. %-- @dot dot spot function      x y @dot num
  273. /@dot
  274. {    % implementation of a dot spot function for halftoning(see setscreen)
  275.     dup mul exch dup mul add 1 exch sub 2 div
  276. } bd
  277.  
  278. %-- @lin line spot function      x y @lin num
  279. /@lin
  280. {    % implementation of a line spot function for halftoning(see setscreen)
  281.     exch pop abs 1 exch sub
  282. } bd
  283.  
  284. %-- @MN    Minimum            val1 val2 @MN value
  285. /@MN
  286. {
  287.     2 copy le
  288.     {pop}
  289.     {exch pop} ifelse    % get minimum of both values
  290. } bd
  291.  
  292. % -- define the setcmykcolor operator if not already defined
  293. /setcmykcolor where    {pop}
  294. {
  295.     /setcmykcolor                     % cyan magenta yellow black setcmykcolor -
  296.     {
  297.         4 1 roll                        % send black below cyan
  298.         3 {3 index add 1 @MN 1 exch sub 3 1 roll} repeat    % convert to BLUE, GREEN and RED
  299.         setrgbcolor
  300.         pop                            % get rid of black
  301.   } bd
  302. } ifelse
  303.  
  304. /setoverprint                % boolean setoverprint
  305. {
  306.     /$op xd
  307. } bd
  308.  
  309.  
  310. /currentoverprint        % - currentoverprint boolean
  311. {
  312.     $op
  313. } bd
  314.  
  315. /setsepcolor                % greyvalue setsepcolor -
  316. {
  317.     1 exch sub setgray                % convert to ps gray
  318. } bd
  319.  
  320. /checksepcolor                % overprint greyvalue setsepcolor boolean
  321. {
  322.     1 exch sub dup setgray                % convert to ps gray
  323.  
  324.     % if white(1) and overprint(1), do not print at all (return false)
  325.     1 eq exch 1 eq and not
  326. } bd
  327.  
  328. /setprocesscolor        % cyan magenta yellow black setprocesscolor -
  329. {
  330.     ColorSeparationMode 0 eq        % Check if not performing color seps.
  331.     {
  332.         setcmykcolor
  333.     }
  334.     {
  335.         0 4 $ink sub index    % Fetch the relevant layer
  336.         exch pop                        % or zero for $ink == 4.
  337.                                                 % |- C M Y K greyvalue
  338.         5 1 roll 4 { pop } repeat        % |- greyvalue
  339.         setsepcolor
  340.     } ifelse
  341. } bd
  342.     
  343.     
  344. % -- define the findcmykcustomcolor operator if not already defined
  345. /findcmykcustomcolor    % cyan magenta yellow black name findcmykcustomcolor array
  346. {
  347.     5 array astore
  348. } bd
  349.  
  350. % -- define the setcustomcolor operator if not already defined
  351. % NOTE: We do not want to redefine this operator if it is defined so that
  352. %       other apps (e.g. Ventura Publisher) can separate our EPS files.
  353.  
  354. /setcustomcolor where    {pop}
  355. {
  356.     /setcustomcolor                     % array tint setcustomcolor -
  357.     {
  358.         ColorSeparationMode 0 eq    % Check if not performing color seps.
  359.         {
  360.             exch                                        % tint array
  361.             aload pop pop                        % |- tint cyan magenta yellow black
  362.             4
  363.             {
  364.                 4 index mul 4 1 roll    % Multiply colour by tint.
  365.             } repeat
  366.             5 -1 roll pop                        % |- cyan magenta yellow black
  367.             setcmykcolor
  368.         }
  369.         {
  370.             exch aload pop                    % |- tint cyan magenta yellow black name
  371.             CurrentInkName eq                % Check if this is the ink currently being separated.
  372.             {
  373.                 4 index                                % Fetch the tint.
  374.             }
  375.             {
  376.                 0                                            % No match, use 0.
  377.             } ifelse                                % |- tint cyan magenta yellow black greyvalue
  378.             6 1 roll
  379.             5 { pop } repeat                % |- greyvalue
  380.             setsepcolor
  381.         } ifelse
  382.     } bd
  383. } ifelse
  384.  
  385. % -- define the colorimage operator if not already defined
  386. % -- NOTE: We know we always call colorimage with ONE procedure
  387. % -- It should call the "image" operator instead
  388. % NOTE ####### Now , just skips the color info
  389. /colorimage where    {pop}
  390. {
  391.     /colorimage                         % wid hei bits matrix proc bool ncolors colorimage -
  392.     {
  393.         pop            % # of colors
  394.         pop            % BOOL always assumed false
  395.         pop            % data aquisition must be different
  396.         pop            % matrix not needed
  397.         pop            % # bits not needed
  398.  
  399.         {currentfile $dat readhexstring pop pop}        % read each row of data
  400.         repeat                                                % until all rows are read
  401.         pop                % clear the rest of the stack
  402.     } bd
  403. }ifelse
  404.  
  405.  
  406. %-- @tc tint color                cyan mag yel blk tint @tc cyan1 mag1 yel1 blk1 
  407. /@tc     % Tint current color (basically multiply 4 components with given tint)
  408. {
  409.     dup 1 ge                % see if tint >= 1
  410.     {pop}                % if it is, pop it
  411.     {                    % otherwise, multiply all 4 components
  412.         4
  413.         {
  414.             dup            % duplicate the tint
  415.             6 -1 roll    % get next component
  416.             mul            % multiply with current tint
  417.             exch            % tint back on top
  418.         } repeat
  419.         pop                % no need for tint anymore
  420.     } ifelse
  421. } bd
  422.  
  423. %-- @scc set current color        tint C M Y K name overprint @scc boolean
  424. /@scc        % -- set current color --
  425.     1 eq setoverprint            % Set overprint parameter.
  426.     dup _ eq                            % Check if process colour.
  427.     {
  428.         pop
  429.         setprocesscolor
  430.         pop
  431.     }
  432.     {                                            % Spot colour.
  433.         findcmykcustomcolor
  434.         exch
  435.         setcustomcolor
  436.     } ifelse
  437.  
  438.     ColorSeparationMode 0 eq    % If not doing color seps, ...
  439.     {
  440.         true
  441.     }
  442.     {
  443.         % if white(1) and overprint, do not print at all(return false)
  444.         currentgray 1 eq currentoverprint and not
  445.     } ifelse
  446. } bd
  447.  
  448. % -------------------- pattern support -----------------------
  449. %-- @sft    set first tile position  - @sft -
  450. /@sft                %set first tile position into $tx $ty (top left corners)
  451. {
  452. %    /$tx $tllx $pxf add dup $tllx gt {$pwid $psx add sub}if def    % first tile's x position(left)
  453. %    /$ty $tury $pyf sub dup $tury lt {$phei $psy add add}if def    % first tile's y position(top) 
  454.  
  455. % 3-Apr-91:KB:Adjusted position of starting tile to make PS Output match
  456. % preview and non-PS printers
  457.     /$tx $tllx $pxf add dup $tllx gt {$pwid sub}if def    % first tile's x position(left)
  458.     /$ty $tury $pyf sub dup $tury lt {$phei add}if def    % first tile's y position(top) 
  459. } bd
  460.  
  461. %-- @stb    set current bbox            - @stb -
  462. /@stb            % stores the current path's bbox into globals $llx,$lly, $urx, $ury
  463. {
  464.     pathbbox /$ury xd /$urx xd /$lly xd /$llx xd         % path's bbox
  465. } bd
  466.  
  467. %-- @ep Execute Pattern        array @ep -
  468. /@ep            % gets a pattern description from the stack and executes it
  469. {
  470.     {
  471.         cvx exec
  472.     } forall
  473. } bd
  474.  
  475. %/@ep            % gets a pattern description from the stack and executes it
  476. %{
  477. %    /$vc 0 def
  478. %    dup length /$vt xd
  479. %    {
  480. %        $vc $vt ge
  481. %        {
  482. %            exit
  483. %        }
  484. %        {
  485. %            dup $vc get
  486. %            cvx exec
  487. %            /$vc $vc 1 add def
  488. %        } ifelse
  489. %    } loop
  490. %    pop
  491. %} bd
  492.  
  493.  
  494. %-- @tp Tile pattern            xpos ypos @tp -
  495. /@tp    % creates a tile at specified position and plays the current
  496. {    % pattern into that tile
  497.       % first, make sure the tile woul be in the clipping path    
  498.     @sv                % save current settings
  499.     /$in true def
  500.     2 copy 
  501.     dup $lly le {/$in false def}if                % below current path?
  502.     $phei sub $ury ge {/$in false def}if        % above current path?
  503.     dup $urx ge {/$in false def}if                % right current path?
  504.     $pwid add $llx le {/$in false def}if        % left current path?
  505.     $in
  506.     {
  507.         @np
  508.         2 copy moveto 
  509.         $pwid 0 rlineto             % Create a rectangle clip box for the tile
  510.         0 $phei neg rlineto 
  511.         $pwid neg 0 rlineto 
  512.         0 $phei rlineto 
  513.         clip @np
  514.                         % translate pattern into new tile
  515.         $pn cvlit load aload pop     % get the current pattern
  516.         7 -1 roll                        % get x tile position on top
  517.         5 index sub                        % tile llx - pattern xpos
  518.         7 -1 roll                        % get the y tile pos on top
  519.         3 index sub                        % tile ury - pattern ypos
  520.         translate
  521.         /$ctm matrix currentmatrix def    % transfo matrix changed for that tile
  522.         @ep                                % execute the pattern description into that tile
  523.         pop pop pop pop
  524.     }
  525.     {pop pop}ifelse    % current tile not visible through current clipping path
  526.     @rs                                    % restore VM
  527. } bd
  528.  
  529. %-- @th Tile pattern    horizontally    - @th -
  530. /@th                % perform tiling when inter-tile shift is only in the x direction
  531. {
  532.     @sft                %set first tile position into $tx $ty
  533.     0 1 $tly 1 sub                        % compute each tile position(in $xp, $yp)
  534.     {    
  535.         dup $psx mul $tx add                    % X position of this row
  536.         {
  537.             dup $llx gt {$pwid sub}{exit}ifelse    % make sure first x is at the left boundary
  538.         } loop
  539.         exch $phei mul $ty exch sub         % first Y position in this row
  540.                                                     % stack: first X and Y in row
  541.         0 1 $tlx 1 sub
  542.         {
  543.             $pwid mul 
  544.             3 copy
  545.             3 -1 roll add exch                        % current tile position(x increased)
  546.             @tp                                    % create a tile and play the pattern into that tile
  547.             pop
  548.         } for
  549.         pop pop                                    % end of column 1
  550.     } for
  551. } bd
  552.  
  553. %-- @tv Tile pattern    vertically    - @tv -
  554. /@tv                % perform tiling when inter-tile shift is only in the y direction
  555. {
  556.     @sft                %set first tile position into $tx $ty
  557.     0 1 $tlx 1 sub                        % compute each tile position(in $xp, $yp)
  558.     {    
  559.         dup $pwid mul $tx add                    % X position of this column
  560.         exch $psy mul $ty exch sub                % first Y position in this column
  561.         {
  562.             dup $ury lt {$phei add}{exit}ifelse    % make sure first Y is at the top boundary
  563.         } loop
  564.                                                         % stack: top X and Y in column
  565.         0 1 $tly 1 sub
  566.         {
  567.             $phei mul 
  568.             3 copy sub                            % current tile position(y decreased)
  569.             @tp                                    % create a tile and play the pattern into that tile
  570.             pop
  571.         } for
  572.         pop pop                                    % end of column 1
  573.     } for
  574. } bd
  575.  
  576. %-- @pf Pattern fill    - @pf -
  577. /@pf        % fills the current path with the current fill pattern
  578. {
  579.     @gs
  580.     $ctm setmatrix           % reset normal ctm
  581.     $pm concat                % concatenate current pattern matrix
  582.     @stb                        % current path bbox(not object bbox)
  583.     @gs 
  584.         % fill background with white ; watch for colorseps % overprinting
  585.     $vectpat
  586.     {
  587.         1 0 0 0 0 _ $o @scc        % fill a white background
  588.         {
  589.             eofill
  590.         } if
  591.     }
  592.     {                                                % For bitmap fills, fill the background now
  593.                                                     % and not for each tile to avoid seams.
  594.         $t $c $m $y $k $n $o @scc
  595.         {
  596.             eofill
  597.             /$bkg true def
  598.         } if
  599.     } ifelse
  600.     @gr        
  601.     eoclip                     % current object shape is the clipping path
  602.     Bburx Bbury $pm itransform /$tury xd /$turx xd        % get object's bbox in transformed space
  603.     Bbllx Bblly $pm itransform /$tlly xd /$tllx xd        % get object's bbox in transformed space
  604.     /$wid $turx $tllx sub def        % current path width
  605.     /$hei $tury $tlly sub def        % current path height
  606.     $wid 0 gt $hei 0 gt and        % make sure current path bbox not NULL
  607.     {
  608.         $pn cvlit load aload pop         % get pattern parms on stack
  609.         /$pd xd                                % $pd = Current pattern description
  610.         3 -1 roll sub /$phei xd            % pattern width
  611.         exch sub /$pwid xd                % pattern height    
  612.         /$tlx $wid $pwid div ceiling 1 add def     %    # of tiles in the X direction
  613.         /$tly $hei $phei div ceiling 1 add def     %    # of tiles in the Y direction
  614.         $psx 0 eq                            % pattern x shift
  615.         {            
  616.             @tv                                % then tile vertically
  617.         }
  618.         {
  619.             @th                                % otherwise tile horizontally
  620.         } ifelse        
  621.     } if             % if pattern size not null
  622.  
  623.     @gr                        % restore initial graphic state
  624.     @np                        % clear the current path
  625.  
  626.     /$bkg false def
  627.  
  628. } bd
  629.  
  630. % --- fountain fill support ------------------
  631. %-- @dlt    compute deltas         - $dlt bprint -    
  632. /@dlt
  633. {                         % step 1 : get deltas between stripes into $dc $dm $dy $dk,
  634.                                  % # of steps in $fst
  635.                                  % also sets initial color values into $c $m $y $k
  636.                                  % returns bool: print or do not print
  637.     ColorSeparationMode 0 eq
  638.     {    % color separation is not active
  639.         /$dc $toc $tot mul $frc $frt mul dup /$c xd sub $fst 1 sub div def        % compute deltas  % original values
  640.         /$dm $tom $tot mul $frm $frt mul dup /$m xd sub $fst 1 sub div def
  641.         /$dy $toy $tot mul $fry $frt mul dup /$y xd sub $fst 1 sub div def
  642.         /$dk $tok $tot mul $frk $frt mul dup /$k xd sub $fst 1 sub div def
  643.         true
  644.     }
  645.     {    % color separation is active
  646.         $frt $frc $frm $fry $frk $frn $o @scc         % set gray to current FROM color 
  647.         dup
  648.         {        % store that gray value
  649.             /$frk 1 currentgray sub def
  650.         }
  651.         {
  652.             /$frk 0 def
  653.         } ifelse
  654.  
  655.         $tot $toc $tom $toy $tok $ton $o @scc        % set gray to current TO color
  656.         dup
  657.         {        % store that gray value
  658.             /$tok 1 currentgray sub def
  659.         }
  660.         {
  661.             /$tok 0 def
  662.         } ifelse
  663.         or            % leaves boolean on stack: True if either from or to colors are to be
  664.                     % printed        
  665.         dup
  666.         {        % if it is to be printed, compute deltas (in black plane only)
  667.             /$c 0 def /$m 0 def /$y 0 def /$k $frk def
  668.             /$dc 0 def /$dm 0 def /$dy 0 def 
  669.             /$dk $tok $frk sub $fst 1 sub div def        % delta gray between steps
  670.         } if        
  671.     }ifelse
  672. } bd
  673.  
  674.  
  675. %-- @ftl fountain fill linear            llx lly urx ury  @ftl -
  676. /@ftl        % generates linear fountain stripes to fill given bbox
  677. {        
  678.     1 index 4 index sub                             % Total width of bbox
  679.     dup $pad mul dup /$pdw xd                    % Store width of each pad in $pdw.
  680.  
  681.     % stack: llx lly urx ury bbox-width $pdw
  682.  
  683.     2 mul sub                                                % width of gradation
  684.     $fst div /$wid xd                                % width of each stripe
  685.     2 index sub /$hei xd                        % compute height
  686.     pop                                                         % stack: llx, lly
  687.     translate
  688.     $c $m $y $k             % starting color
  689.     
  690.     4 copy                                             % 4 colors on stack
  691.     ColorSeparationMode 0 ne                    % Doing color seps?
  692.         { 1 exch sub setgray pop pop pop}    % only use the gray component if so
  693.         {setcmykcolor}ifelse                        % otherwise, use them all
  694.     0 0 moveto 0 $hei lineto $pdw $hei lineto $pdw 0 lineto 0 0 lineto fill    % draw starting pad
  695.      $pdw 0 translate                                % next band position
  696.  
  697.     $fst                         % loop for each band
  698.     {
  699.         4 copy                 % 4 colors on stack
  700.         ColorSeparationMode 0 ne                    % Doing color seps?
  701.             { 1 exch sub setgray pop pop pop}    % only use the gray component if so
  702.             {setcmykcolor}ifelse                        % otherwise, use them all
  703.         0 0 moveto 0 $hei lineto $wid $hei lineto $wid 0 lineto 0 0 lineto fill    % draw band
  704.         $wid 0 translate            % next band position
  705.         $dk add 4 1 roll             % set colors for next band
  706.         $dy add 4 1 roll 
  707.         $dm add 4 1 roll 
  708.         $dc add 4 1 roll 
  709.     } repeat
  710.  
  711.     $dk sub 4 1 roll             % come back to last color for ending pad
  712.     $dy sub 4 1 roll 
  713.     $dm sub 4 1 roll 
  714.     $dc sub 4 1 roll 
  715.     ColorSeparationMode 0 ne                    % Doing color seps?
  716.         { 1 exch sub setgray pop pop pop}    % only use the gray component if so
  717.         {setcmykcolor}ifelse                        % otherwise, use them all
  718.     0 0 moveto 0 $hei lineto $pdw $hei lineto $pdw 0 lineto 0 0 lineto fill    % draw ending pad
  719. } bd
  720.  
  721. %-- @ftr fountain fill radial            llx lly urx ury  @ftr -
  722. /@ftr        % generates radial fountain stripes to fill given bbox
  723. {        
  724.      % get radius
  725.     1 index 4 index sub             % bbox width on stack
  726.     dup $rox mul /$row xd            % Store width of center offset in $row
  727.  
  728.     % stack: llx lly urx ury bbox-width
  729.  
  730.     2 div                                            % half bbox width 
  731.     1 index 4 index sub              % bbox height on stack
  732.  
  733.     % stack: llx lly urx ury bbox-width/2 bbox-height
  734.  
  735.     dup $roy mul /$roh xd            % Store height of center offset in $roh
  736.     2 div                                            % half bbox height 
  737.  
  738.     % stack: llx lly urx ury bbox-width/2 bbox-height/2
  739.  
  740.     2 copy dup mul exch dup mul add sqrt            % total radius on stack
  741.     $row dup mul $roh dup mul add sqrt add        % add offset to radius
  742.     
  743.     dup /$hei xd $fst div /$wid xd    % width of each band(delta radius)in $wid
  744.                                                                     % original radius in $hei
  745.                                                                     % on stack: llx lly urx ury w/2 h/2
  746.     4 index add    $roh add                    % y center with offset
  747.     exch
  748.     5 index add $row add                    % x center with offset
  749.     
  750.     exch translate                              % origin in center of bbox
  751.     pop pop pop pop                        % don't need bbox anymore
  752.  
  753.     currentflat dup 5 mul setflat             % no need for extra precision on fountain circles
  754.     $c $m $y $k             % starting color
  755.  
  756.     % Draw the background pad
  757.  
  758.     4 copy 
  759.     ColorSeparationMode 0 ne                    % Doing color seps?
  760.         { 1 exch sub setgray pop pop pop}    % only use the gray component if so
  761.         {setcmykcolor}ifelse                        % otherwise, use them all
  762.     $wid 0 moveto 0 0 $hei 0 360 arc fill    % draw circle at new center of bbox
  763.             % then scale according to the pad size
  764.     1.0 $pad 2 mul sub dup scale                    % scale around new center for pad
  765.     
  766.     $fst                         % loop for each band
  767.     {
  768.         4 copy 
  769.         ColorSeparationMode 0 ne                    % Doing color seps?
  770.             { 1 exch sub setgray pop pop pop}    % only use the gray component if so
  771.             {setcmykcolor}ifelse                        % otherwise, use them all
  772.         $wid 0 moveto 0 0 $hei 0 360 arc fill            % draw circle at new center of bbox
  773.         /$hei $hei $wid sub def        % next band radius in $hei
  774.         $dk add 4 1 roll                 % set colors for next band
  775.         $dy add 4 1 roll 
  776.         $dm add 4 1 roll 
  777.         $dc add 4 1 roll 
  778.     } repeat
  779.     pop pop pop pop     
  780.     setflat
  781. } bd
  782.  
  783. %-- @ff fountain fill current path    - @ff -
  784. /@ff
  785. {
  786.     @gs
  787.     @dlt                    % step 1 : get deltas between stripes into $dc $dm $dy $dk,
  788.                                 % # of steps in $fst
  789.                                 % also sets initial color values into $c $m $y $k
  790.                                 % puts a bool on the stack, same meaning as for @scc
  791.     {
  792.         $ctm setmatrix             % reset normal ctm
  793.         eoclip                     % current path is clipping path
  794.         newpath
  795.         Bbllx Bblly moveto    % compute size of box around current object
  796.         Bbllx Bbury lineto
  797.         Bburx Bbury lineto
  798.         Bburx Bblly lineto
  799.         $fan rotate
  800.         pathbbox
  801.         newpath
  802.  
  803.         $fty 1 eq            % fountain type ?
  804.         {@ftr}            % radial fountain
  805.         {@ftl} ifelse    % linear fountain
  806.     } if
  807.     @gr
  808.     @np
  809. } bd
  810.  
  811. %--@Pf Postscript Fill        - @Pf -
  812. /@Pf
  813. {    % Call user-defined Postscript fill with current parameters
  814.     @sv            % don't take chances, save current state
  815.                     % 20dec90:MB: Print PS fill only in composite
  816.                     %                     or in black plane of color seps.
  817.     ColorSeparationMode 0 eq  $ink 3 eq or
  818.     {            % PS fills can be printed
  819.         0 J 0 j [] 0 d                        % reset stroke attributes (all PS fills set line width)
  820.  
  821.         $t $c $m $y $k $n $o @scc    pop        % set colour
  822.  
  823.         $ctm setmatrix                        % reset matrix for PS-filling
  824.             % --- NOTE: All PS fills expect the current UNIT to be MIL (1/1000 inch)
  825.             % --- and Bburx, .. need to be specified in that unit as well.
  826.         72 1000 div dup matrix scale    % scaling matrix
  827.         dup concat                            % change current ctm
  828.         dup Bburx exch Bbury exch itransform 
  829.             ceiling cvi /Bbury xd 
  830.             ceiling cvi /Bburx xd        % change unit of BBox
  831.         Bbllx exch Bblly exch itransform 
  832.             floor cvi /Bblly xd 
  833.             floor cvi /Bbllx xd
  834.  
  835.         $Prm aload pop                        % Bring the parameters on stack
  836.         $Psn load exec                        % execute the ps fill as desired
  837.     }                
  838.     {            % Not proper color plane, fill in white instead.
  839.         1 setgray eofill
  840.     } ifelse
  841.     @rs                                    % restore original state
  842.     @np                                    % and clear the path
  843. } bd
  844.  
  845. % -------------------------------------------------------------------
  846. % -- painting attributes operators 
  847.  
  848. %-- g    Fill gray                gray g -            
  849. /g
  850. {
  851.     1 exch sub /$k xd                        % get black component
  852.     /$c 0 def /$m 0 def /$y 0 def /$t 1 def /$n _ def /$fil 0 def 
  853. } bd
  854.  
  855. %-- G    Stroke gray                gray G - 
  856. /G
  857. {
  858.     1 exch sub /$K xd                        % get black component
  859.     /$C 0 def /$M 0 def /$Y 0 def /$T 1 def /$N _ def    
  860. } bd
  861.  
  862. %-- k    Fill color                 cyan mag yel blk k -
  863. /k
  864. {
  865.     /$k xd /$y xd /$m xd /$c xd
  866.     /$t 1 def /$n _ def /$fil 0 def 
  867. } bd
  868.  
  869. %-- K    Stroke color            cyan mag yel blk K -
  870. /K
  871. {
  872.     /$K xd /$Y xd /$M xd /$C xd
  873.     /$T 1 def /$N _ def 
  874. } bd
  875.  
  876. %-- x    Fill custom color        cyan mag yel blk strname tint x -
  877. /x
  878. {
  879.     % Tint 0 is no ink; 1 is Full ink.
  880.     /$t xd /$n xd 
  881.     /$k xd /$y xd /$m xd /$c xd /$fil 0 def
  882. } bd
  883.  
  884. %-- X    Stroke custom color    cyan mag yel blk strname tint X -
  885. /X
  886. {
  887.     % Tint 0 is no ink; 1 is Full ink.
  888.     /$T xd /$N xd 
  889.     /$K xd /$Y xd /$M xd /$C xd
  890. } bd
  891.  
  892. %-- d    setdash                    array offset d -
  893. /d /setdash ld
  894.  
  895. %-- i    set current flat        flat    i -
  896. /i
  897. {
  898.     dup 0 ne {setflat} {pop} ifelse
  899. } bd
  900.  
  901. %-- j    set line join            join j -
  902. /j /setlinejoin ld
  903.  
  904. %-- J set line cap            cap J -
  905. /J /setlinecap ld
  906.  
  907. %-- M    set miter limit        value    M -
  908. /M /setmiterlimit ld
  909.  
  910. %-- w    set line width            width w -
  911. /w /setlinewidth ld
  912.  
  913. %-- O    set overprint fill    flag O -
  914. /O
  915. {
  916.     /$o xd
  917. } bd
  918.  
  919. %-- R    set overprint stroke    flag R -
  920. /R
  921. {
  922.     /$O xd
  923. } bd
  924.  
  925. %------------------------------------------------------------------------
  926. %-- path construction operators
  927.  
  928. %-- c    curveto smooth            x1 y1 x2 y2 x3 y3 c -
  929. /c /curveto ld
  930.  
  931. %-- C    curveto corner            x1 y1 x2 y2 x3 y3 C -
  932. /C /c ld
  933.  
  934. %-- v    curveto smooth            x12 y12 x3 y3 v -
  935. /v
  936. {
  937.     4 -2 roll                     % get x12 y12 on top
  938.     2 copy                        % duplicate them
  939.     6 -2 roll curveto            % move x3 y3 back to the end
  940. } bd
  941.  
  942. %-- V    curveto corner            x12 y12 x3 y3 V -
  943. /V /v ld
  944.  
  945. %-- y    curveto smooth            x1 y1 x23 y23 y -
  946. /y
  947. {
  948.     2 copy curveto                % duplicate last point 
  949. } bd
  950.  
  951. %-- Y    curveto corner            x1 y1 x23 y23 Y -
  952. /Y /y ld
  953.  
  954. %-- l    lineto smooth            x y l -
  955. /l /lineto ld
  956.  
  957. %-- L    lineto corner            x y L -
  958. /L /l ld
  959.  
  960. %-- rl rlineto                x y rl
  961. /rl /rlineto ld
  962.  
  963. %-- m    moveto                    x y m -
  964. /m /moveto ld
  965.  
  966.  
  967. %------------------------------------------------------------------------
  968. % -- Painting operators
  969.  
  970. %-- n    newpath                    - n -
  971. /n /newpath ld
  972.  
  973. %-- N    newpath                    - N -
  974. /N /newpath ld
  975.  
  976. %-- F    fill                        - F -
  977. /F
  978. {
  979.     matrix currentmatrix        % save current transfo matrix on stack
  980.     $sdf {$scf $sca $scp @ss} if        % alternate halftone screen?
  981.     $fil 1 eq
  982.     {@pf}                     % pattern fill
  983.     {                             % 
  984.         $fil 2 eq                % fountain fill?
  985.         {@ff}                    % fountain fill path
  986.         {
  987.             $fil 3 eq            % Postscript fill?
  988.             {@Pf}                % PS fill
  989.             {
  990.                 $t $c $m $y $k $n $o @scc                            % set FILL color, returns TRUE if we fill, FALSE if not
  991.                 {eofill}
  992.                 {@np} ifelse
  993.             } ifelse
  994.         } ifelse
  995.     } ifelse
  996.     $sdf {$dsf $dsa $dsp @ss} if        % reset default halftone screen
  997.     setmatrix                     % reset original transfo matrix on stack
  998. } bd
  999.  
  1000. %-- f    closepath fill            - f -
  1001. /f
  1002. {
  1003.     @cp F
  1004. } bd
  1005.  
  1006. %-- S    stroke                    - s -
  1007. /S
  1008. {
  1009.     matrix currentmatrix        % save current transfo matrix on stack
  1010.     $ctm setmatrix                 % reset normal ctm
  1011.     $SDF {$SCF $SCA $SCP @ss}if        % alternate halftone screen?
  1012.     $T $C $M $Y $K $N $O @scc                            % set current stroke color, returns TRUE if we paint, FALSE if not
  1013.     {
  1014.         matrix currentmatrix
  1015.         $ptm concat            % set the pen matrix
  1016.         stroke
  1017.         setmatrix                % reset the original matrix(from stack)
  1018.     }
  1019.     {@np}ifelse
  1020.     $SDF {$dsf $dsa $dsp @ss}if        % reset default halftone screen
  1021.     setmatrix                    % reset original matrix set on stack
  1022. } bd
  1023.  
  1024. %-- s    closepath stroke         - s -
  1025. /s
  1026. {
  1027.     @cp
  1028.     S
  1029. } bd
  1030.  
  1031. %-- B    fill, then stroke        - B -
  1032. /B
  1033. {
  1034.     @gs F    @gr                    % fill
  1035.     S                                % stroke
  1036. } bd
  1037.  
  1038. %-- b    closepath, fill, stroke    - b -
  1039. /b
  1040. {
  1041.     @cp B
  1042. } bd
  1043.  
  1044. %-- W    clip path                - W -
  1045. /W
  1046. {
  1047.     eoclip                 % clip to current path
  1048. } bd
  1049.  
  1050. %-- p    pattern fill            name xpos ypos xmag ymag angle reflect_flag 
  1051. %--                                reflect_angle skew_angle skew_imposed_angle 
  1052. %--                                matrix - p -
  1053. /p
  1054. {
  1055.     /$pm xd                        % current pattern matrix
  1056.     7 {pop} repeat                % get rid of undesired parms(not implemented)
  1057.     /$pyf xd /$pxf xd            % remember X Y original offests
  1058.     /$pn xd                        % remember pattern name    
  1059.     /$fil 1 def                    % set global for filling
  1060. } bd
  1061.  
  1062. %-- P    pattern stroke            (same as p)
  1063. /P
  1064. {                % NOT IMPLEMENTED
  1065.     11 {pop} repeat                % get rid of undesired parms(not implemented)
  1066. } bd            
  1067.  
  1068.  
  1069. %-------------------------------------------------------------------------
  1070.     % --- grouping information ---
  1071. %-- u    begin group                - u -
  1072. /u {} bd
  1073.  
  1074. %-- U    end group                - U -
  1075. /U {} bd
  1076.  
  1077. %-- A    locked object            flag A -
  1078. /A {pop} bd
  1079.  
  1080. %-- q    gsave                          - g -
  1081. /q /@gs ld
  1082.  
  1083. %-- Q    grestore                    - Q -
  1084. /Q /@gr ld
  1085.  
  1086.  
  1087. %--------------------------------------------------------------------
  1088. %--- pattern operators
  1089.  
  1090. %-- E    define pattern            name llx lly urx ury description E -
  1091. % a pattern will be defined as an array of 5 entries:
  1092. %     (0)llx (1)lly (2)urx (3)ury (4)descrition
  1093. % the description is also an array of executable strings
  1094. /E
  1095. {
  1096.     5 array astore              % -- parms are in an array
  1097.     exch cvlit exch def        % -- defined with key equal to the name(string)
  1098. } bd
  1099.  
  1100. %-- `    place marker            - ` -
  1101. /` {}bd
  1102.  
  1103. %-- ~    end place                - ~ -
  1104. /~ {}bd
  1105.     
  1106. %-- @    pattern marker            - @ -    
  1107. /@ {}bd
  1108.  
  1109. %-- &    pattern marker            - & -    
  1110. /& {}bd
  1111.  
  1112. % ------------------------------------------------------------------------
  1113. % -- CORELDRAW 2.X re-encoding vector for characters above 128
  1114. /CorelDrawReencodeVect [
  1115. 16#80/grave/circumflex/tilde/dotlessi/florin/quotedblleft/quotedblright/guilsinglleft
  1116. 16#88/guilsinglright/fi/fl/dagger/daggerdbl/endash/periodcentered/breve
  1117. 16#90/quotedblbase/ellipsis/perthousand/trademark/Pt/fractionbar
  1118. 16#98/divide
  1119. 16#a1/exclamdown/cent/sterling/currency/yen/bar/section
  1120. 16#a8/dieresis/copyright/ordfeminine/guillemotleft/logicalnot/emdash/registered/overbar
  1121. 16#b0/ring/plusminus/twosuperior/threesuperior/acute/mu/paragraph/bullet
  1122. 16#b8/cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown
  1123. 16#c0/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
  1124. 16#c8/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis
  1125. 16#d0/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/OE  
  1126. 16#d8/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
  1127. 16#e0/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
  1128. 16#e8/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
  1129. 16#f0/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/oe
  1130. 16#f8/oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis
  1131. ] def
  1132.  
  1133. % -- @cc    collect bitmap data        - @cc string
  1134. % -- NOTE: Can be temporarily redefined by @N operator
  1135. /@cc
  1136. {    % collect bitmap information from current file (used by @C)
  1137.     currentfile $dat readhexstring pop
  1138. } bd
  1139.  
  1140. % --------------------------- COREL EXTENSIONS ---------------------
  1141. % --Definitions of COREL extensions to the official AI language
  1142. % --All operators start with a @ followed by ONE letter.
  1143.  
  1144. %-- @sm save currentmatrix         - @sm -
  1145. /@sm        % save current transfo matrix into global $ctm
  1146. {    
  1147.     /$ctm $ctm currentmatrix def
  1148. } bd
  1149.  
  1150. %-- @E Define Object's bbox   bbllx bblly bburx bbury matrix @E -
  1151. /@E
  1152. {    % must be called before painting if PATTERNS, PSFILLS, or FOUNTAINS are used
  1153.     /Bbury xd /Bburx xd         % upper right of OBJECT's bbox in absolute space
  1154.     /Bblly xd /Bbllx xd        % lower left of OBJECT's bbox in absolute space
  1155. } bd
  1156.  
  1157. %-- @c Close sub Path
  1158. /@c
  1159. {    % must be called during the path description
  1160.     @cp
  1161. } bd
  1162.  
  1163. %-- @p COREL Tiled pattern fill      name xoffset yoffset xshift yshift matrix pattern_type @p -
  1164. /@p
  1165. {
  1166.     /$fil 1 def                    % set global for pattern filling
  1167.     1 eq /$vectpat xd        % pattern type: 0 - bitmap, 1 - vector
  1168.     /$pm xd                            % current pattern matrix
  1169.     /$psy xd                       % current Y shift before transformation(x & y exclusives)
  1170.     /$psx xd                      % current X shift before transformation(x & y exclusives)
  1171.     /$pyf xd /$pxf xd        % remember X Y original offests (before transformation)
  1172.     /$pn xd                            % remember pattern name    
  1173. } bd
  1174.  
  1175. %-- @P COREL Postscript Fill     parm1 .. parmn n fillname @P -
  1176. /@P
  1177. {     % COREL Postscript fill # of parms can vary 
  1178.     /$fil 3 def                % set global for filling
  1179.     /$Psn xd                    % PS-fill name
  1180.     array astore            % build array for PS-fill parms
  1181.     /$Prm xd                    % parms in Prm
  1182. } bd
  1183.  
  1184. %-- @k Fountain fill CMYK-CMYK    cy ma ye bl cy ma ye bl angle type pad xoff yoff @k -
  1185. /@k
  1186. {        % specifies that the next object will be filled with a fountain
  1187.             % angle is in degrees , "type" is a flag (0 = linear, 1 radial)
  1188.             % pad is the amount of padding to be set around edges( between 0 and 1.0 )
  1189.             % xoff & yoff indicate the radial center offset (relative to bbox size (-1 to 1))
  1190.     /$fil 2 def                % set global for filling
  1191.     /$roy xd /$rox xd /$pad xd
  1192.     /$fty    xd /$fan    xd
  1193.     $fty 1 eq {/$fan 0 def}if        % if radial fill, force angle to 0
  1194.     /$tok xd /$toy xd /$tom    xd /$toc xd
  1195.     /$frk xd /$fry xd /$frm xd /$frc xd
  1196.     /$frn _ def /$frt    1 def /$ton _ def /$tot    1 def
  1197. } bd
  1198.  
  1199. %-- @x Fountain fill custom-custom    cy ma ye bl name tint cy ma ye bl name tint angle type pad xoff yoff @x -
  1200. /@x
  1201. {        % specifies that the next object will be filled with a fountain
  1202.             % angle is in degrees , "type" is a flag (0 = linear, 1 radial)
  1203.             % pad is the amount of padding to be set around edges( between 0 and 1.0 )
  1204.             % xoff & yoff indicate the radial center offset (relative to bbox size (-1 to 1))
  1205.             % Tint 0 is no ink; 1 is Full ink.
  1206.     /$fil 2 def                % set global for filling
  1207.     /$roy xd /$rox xd /$pad xd
  1208.     /$fty    xd /$fan    xd
  1209.     /$tot    xd /$ton xd /$tok xd /$toy xd /$tom    xd /$toc xd
  1210.     /$frt    xd /$frn xd /$frk xd /$fry xd /$frm xd /$frc xd
  1211. } bd
  1212.  
  1213.  
  1214. %-- @ii image preparation         llx lly urx ury matrix @ii -
  1215. /@ii
  1216. {         % common bitmap code
  1217.     concat                    % integrate transo right away
  1218.     3 index 3 index m        % set clipping path(cropping rect)
  1219.     3 index 1 index l 
  1220.     2 copy l 
  1221.     1 index 3 index l
  1222.     3 index 3 index l
  1223.     clip                        % this is the clipping path
  1224.     pop pop pop pop        % pop cropping rect
  1225. } bd
  1226.  
  1227. % -- @i Gray/Mono bitmap        pxlwid pxlhei bits llx lly urx ury 
  1228. %                                        background foreground
  1229. %                                        cropllx croplly cropurx cropury 
  1230. %                                        matrix @i -
  1231. /@i    % gray/mono bitmap image
  1232.         % parms: pxlwid pxlhei : size of bitmap in pixels 
  1233.         %            bits : # of bits per sample
  1234.         %            llx lly urx ury : total size of bitmap(before transfos)
  1235.         %            background:    flag: 1: fill background with current fill attributes, 0: transparent background
  1236.         %            foreground:    flag: 1: mask foreground with current stroke attributes, 0: transparent foreground
  1237.         %            cropllx croplly cropurx cropury: cropping rectangle(before transfos)
  1238.         %            matrix: additional transfo matrix for stretching/rotating, etc..
  1239.         %    NOTE:    height can be negative if it comes from @N operator, in such a
  1240.         %            case, it must be printed upside down.
  1241. {
  1242.     @sm @gs                    % save current ctm and graphics state
  1243.     @ii                        % get common parameters
  1244.  
  1245.     % stack: pxlwid pxlhei bits llx lly urx ury background_flag foreground_flag
  1246.  
  1247.     6 index 1 ne                                            % grayscale bitmap
  1248.     {
  1249.         /$frg true def
  1250.         pop pop
  1251.     }
  1252.     {                                                                    % monochrome bitmap
  1253.         % When doing colour seps of a monochrome bitmap, if the background is
  1254.         % printed, then print the foreground also.
  1255.  
  1256.         1 eq                                                        % Check if foreground flag is set.
  1257.         {
  1258.             $T $C $M $Y $K $N $O @scc            % Set foreground color.
  1259.             /$frg xd
  1260.         }
  1261.         {
  1262.             /$frg false def
  1263.         } ifelse
  1264.  
  1265.         1 eq                                                        % Check if background flag is set.
  1266.         {
  1267.             @gs $ctm setmatrix
  1268.             $t $c $m $y $k $n $o @scc            % Check if background to be filled.
  1269.             {
  1270.                 eofill                                            % If bitmap to be painted, fill background.
  1271.             } if
  1272.             @gr
  1273.         } if
  1274.     } ifelse
  1275.  
  1276.     % If the background of a bitmap fill was painted in "@pf", always paint
  1277.     % the foreground.
  1278.  
  1279.     /$frg $frg $bkg or def
  1280.  
  1281.     @np                        % no path but clipping
  1282.  
  1283.     % stack: pxlwid pxlhei bits llx lly urx ury
  1284.  
  1285.     /$ury xd /$urx xd /$lly xd /$llx xd        % bitmap rectangle
  1286.     /$bts xd                                            % # of bits per sample
  1287.     /$hei xd /$wid xd                                % pixel size
  1288.  
  1289.     /$dat $wid $bts mul 8 div ceiling cvi string def                % string for data entry (each scan line)
  1290.  
  1291.     $frg                        % foreground to be printed?
  1292.     {
  1293.         $SDF {$SCF $SCA $SCP @ss}if        % alternate halftone screen? (determined by stroke attribs)
  1294.             % set params for the imagemask/image operator
  1295.         $llx $lly translate
  1296.         $urx $llx sub $ury $lly sub scale
  1297.         $wid $hei abs                                % if height is negative, print it upside down
  1298.         $bts 1 eq {false}{$bts}ifelse            % either false or #bits/sample 
  1299.         [ $wid 0 0 
  1300.           $hei neg 0 
  1301.           $hei 0 gt{$hei}{0}ifelse]     % matrix(upside down if $hei is negative)
  1302.         /@cc load                              %    @cc can be redefined by @N 
  1303.         $bts 1 eq {imagemask}{image}ifelse
  1304.         $SDF {$dsf $dsa $dsp @ss}if        % reset default halftone screen
  1305.     }
  1306.     {
  1307.         $hei abs {@cc pop} repeat            % skip all lines
  1308.     } ifelse        % in color seps, the foreground might not be printed
  1309.  
  1310.     @gr $ctm setmatrix                     % Restore graphics state & org matrix
  1311.  
  1312. } def      % not bd because @cc can be redefined by @N
  1313.  
  1314. %-- @M Short Bitmap data starts        - @M -
  1315. /@M
  1316. {    % called prior to defining a bitmap pattern/bitmap in vector pattern.
  1317.             % Immediately following this call, there are a sequence of binary
  1318.             % strings defining the bitmap data that will be put on the stack.
  1319.     @sv    % Save VM so that the space occupied by the string(s) is
  1320.             % freed at the end of @N (which performs a restore).
  1321.             % the @N operator must be called to free the stack from all those 
  1322.             % strings and to print the bitmap
  1323.             % BITMAP DATA MUST FIT IN 64K
  1324. }bd
  1325.  
  1326. %-- @N Short bitmap pattern or bitmap in a vector pattern.
  1327. %                string1 string2 ... stringn
  1328. %
  1329. %                pxlwid pxlhei bits llx lly urx ury background foreground
  1330. %                cropllx croplly cropurx cropury matrix 1 @N -
  1331. %
  1332. %                                        or
  1333. %
  1334. %                pxlwid pxlhei bits ncolors llx lly urx ury
  1335. %                cropllx croplly cropurx cropury matrix 0 @N -
  1336. %
  1337. /@N % parms: pxlwid pxlhei : size of bitmap in pixels
  1338.         %            bits : # of bits per sample
  1339.         %            ncolors : number of colors (if color bitmap)
  1340.         %            llx lly urx ury : total size of bitmap(before transfos)
  1341.         %            background:    flag: 1: fill background with current fill attributes, 0: transparent background
  1342.         %                (only for monochrome/grayscale bitmaps)
  1343.         %            foreground:    flag: 1: mask background with current stroke attributes, 0: transparent background
  1344.         %                (only for monochrome/grayscale bitmaps)
  1345.         %            cropllx croplly cropurx cropury: cropping rectangle(before transfos)
  1346.         %            matrix: additional transfo matrix for stretching/rotating, etc..
  1347.         %    NOTE:    height can be negative if it comes from @N operator, in such a
  1348.         %            case, it must be printed upside down.
  1349. {
  1350.     /@cc {} def
  1351.  
  1352.     % Make the bitmap pxl height negative, so that @i/@I knows that the data
  1353.     % is upside down.
  1354.  
  1355.     1 eq
  1356.     {
  1357.         12 -1 roll neg 12 1 roll    % height negative
  1358.         @I
  1359.     }
  1360.     {
  1361.         13 -1 roll neg 13 1 roll    % height negative
  1362.         @i
  1363.     } ifelse
  1364.     @rs
  1365. } bd
  1366.  
  1367. % -- @I Color bitmap                pxlwid pxlhei bits ncolors 
  1368. %                                        llx lly urx ury 
  1369. %                                        cropllx croplly cropurx cropury 
  1370. %                                        matrix @I -
  1371. /@I    % Color bitmap image
  1372.         % parms: pxlwid pxlhei : size of bitmap in pixels
  1373.         %            bits : # of bits per color component(24-bits color is 8 bits per component)
  1374.         %            ncolors: # of color components(RGB=3, CMYK=4)
  1375.         %            llx lly urx ury : total size of bitmap(before transfos)
  1376.         %            cropllx croplly cropurx cropury: cropping rectangle(before transfos)
  1377.         %            matrix: additional transfo matrix for stretching/rotating, etc..
  1378. {
  1379.     @sm @gs                     % save current ctm and graphics state
  1380.     @ii                        % get common parameters
  1381.     @np                        % no path but clipping
  1382.  
  1383.     % stack: pxlwid pxlhei bits ncolors llx lly urx ury
  1384.  
  1385.     /$ury xd /$urx xd /$lly xd /$llx xd        % bitmap rectangle
  1386.     /$ncl xd                                            % # of color components
  1387.     /$bts xd                                            % # of bits per color component
  1388.     /$hei xd /$wid xd                                % pixel size
  1389.     /$dat $wid $bts mul $ncl mul 8 div ceiling cvi string def    % string for data entry (each scan line)
  1390.  
  1391.     % set params for the colorimage operator
  1392.  
  1393.     $llx $lly translate
  1394.     $urx $llx sub $ury $lly sub scale        % set current scale for bitmap size
  1395.     $wid $hei abs                                        % parms for colorimage
  1396.     $bts 
  1397.     [ $wid 0 0 
  1398.       $hei neg 0  
  1399.       $hei 0 gt{$hei}{0}ifelse]     % matrix(upside down if $hei is negative)
  1400.     /@cc load     
  1401.     false $ncl
  1402.     colorimage                                        % colorimage redefined.
  1403.     @gr $ctm setmatrix                               % restore graphics state & original matrix
  1404. } bd
  1405.  
  1406. % -------------------- text support ----------------------------
  1407. %--------------------------------------------------------------------
  1408.     % -- text/font manipulation
  1409. %-- z    findfont                    fontname size z -
  1410. /z
  1411. {        % sets current font, ptsize
  1412.     exch findfont exch scalefont setfont        % set the current font
  1413. } bd
  1414.  
  1415. %-- ZB define raster font
  1416. /ZB         % fontname default_metrics_entry FontBBox FontMatrix ZB
  1417. {
  1418.     9 dict
  1419.  
  1420.     % stack: fontname default_metrics_entry FontBBox FontMatrix fontdict
  1421.  
  1422.     dup begin
  1423.  
  1424.     4 1 roll
  1425.  
  1426.     % stack: fontname fontdict default_metrics_entry FontBBox FontMatrix
  1427.  
  1428.     /FontType 3 def
  1429.     /FontMatrix xd
  1430.     /FontBBox xd
  1431.  
  1432.     % stack: fontname fontdict default_metrics_entry
  1433.  
  1434.     /Encoding 256 array def
  1435.     0 1 255
  1436.     {
  1437.         Encoding exch /.notdef put
  1438.     } for
  1439.  
  1440.     /CharStrings 256 dict def
  1441.     CharStrings /.notdef {} put
  1442.  
  1443.     /Metrics 256 dict def
  1444.  
  1445.     % stack: fontname fontdict default_metrics_entry
  1446.  
  1447.     Metrics /.notdef 3 -1 roll put
  1448.  
  1449.     % stack: fontname fontdict
  1450.  
  1451.     /BuildChar
  1452.     {
  1453.         % stack: font char
  1454.         exch
  1455.  
  1456.         % stack: char font
  1457.  
  1458.         dup /$char exch /Encoding get 3 index get def        % Get character name.
  1459.  
  1460.         % stack: char font
  1461.  
  1462.         % Get origin of next char relative to current char and bounding box
  1463.         % for current char and call setcachedevice.
  1464.  
  1465.         dup /Metrics get $char get aload pop setcachedevice
  1466.  
  1467.         begin
  1468.         Encoding exch get CharStrings exch get
  1469.         end
  1470.         exec
  1471.     } def
  1472.     end
  1473.  
  1474.     % stack: fontname fontdict
  1475.  
  1476.     definefont pop
  1477. } bd
  1478.  
  1479. /ZBAddChar    % metrics_entry char_proc char_code char_name fontname ZBAddChar
  1480. {
  1481.     findfont begin
  1482.  
  1483.     % stack: metrics_entry char_proc char_code char_name
  1484.  
  1485.     dup 4 1 roll dup 6 1 roll
  1486.  
  1487.     % stack: char_name metrics_entry char_name char_proc char_code char_name
  1488.  
  1489.     Encoding 3 1 roll put
  1490.  
  1491.     % stack: char_name metrics_entry char_name char_proc
  1492.  
  1493.     CharStrings 3 1 roll put
  1494.  
  1495.     % stack: char_name metrics_entry
  1496.  
  1497.     Metrics 3 1 roll put
  1498.     end
  1499. } bd
  1500.  
  1501. %-- Z    re-encode font            width-array encode-array newfontname fontname Z -
  1502. /Z
  1503. {
  1504.     % get font dictionary on stack
  1505.  
  1506.     findfont    
  1507.     dup maxlength 2 add dict exch        % get its size    & create new font dictionary
  1508.     % on stack: width-array encode-array newfontname new-dict old-dict
  1509.     
  1510.     % -- copy all entries from the old dict to the new dict
  1511.     dup    
  1512.     {
  1513.         1 index /FID ne                % avoid copying the FID key
  1514.         {                  
  1515.             3 index             % stack: ... newdict olddict key value newdict
  1516.             3 1 roll put    % store entry in dict
  1517.         }                
  1518.         {
  1519.             pop pop
  1520.         } ifelse
  1521.     } forall             % for all entries in the old dict
  1522.     
  1523.     % Now, get the new encoding array into the new dictionary
  1524.     % stack: width-array encode-array  newfontname new-dict old-dict
  1525.  
  1526.     pop                        % don't need old dict anymore    
  1527.  
  1528.     dup dup /Encoding get
  1529.  
  1530.     % stack: width-array encode-array newfontname newdict newdict Encoding
  1531.  
  1532.     256 array copy                % get a copy of original encoding array (to modify)
  1533.     dup /$fe xd                        % prepare a pointer to the dest Encoding array
  1534.     /Encoding exch put        % store copy of original in encoding vect
  1535.  
  1536.     % stack: width-array encode-array  newfontname new-dict
  1537.  
  1538.     dup /Fontname 3 index put    % store it's own new name in that font
  1539.  
  1540.     % stack: width-array encode-array  newfontname new-dict
  1541.  
  1542.     % store the new encoding array into the copy
  1543.  
  1544.     3 -1 roll        % |- width-array newname newdict encode-array
  1545.     dup length 0 ne
  1546.     {
  1547.         0 exch 
  1548.         {    % the array has either numbers or names; initialize counter
  1549.             dup type 0 type eq    % check for numbers
  1550.             {
  1551.                 exch pop            % throw the old number away
  1552.             }
  1553.             {                        % else, must be a char name
  1554.                 $fe exch 2 index exch put    % put it into array
  1555.                 1 add                    % get ready for next
  1556.             } ifelse
  1557.         } forall
  1558.         pop                % remove counter
  1559.     } if
  1560.  
  1561.     % stack: width-array newname newfontdict
  1562.  
  1563.     dup 256 dict
  1564.  
  1565.     %stack: width-array newname newfontdict newfontdict metricsdict
  1566.  
  1567.     dup /$met xd                % prepare a pointer to the dest Metrics dict
  1568.  
  1569.     /Metrics exch put
  1570.  
  1571.     %stack: width-array newname newfontdict
  1572.  
  1573.     % Character widths in width-array are for a 1000 unit character coordinate
  1574.     % system.  If this is not the coordinate system used for this font, the
  1575.     % character widths have to be scaled appropriately.  This scale factor
  1576.     % is being calculated here.
  1577.  
  1578.     dup /FontMatrix get
  1579.     0 get
  1580.     1000 mul
  1581.     1 exch div
  1582.  
  1583.     %stack: width-array newname newfontdict scale-factor
  1584.  
  1585.     % Add character widths in width-array to the font if width-array contains
  1586.     % 256 entries.
  1587.  
  1588.     3 index length 256 eq
  1589.     {
  1590.         0 1 255
  1591.         {
  1592.             %stack: width-array newname newfontdict scale-factor index
  1593.  
  1594.             dup $fe exch get
  1595.  
  1596.             %stack: width-array newname newfontdict scale-factor index char
  1597.  
  1598.             dup /.notdef eq
  1599.             {
  1600.                 pop pop
  1601.             }
  1602.             {
  1603.                 %stack: width-array newname newfontdict scale-factor index char
  1604.  
  1605.                 5 index
  1606.  
  1607.                 3 -1 roll get
  1608.  
  1609.                 % stack: width-array newname newfontdict scale-factor char char-width
  1610.  
  1611.                 2 index mul
  1612.  
  1613.                 $met 3 1 roll put
  1614.             } ifelse
  1615.         } for
  1616.     }    if
  1617.  
  1618.     pop
  1619.  
  1620.     %stack: width-array newname newfontdict
  1621.  
  1622.     definefont pop        % then, record that new font in the font list
  1623.  
  1624.     %stack: width-array
  1625.  
  1626.     pop
  1627.  
  1628. } bd
  1629.     
  1630. %-- @ftx Text fill(special)    string @ftx -
  1631. /@ftx     % fill text with pattern or fountain
  1632. {
  1633.     {        % loop for each character in the string
  1634.         (0) dup 3 -1 roll 0 exch put        % convert integer into a string
  1635.         @gs
  1636.         true charpath                         % get character outline in path
  1637.         $ctm setmatrix                        % set matrix for pattern filling
  1638.         @@txt                                            % pattern fill or fountain fill
  1639.         @gr
  1640.         @np
  1641.     } forall
  1642. } bd
  1643.  
  1644.  
  1645. %--@ft    fill text object        string @ft -
  1646. /@ft            % fill current text object
  1647. {
  1648.     matrix currentmatrix exch            % save current transfo matrix on stack
  1649.     $sdf {$scf $sca $scp @ss} if    % alternate halftone screen?
  1650.     $fil 1 eq                                     % pattern fill?
  1651.     {/@@txt /@pf ld @ftx}         % pattern fill on text
  1652.     {
  1653.         $fil 2 eq                                % fountain fill?
  1654.         {/@@txt /@ff ld @ftx}        % fountain fill on text
  1655.         {
  1656.             $fil 3 eq                            % Postscript fill?
  1657.             {/@@txt /@Pf ld @ftx}    % PS fill on text
  1658.             {
  1659.                 $t $c $m $y $k $n $o @scc                    % set FILL color, returns TRUE if we fill, FALSE if not
  1660.                 {show}                                                        % show text
  1661.                 {pop} ifelse
  1662.             } ifelse
  1663.         } ifelse
  1664.     } ifelse                        
  1665.     $sdf {$dsf $dsa $dsp @ss} if        % reset default halftone screen
  1666.     setmatrix                                             % reset original transfo matrix on stack
  1667. } bd
  1668.  
  1669. %--@st    stroke text object        string @st -
  1670. /@st            % stroke current text object
  1671. {
  1672.     matrix currentmatrix exch                    % save current transfo matrix on stack
  1673.     $SDF {$SCF $SCA $SCP @ss} if            % alternate halftone screen?
  1674.     $T $C $M $Y $K $N $O @scc                    % set STROKE color, returns TRUE if we stroke, FALSE if not
  1675.     {    
  1676.         {        % loop for each character in the string
  1677.             (0) dup 3 -1 roll 0 exch put    % convert integer into a string
  1678.             @gs
  1679.             true charpath                                 % get character outline in path
  1680.             $ctm setmatrix $ptm concat        % set matrix for stroking
  1681.             stroke                                                % stroke it
  1682.             @gr
  1683.         } forall
  1684.     }
  1685.     {pop} ifelse        % @scc
  1686.     $SDF {$dsf $dsa $dsp @ss} if        % reset default halftone screen
  1687.     setmatrix                                 % reset original transfo matrix on stack
  1688. } bd
  1689.  
  1690. %--@te    print filled text     string @te -
  1691. /@te        % prints text as filled only    
  1692. {
  1693.     @ft                        % fill that text
  1694. } bd
  1695.  
  1696. %--@tr    print stroked text     string @tr -
  1697. /@tr        % prints text as stroked only    
  1698. {
  1699.     @st                        % stroke that text
  1700. } bd
  1701.  
  1702. %--@ta    fill & stroke text      string @ta -
  1703. /@ta        % prints text as filled & stroked
  1704. {
  1705.     dup
  1706.     @gs @ft @gr                % fill the text
  1707.     @st                        % then stroke text
  1708. } bd
  1709.  
  1710. %--@t@a    stroke & fill text      string @t@a -
  1711. /@t@a        % prints text as stroked & filled 
  1712. {
  1713.     dup
  1714.     @gs @st @gr                % stroke the text
  1715.     @ft                         % then fill text
  1716. } bd
  1717.  
  1718. %-- @tm set text matrix            matrix @tm -
  1719. /@tm
  1720. {
  1721.     % Create a VM snapshot to be restored when the text object processing
  1722.     % is finished (See the T operator).  This allows memory consumed for
  1723.     % strings and matrices during processing of the text object to be freed.
  1724.  
  1725.     /$textsave save def
  1726.  
  1727.     @sm                % save current matrix
  1728.     concat
  1729. } bd
  1730.  
  1731. %-- e    filled text                - e -
  1732. /e
  1733. {
  1734.     /t {@te} def            % define operator t as @te
  1735. } bd
  1736.  
  1737. %-- r    stroked text            - r -
  1738. /r
  1739. {
  1740.     /t {@tr} def            % define operator t as @tr
  1741. } bd
  1742.  
  1743. %-- o    invisible text          - o -
  1744. /o
  1745. {
  1746.     /t {pop} def            % define operator t as nothing
  1747. } bd
  1748.  
  1749. %-- a    fill&stroke text        - a -
  1750. /a
  1751. {
  1752.     /t {@ta} def            % define operator t as @ta
  1753. } bd
  1754.  
  1755.  
  1756. %-- @a stroke&fill text        - @a -
  1757. %--@a 
  1758. /@a
  1759. {
  1760.     /t {@t@a} def            % define operator t as @t@a
  1761. } bd
  1762.  
  1763. %-- t    text body                string t -
  1764. /t {@te} def            % default value: will be redefined by a,e,o,r, and I
  1765.  
  1766. %-- T    end text (restore)        - T -
  1767. /T
  1768. {
  1769.     @np                                % Clear path.
  1770.     $ctm setmatrix        % Reset current matrix.
  1771.     /$ttm matrix def    % Reset extended text matrix.
  1772.  
  1773.     % Restore VM snapshot.
  1774.  
  1775.     $textsave restore
  1776. } bd
  1777.  
  1778.  
  1779. %-- @t 1-character text        xpos ypos string  @t -
  1780. /@t            % -- paints a 1-character string at desired position
  1781. {
  1782.     /$stm $stm currentmatrix def    % save current matrix
  1783.     3 1 roll                                            % send string to bottom
  1784.     moveto                                                % move to character position
  1785.     $ttm concat                                        % add text matrix
  1786.     t                                                          % draw the character (current t operator)
  1787.     $stm setmatrix                                % restore saved matrix
  1788. } def    % NO "bind def" because of t (can be modified)    
  1789.  
  1790. %-- @n character angle        angle @n -
  1791. /@n        % set current caracter angle (held in matrix $ttm)
  1792. {
  1793.     /$ttm exch matrix rotate def     % modify current text matrix accordingly
  1794. } bd
  1795.  
  1796. % -- @s : Mark a space        - @s -
  1797. /@s {} bd        % does nothing but mark a space character in extended text
  1798.  
  1799. % -- @l : Mark an end of line        - @l -
  1800. /@l {} bd        % does nothing but mark an end of line in extended text
  1801.  
  1802.  
  1803. %-- @B    stroke, then fill        - @B -
  1804. /@B
  1805. {
  1806.     @gs S    @gr                    % stroke
  1807.     F                                % fill
  1808. } bd
  1809.  
  1810. %-- @b closepath, stroke & fill path - @b -
  1811. /@b
  1812. {
  1813.     @cp @B
  1814. } bd
  1815.  
  1816. %-- @w  calligraphic pen matrix        [matrix] bscale width height angle @w -
  1817. /@w
  1818. {        % set pen matrix "$ptm" to desired settings
  1819.         % bscale is a flag: 1: "scale with object",  0 no scale
  1820.         % matrix is passed only if bscale is 1 (object total matrix)
  1821.  
  1822.     matrix rotate /$ptm xd        % define $ptm to be rotation matrix
  1823.     matrix scale                             % set pen shape
  1824.     $ptm dup concatmatrix /$ptm xd
  1825.     1 eq                        % if scale, concat object matrix
  1826.     {
  1827.         $ptm exch dup concatmatrix /$ptm xd
  1828.     } if
  1829.     1 w                                % basic thickness to be transformed by $ptm
  1830. } bd    
  1831.     
  1832. %-- @g setscreen for fill        freq ang spotproc 1 @g -
  1833. %or default screen for fill    0 @g -
  1834. /@g
  1835. {  % Set halftone screen for gray filling
  1836.          % parm spotproc is a spot procedure name (ex: /@dot or /@lin)
  1837.     1 eq dup /$sdf xd            % set global flag
  1838.     {    % next 3 parameters are set only if parm1 is 1
  1839.         /$scp xd                    % Current spot func for fill
  1840.  
  1841.         % 29-Jan-91:KB:Removed the negation of screen angle to make work like 1.21 did
  1842.         /$sca xd            % Current screen angle for fill
  1843.         /$scf xd                    % Current screen frequency for fill
  1844.     } if
  1845. } bd 
  1846.  
  1847. %-- @G setscreen for stroke        freq ang spotproc 1 @G -
  1848. %or default screen for stroke        0 @G -
  1849. /@G
  1850. {  % Set halftone screen for gray filling
  1851.          % parm spotproc is a spot procedure name (ex: /@dot ot /@lin)
  1852.     1 eq dup /$SDF xd            % set global flag
  1853.     {    % next 3 parameters are set only if parm1 is 1
  1854.         /$SCP xd                    % Current spot func for stroke
  1855.  
  1856.         % 29-Jan-91:KB:Removed the negation of screen angle to make work like 1.21 did
  1857.         /$SCA xd             % Current screen angle for stroke
  1858.         /$SCF xd                    % Current screen frequency for stroke
  1859.     } if
  1860. } bd
  1861.  
  1862. %-- @D setscreen for all document    freq ang spotproc @D -
  1863. /@D
  1864. {  % Set halftone screen for all document
  1865.     3 copy  @ss                % set that screen right now
  1866.     /$dsp xd                    % default spot func name
  1867.     /$dsa xd                    % default screen angle
  1868.     /$dsf xd                    % default screen frequency function
  1869. } bd
  1870.  
  1871. %-- @j Begin Arrow head            @j -
  1872. /@j
  1873. {    % -- DEF: BEGIN ARROW HEAD
  1874.             % -- Stack:  nothing  
  1875.     @sv        % this is just a save followed by a new path
  1876.     @np        % Look at @J for the corresponding restore
  1877. } bind def
  1878.  
  1879. %-- @J End Arrow head            @J -
  1880. /@J
  1881. {    % -- DEF: END ARROW HEAD
  1882.             % -- Stack:  nothing  
  1883.     @rs        % this is just a grestore; Look at @j for the corresponding save
  1884. } bind def
  1885.  
  1886. % --- color separation support---
  1887. % --@sep  Initialize color separation mode     - @sep -
  1888. /@sep
  1889. {
  1890.         %    ColorSeparationMode defines the current mode for color separation
  1891.         %  Possible values are:    0-composite(no color seps)
  1892.         %                                1-CMYK Only (maximum four colors, custom colors converted)
  1893.         %                                2-CMYK+Customs (four colors + each of the customs)
  1894.     /ColorSeparationMode where
  1895.     {pop}         
  1896.     {
  1897.         /ColorSeparationMode 0 def            % if not defined previously: composite
  1898.         /CurrentInkName (Composite) def    % if not defined previously: composite
  1899.     }ifelse
  1900.  
  1901.     ColorSeparationMode 0 eq                % if not defined previously: composite
  1902.     {
  1903.         /CurrentInkName (Composite) def
  1904.     } if
  1905.         
  1906.     %    CurrentInkName is a string defining the current color plane being 
  1907.     %  printed.  The possible values are: (case sensitive, not to be translated)
  1908.     %     (Composite), (Cyan), (Magenta), (Yellow), (Black), 
  1909.     %     or any of the custom colors defined in the document; e.g.: (Pantone 345)
  1910.     %  Custom color names are only valid when  "ColorSeparationMode" is 2.
  1911.  
  1912.     /CurrentInkName where
  1913.     {pop}         
  1914.     {
  1915.         /CurrentInkName (Composite) def        % if not defined previously: composite
  1916.     } ifelse
  1917.     
  1918.     %-- Internally, a numeric variable ($ink)    indicates the numeric value for the
  1919.     %    current ink, -1:composite, 0:cyan, 1:magenta, 2:yellow, 3:Black, 4: any custom
  1920.     CurrentInkName (Composite) eq 
  1921.     {/$ink -1 def}
  1922.     {
  1923.         CurrentInkName (Cyan) eq
  1924.         {/$ink 0 def}
  1925.         {
  1926.             CurrentInkName (Magenta) eq
  1927.             {/$ink 1 def}
  1928.             {
  1929.                 CurrentInkName (Yellow) eq
  1930.                 {/$ink 2 def}
  1931.                 {
  1932.                     CurrentInkName (Black) eq
  1933.                     {/$ink 3 def}
  1934.                     {
  1935.                         /$ink 4 def
  1936.                     } ifelse
  1937.                 } ifelse
  1938.             } ifelse
  1939.         } ifelse
  1940.     } ifelse
  1941. } bd
  1942. @sep    % -- And by default, call it (Can also be called in the setup section)
  1943.  
  1944. %-- @whi Fill Page white        - @whi -
  1945. /@whi
  1946. {    %- Fill everything white
  1947.     @gs
  1948.     -72000 dup moveto
  1949.     -72000 72000 lineto
  1950.     72000 dup lineto
  1951.     72000 -72000 lineto
  1952.     closepath 1 setgray fill
  1953.     @gr
  1954. } bd     
  1955.  
  1956. %-- @neg Print negative            - @neg -
  1957. /@neg
  1958. { %def -- MAKE ALL COLORS NEGATIVE  -- STACK: -
  1959.         % Only set the GRAY scale transfer function since WALDO only 
  1960.         % Uses negative for color separations.
  1961.     [{1 exch sub} /exec cvx currenttransfer /exec cvx] cvx settransfer
  1962.     @whi                            % fill page in white (Will be turned into white)
  1963. } bd
  1964.  
  1965. %-- @reg Print registration mark        x y @reg -
  1966. /@reg
  1967. {
  1968.     % 25-Apr-91:KB:Reset line type to solid
  1969.     [] 0 d
  1970.     0 setgray .3 setlinewidth
  1971.     2 copy 5.4 0 360 arc closepath
  1972.     2 copy moveto 9 0 rlineto 
  1973.     2 copy moveto -9 0 rlineto 
  1974.     2 copy moveto 0 9  rlineto 
  1975.     moveto 0 -9 rlineto stroke
  1976. } bd
  1977.  
  1978. /leftbracket {(\050)} def
  1979. /rightbracket {(\051)} def
  1980.