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