home *** CD-ROM | disk | FTP | other *** search
/ The Net Power 1997 April / NETDisc0497.iso / pc / demos / mmedia / xres / data.z / UTILS.PS < prev    next >
Encoding:
Text File  |  1996-02-26  |  10.7 KB  |  423 lines

  1.  
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %%                                    %%
  4. %% utils.ps:  PostScript procedures read in during startup, but        %%
  5. %% which don't really need to be in init.ps itself            %%
  6. %%                                    %%
  7. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8.  
  9. systemdict begin        %% All of this goes in systemdict...
  10.  
  11. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  12. %%                                    %%
  13. %% Set up basic dictionary aliases                    %%
  14. %%                                    %%
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16.  
  17. /shareddict globaldict def
  18. /SharedFontDirectory GlobalFontDirectory def
  19.  
  20.  
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22. %%                                    %%
  23. %% Start with a few universally useful things                %%
  24. %%                                    %%
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26.  
  27. /binddef {
  28.   bind def
  29. } bind def
  30.  
  31. /exchdef {
  32.   exch def
  33. } binddef
  34.  
  35.  
  36. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  37. %%                                    %%
  38. %% Define `executive' and friends.                    %%
  39. %%                                    %%
  40. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  41.  
  42. /prompt {(TPro> ) print flush} def
  43.  
  44. /execdict <<
  45.   /banner
  46.     (Welcome to TPro version ) version
  47.     1 index length 1 index length add 1 add string
  48.     dup 0 4 index putinterval
  49.     dup 4 -1 roll length 4 -1 roll putinterval
  50.     dup dup length 1 sub 10 put
  51.   /copyright (Copyright (c) 1994-1996 TechPool Software, Inc.\n)
  52.   dup 19 currentsystemparams /KernelBuild get
  53.     dup length 4 sub 4 getinterval putinterval
  54.   /execdepth 0
  55.   /prompt {(TPro) print execdepth {(>) print} repeat ( ) print flush}
  56.   /binary false
  57.   /quitflag false
  58.   /checkquit {quitflag {exit} if}
  59. >> def
  60.  
  61. /executive {
  62.   execdict begin
  63.   execdepth 0 eq {
  64.     true echo
  65.     banner print copyright print
  66.     flush
  67.   } if
  68.   /execdepth execdepth 1 add def
  69.   end
  70.   {
  71.     execdict begin prompt end
  72.     {(%statementedit) (r) file} stopped {pop pop exit} if
  73.     {cvx exec} stopped {
  74.        $error /newerror get not {exit} if
  75.        errordict /handleerror get exec
  76.     } if
  77.     flush
  78.     execdict begin checkquit end
  79.   } loop
  80.   execdict begin
  81.   /execdepth execdepth 1 sub def
  82.   execdepth 0 eq {
  83.     (%%[ End of interactive mode ]%%\n) print flush
  84.   } if
  85.   end
  86. } binddef
  87.  
  88.  
  89. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90. %%                                    %%
  91. %% Define == and its dictionary                        %%
  92. %%                                    %%
  93. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  94.  
  95. /=print {=} def
  96.  
  97. /=string 256 string def
  98.  
  99. <<
  100.   /rmargin 72
  101.   /cp 3
  102.   /NL (\n)
  103.   /cvsprint {
  104.     =string cvs tprint ( ) tprint
  105.   } bind
  106.  
  107.   /linebreak {
  108.     NL print /cp 0 def
  109.   } bind
  110.  
  111.   /tprint {
  112.     dup length cp add rmargin gt {
  113.       NL print /cp 0 def
  114.     }if
  115.     dup length cp add /cp exch def
  116.     print
  117.   } bind
  118.  
  119.   /typeprint {
  120.     dup type exec
  121.   } bind
  122.  
  123.   /arraytype {
  124.     dup rcheck {
  125.       dup xcheck {
  126.         ({) tprint {typeprint} forall (}) tprint
  127.       } {
  128.         ([) tprint {typeprint} forall (]) tprint
  129.       } ifelse
  130.     } {
  131.       pop (-array- ) tprint
  132.     } ifelse
  133.   } bind
  134.  
  135.   /packedarraytype 1 index
  136.  
  137.   /stringtype{
  138.     dup rcheck {
  139.       (\() tprint tprint (\)) tprint
  140.      } {
  141.       pop (-string- ) tprint
  142.     } ifelse 
  143.   } bind
  144.  
  145.   /nametype {
  146.     dup xcheck not {
  147.       (/) tprint
  148.     } if
  149.     cvsprint
  150.   } bind
  151.  
  152.   /marktype {pop (-mark- ) tprint} bind
  153.  
  154.   /filetype {pop (-file- ) tprint} bind
  155.  
  156.   /dicttype {
  157.     dup rcheck {
  158.       dup length 0 eq {
  159.         (<< >> ) tprint
  160.       } {
  161.         (<<) tprint linebreak
  162.         {
  163.           exch typeprint typeprint linebreak
  164.         } forall
  165.         (>> ) tprint
  166.       } ifelse
  167.     } {
  168.       pop (-dictionary- ) tprint
  169.     } ifelse
  170.   } bind
  171.  
  172.   /nulltype {pop (-null- ) tprint} bind
  173.  
  174.   /booleantype {cvsprint} 
  175.  
  176.   /realtype {cvsprint}
  177.  
  178.   /operatortype {cvsprint}
  179.  
  180.   /integertype {cvsprint}
  181.  
  182.   /fonttype {pop (-font- ) tprint} bind
  183.  
  184.   /savetype {pop (-save- ) tprint} bind
  185.  
  186.   /graphicsstatetype {pop (-graphicsstate- ) tprint} bind
  187.  
  188.   /canvastype {pop (-canvas- ) tprint} bind
  189.  
  190.   /processtype {pop (-process- ) tprint} bind
  191.  
  192. >>
  193.  
  194. {
  195.   null begin
  196.   /cp 0 def typeprint NL print
  197.   end
  198. }
  199.  
  200. dup 0 4 -1 roll put bind /== exchdef
  201.  
  202.  
  203. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  204. %%                                    %%
  205. %% Some more useful printing procedures                    %%
  206. %%                                    %%
  207. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  208.  
  209. /stack {
  210.   count 1 sub 0 1 3 -1 roll {
  211.     index =
  212.   } for
  213. } binddef
  214.  
  215. /pstack {
  216.   count 1 sub 0 1 3 -1 roll {
  217.     index ==
  218.   } for
  219. } binddef
  220.  
  221.  
  222. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  223. %%                                    %%
  224. %% The escape for Freehand v2 jobs which use setcolor.  The        %%
  225. %% interpreter calls this procedure if you execute setcolor in what %%
  226. %% looks like a Freehand v2 job.                    %%
  227. %%                                    %%
  228. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  229.  
  230. /##_setcolor_## {
  231.   dup length 4 eq {
  232.     aload overprintprocess setcmykcolor
  233.   } {
  234.     aload 1 get spots exch get 5 get setinkoverprint setspotcolor
  235.   } ifelse
  236. } binddef
  237.  
  238.  
  239. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  240. %%                                    %%
  241. %% A version of setcustomcolor which uses the /Separation colour    %%
  242. %% space so as to let you produce the spot colour you asked for.    %%
  243. %%                                    %%
  244. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  245.  
  246. /findcmykcustomcolor {
  247.   5 array astore
  248. } binddef
  249.  
  250. /setcustomcolorspace {
  251.   mark /Separation 2 index 4 get
  252.   /DeviceCMYK
  253.   {dup 0 mul exch dup 0 mul exch dup 0 mul exch 0 mul}
  254.   dup length array copy
  255.   dup 1 7 index 0 get put
  256.   dup 5 7 index 1 get put
  257.   dup 9 7 index 2 get put
  258.   dup 12 7 index 3 get put cvx
  259.   ] setcolorspace
  260.   pop
  261. } binddef
  262.  
  263. /setcustomcolor {
  264.   exch setcustomcolorspace setcolor
  265. } binddef
  266.  
  267. %%/setseparationgray {
  268. %%  currentcolorspace 0 get dup /DeviceGray ne {
  269. %%    exch
  270. %%    1 exch sub
  271. %%    exch
  272. %%  } if
  273. %%  /DeviceCMYK eq {
  274. %%    dup dup dup
  275. %%  } if
  276. %%  setcolor
  277. %%} binddef
  278.  
  279. /customcolorimage {
  280.   setcustomcolorspace
  281.   10 dict begin
  282.   /DataSource exch def
  283.   /ImageMatrix exch def
  284.   /BitsPerComponent exch def
  285.   /Height exch def
  286.   /Width exch def
  287.   /ImageType 1 def
  288.   /Decode [1 0] def
  289.   currentdict end image
  290. } binddef
  291.  
  292.  
  293.  
  294. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  295. %%                                    %%
  296. %% $fbf is an undocumented procedure which seems to be needed if    %%
  297. %% the RIP provides makeblendedfont as an operator.  I can't quite  %%
  298. %% see why it's necessary, other than because the PostScript code   %%
  299. %% assumes it's been defined.  It certainly doesn't add any         %%
  300. %% functionality.                            %%
  301. %%                                    %%
  302. %% This may have been a PostScript printer driver bug, as I'm sure  %%
  303. %% I've since seen code with $fbf that worked OK.            %%
  304. %%                                    %%
  305. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  306.  
  307. /$fbf {
  308.   FontDirectory counttomark 3 add -1 roll known {
  309.     cleartomark pop findfont
  310.   } {
  311.     ] exch findfont exch makeblendedfont
  312.     dup /Encoding currentfont /Encoding get put definefont
  313.   } ifelse
  314.   currentfont /ScaleMatrix get makefont setfont
  315. } binddef
  316.  
  317.  
  318.  
  319. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  320. %%                                    %%
  321. %% A procedure to render a PDF document from beginning to end.      %%
  322. %%                                    %%
  323. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  324.  
  325. /PDFrun {
  326.   PDFfile
  327.   dup 1 PDFpagebbox
  328.   4 2 roll pop pop 2 array astore << /PageSize 3 -1 roll >> setpagedevice
  329.   1 1 2 index PDFpagecount {
  330.     1 index exch PDFpage showpage
  331.   } for
  332.   pop
  333. } binddef
  334.  
  335.  
  336. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  337. %%                                    %%
  338. %% A veritable forest of paper sizes                    %%
  339. %%                                    %%
  340. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  341.  
  342. /A3 {<</PageSize [842 1190] /ImagingBBox null>> setpagedevice} binddef
  343. /a3 /A3 load def
  344. /A4 {<</PageSize [595 842] /ImagingBBox null>> setpagedevice} binddef
  345. /a4 /A4 load def
  346. /A5 {<</PageSize [421 595] /ImagingBBox null>> setpagedevice} binddef
  347. /a5 /A5 load def
  348. /B4 {<</PageSize [709 1001] /ImagingBBox null>> setpagedevice} binddef
  349. /b4 /B4 load def
  350. /B5 {<</PageSize [499 709] /ImagingBBox null>> setpagedevice} binddef
  351. /b5 /B5 load def
  352. /c5 {<</PageSize [459 649] /ImagingBBox null>> setpagedevice} binddef
  353. /com10 {<</PageSize [297 684] /ImagingBBox null>> setpagedevice} binddef
  354. /dl {<</PageSize [312 624] /ImagingBBox null>> setpagedevice} binddef
  355. /execu {<</PageSize [522 756] /ImagingBBox null>> setpagedevice} binddef
  356. /Legal {<</PageSize [612 1008] /ImagingBBox null>> setpagedevice} binddef
  357. /legal /Legal load def
  358. /Letter {<</PageSize [612 792] /ImagingBBox null>> setpagedevice} binddef
  359. /letter /Letter load def
  360. /monarch {<</PageSize [279 540] /ImagingBBox null>> setpagedevice} binddef
  361. /Note {<</PageSize [554 732] /ImagingBBox null>> setpagedevice} binddef
  362. /note /Note load def
  363. /11x17 {<</PageSize [792 1224] /ImagingBBox null>> setpagedevice} binddef
  364. /a4small {<</PageSize [595 842] /ImagingBBox [25 25 570 817]>> setpagedevice} binddef
  365. /lettersmall {<</PageSize [612 792] /ImagingBBox [25 25 587 767]>> setpagedevice} binddef
  366.  
  367. %% Added for HP compatibility.  C.C. - 2/26/96
  368. /lettertray {<< /PageSize [612 792] >> setpagedevice} def
  369.  
  370. /setpage {statusdict begin setpage end} def
  371.  
  372. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  373. %%                                    %%
  374. %% Added to make processing EPSF files easier, per the instructions %%
  375. %% on p. 726 of the PLRM.  C.C. - 2/26/96                %%
  376. %%                                    %%
  377. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  378.  
  379. /BeginEPSF
  380. {
  381.     /b4_Inc_state save def
  382.     /dict_count countdictstack def
  383.     /op_count count 1 sub def
  384.     userdict begin
  385.     /showpage {} def
  386.     0 setgray 0 setlinecap
  387.     1 setlinewidth 0 setlinejoin
  388.     10 setmiterlimit [] 0 setdash newpath
  389.     /languagelevel where
  390.     {
  391.         pop languagelevel
  392.         1 ne {false setstrokeadjust false setoverprint} if
  393.     } if
  394. } bind def
  395.  
  396. /EndEPSF
  397. {
  398.     count op_count sub {pop} repeat
  399.     countdictstack dict_count sub {end} repeat
  400.     b4_Inc_state restore
  401. } bind def
  402.  
  403.  
  404. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  405. %%                                    %%
  406. %% Added to make color accuracy better when rasterizing AI 1.1        %%
  407. %% files.  C.C. - 2/26/96                        %%
  408. %%                                    %%
  409. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  410. /setcmybcolor
  411. {
  412.  
  413. %    (Calling setcmybcolor.) = flush
  414.  
  415.     setcmykcolor
  416.  
  417. } bind def
  418.  
  419.  
  420. end    % systemdict
  421.  
  422.  
  423.