home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 September / PCWorld_2001-09_cd.bin / Software / Vyzkuste / rychlokurz / gs700w32.exe / gs7.00 / lib / gs_init.ps < prev    next >
Text File  |  2001-04-09  |  60KB  |  1,818 lines

  1. %    Copyright (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of AFPL Ghostscript.
  3. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  4. % distributor accepts any responsibility for the consequences of using it, or
  5. % for whether it serves any particular purpose or works at all, unless he or
  6. % she says so in writing.  Refer to the Aladdin Free Public License (the
  7. % "License") for full details.
  8. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. % in a plain ASCII text file named PUBLIC.  The License grants you the right
  10. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. % conditions described in the License.  Among other things, the License
  12. % requires that the copyright notice and this notice be preserved on all
  13. % copies.
  14.  
  15. % $Id: gs_init.ps,v 1.34 2001/04/09 06:20:03 raph Exp $
  16. % Initialization file for the interpreter.
  17. % When this is run, systemdict is still writable.
  18.  
  19. % Comment lines of the form
  20. %    %% Replace <n> <file(s)>
  21. % indicate places where the next <n> lines should be replaced by
  22. % the contents of <file(s)>, when creating a single merged init file.
  23.  
  24. % The interpreter can call out to PostScript code.  All procedures
  25. % called in this way, and no other procedures defined in these
  26. % initialization files, have names that begin with %, e.g.,
  27. % (%Type1BuildChar) cvn.
  28.  
  29. % Check the interpreter revision.  NOTE: the interpreter code requires
  30. % that the first non-comment token in this file be an integer.
  31. 700
  32. dup revision ne
  33.  { (gs: Interpreter revision \() print revision 10 string cvs print
  34.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  35.    (\).\n) print flush null 1 .quit
  36.  }
  37. if pop
  38.  
  39. % Acquire userdict, and set its length if necessary.
  40. /userdict where
  41.  { pop userdict maxlength 0 eq }
  42.  { true }
  43. ifelse
  44. systemdict exch
  45.  {        % userdict wasn't already set up by iinit.c.
  46.    dup /userdict
  47.    currentdict dup 200 .setmaxlength        % userdict
  48.    .forceput            % userdict is local, systemdict is global
  49.  }
  50. if begin
  51.  
  52. % Define dummy local/global operators if needed.
  53. systemdict /.setglobal known
  54.  { true .setglobal
  55.  }
  56.  { /.setglobal { pop } bind def
  57.    /.currentglobal { false } bind def
  58.    /.gcheck { pop false } bind def
  59.  }
  60. ifelse
  61.  
  62. % Define .languagelevel if needed.
  63. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  64.  
  65. % Optionally choose a default paper size other than U.S. letter.
  66. % (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
  67.  
  68. % Turn on array packing for the rest of initialization.
  69. true setpacking
  70.  
  71. % Define the old MS-DOS EOF character as a no-op.
  72. % This is a hack to get around the absurd habit of MS-DOS editors
  73. % of adding an EOF character at the end of the file.
  74. <1a> cvn { } def
  75.  
  76. % Acquire the debugging flags.
  77. currentdict /DEBUG known   /DEBUG exch def
  78.   /VMDEBUG
  79.     DEBUG {{print mark
  80.             systemdict /level2dict known
  81.          { .currentglobal dup false .setglobal vmstatus
  82.            true .setglobal vmstatus 3 -1 roll pop
  83.            6 -2 roll pop .setglobal
  84.          }
  85.          { vmstatus 3 -1 roll pop
  86.          }
  87.         ifelse usertime 16#fffff and counttomark
  88.           { ( ) print (           ) cvs print }
  89.         repeat pop
  90.         ( ) print systemdict length (    ) cvs print
  91.         ( ) print countdictstack (  ) cvs print
  92.         ( <) print count (    ) cvs print (>\n) print flush
  93.       }}
  94.       {{pop
  95.       }}
  96.      ifelse
  97.   def
  98.  
  99. currentdict /BATCH known   /BATCH exch def
  100. currentdict /DELAYBIND known   /DELAYBIND exch def
  101. currentdict /DISKFONTS known   /DISKFONTS exch def
  102. currentdict /DOINTERPOLATE .knownget { /INTERPOLATE exch def } if
  103. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  104. currentdict /FAKEFONTS known   /FAKEFONTS exch def
  105. currentdict /FIXEDMEDIA known   /FIXEDMEDIA exch def
  106. currentdict /FIXEDRESOLUTION known   /FIXEDRESOLUTION exch def
  107. currentdict /LOCALFONTS known   /LOCALFONTS exch def
  108. currentdict /NOBIND known   /NOBIND exch def
  109. /.bind /bind load def
  110. NOBIND { /bind { } def } if
  111. currentdict /NOCACHE known   /NOCACHE exch def
  112. currentdict /NOCIE known   /NOCIE exch def
  113. currentdict /NODISPLAY known   not /DISPLAYING exch def
  114. currentdict /NOFONTMAP known   /NOFONTMAP exch def
  115. currentdict /NOFONTPATH known   /NOFONTPATH exch def
  116. currentdict /NOGC known   /NOGC exch def
  117. currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
  118. currentdict /NOPAGEPROMPT known   /NOPAGEPROMPT exch def
  119. currentdict /NOPAUSE known   /NOPAUSE exch def
  120. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  121. currentdict /NOPROMPT known   /NOPROMPT exch def
  122. % The default value of ORIENT1 is true, not false.
  123. currentdict /ORIENT1 known not { /ORIENT1 true def } if
  124. currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
  125. currentdict /OUTPUTFILE known    % obsolete
  126.  { /OutputFile /OUTPUTFILE load def
  127.    currentdict /OUTPUTFILE .undef
  128.  } if
  129. currentdict /QUIET known   /QUIET exch def
  130. currentdict /SAFER known   /SAFER exch def
  131. currentdict /DELAYSAFER known   /DELAYSAFER exch def
  132. currentdict /SHORTERRORS known   /SHORTERRORS exch def
  133. currentdict /STRICT known   /STRICT exch def
  134. currentdict /TTYPAUSE known   /TTYPAUSE exch def
  135. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  136.  
  137. % Acquire environment variables.
  138. currentdict /DEVICE known not
  139.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  140.  
  141. (START) VMDEBUG
  142.  
  143. % Open the standard files, so they will be open at the outermost save level.
  144. (%stdin) (r) file pop
  145. (%stdout) (w) file pop
  146. (%stderr) (w) file pop
  147.  
  148. /.currentuserparams where {
  149.   pop mark
  150.     % The Adobe implementations appear to have very large maximum
  151.     % stack sizes.  This turns out to actually make a difference,
  152.     % since some badly-behaved files include extremely long procedures,
  153.     % or construct huge arrays on the operand stack.
  154.     % We reset the stack sizes now so that we don't have to worry
  155.     % about overflowing the (rather small) built-in stack sizes
  156.     % during initialization.
  157.   /MaxDictStack 500
  158.   /MaxExecStack 5000
  159.   /MaxOpStack 50000
  160.   .dicttomark .setuserparams
  161. } if
  162.  
  163. % Define a procedure for skipping over an unneeded section of code.
  164. % This avoids allocating space for the skipped procedures.
  165. % We can't use readline, because that imposes a line length limit.
  166. /.skipeof    % <string> .skipeof -
  167.  { currentfile exch 1 exch .subfiledecode flushfile
  168.  } .bind def
  169.  
  170. % Define procedures to assist users who don't read the documentation.
  171. userdict begin
  172. /help
  173.  { (Enter PostScript commands.  '(filename) run' runs a file, 'quit' exits.\n)
  174.    print flush
  175.  } .bind def
  176. end
  177.  
  178. % Define =string, which is used by some PostScript programs even though
  179. % it isn't documented anywhere.
  180. % Put it in userdict so that each context can have its own copy.
  181. userdict /=string 256 string put
  182.  
  183. % Print the greeting.
  184.  
  185. /printgreeting
  186.  { mark
  187.    product (Ghostscript) search
  188.     { pop pop pop
  189.       (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
  190.     }
  191.     { pop
  192.     }
  193.    ifelse
  194.    (\n) copyright
  195.    (\)\n) revisiondate 10 mod revisiondate 10 idiv 10 mod (-)
  196.    revisiondate 100 idiv 10 mod revisiondate 1000 idiv 10 mod (-)
  197.    revisiondate 10000 idiv ( \()
  198.    revision 10 mod
  199.    revision 100 mod dup 0 ne { 10 idiv } { pop } ifelse (.)
  200.    revision 100 idiv ( )
  201.    product
  202.    counttomark
  203.     { (%stdout) (w) file exch 0 .writecvp
  204.     } repeat pop
  205.  } .bind def
  206.  
  207. QUIET not { printgreeting flush } if
  208.  
  209. % Define a special version of def for making operator procedures.
  210. /obind {    % <name> <proc> obind <name> <oper>
  211.   1 index exch .makeoperator
  212. } .bind def
  213. /odef {        % <name> <proc> odef -
  214.   1 index exch .makeoperator def
  215. } .bind def
  216.  
  217. % Define a special version of def for storing local objects into global
  218. % dictionaries.  Like .forceput, this exists only during initialization.
  219. /.forcedef {        % <key> <value> .forcedef -
  220.   currentdict 3 1 roll .forceput
  221. } .bind odef
  222.  
  223. % Define procedures for accessing variables in systemdict and userdict
  224. % regardless of the contents of the dictionary stack.
  225. /.systemvar {        % <name> .systemvar <value>
  226.   //systemdict exch get
  227. } .bind odef
  228. /.userdict {        % - .userdict <dict>
  229.   /userdict .systemvar
  230. } .bind odef
  231. /.uservar {        % <name> .uservar <value>
  232.   .userdict exch get
  233. } .bind odef
  234.  
  235. % If we're delaying binding, remember everything that needs to be bound later.
  236. DELAYBIND NOBIND not and
  237.  { .currentglobal false .setglobal
  238.    systemdict /.delaybind 1500 array .forceput
  239.    .setglobal
  240.    userdict /.delaycount 0 put
  241.     % When we've done the delayed bind, we want to stop saving.
  242.     % Detect this by the disappearance of .delaybind.
  243.    /bind
  244.     { /.delaybind .systemvar dup length 0 ne
  245.        { .delaycount 2 index put
  246.          .userdict /.delaycount .delaycount 1 add put
  247.        }
  248.        { pop .bind
  249.        }
  250.       ifelse
  251.     } .bind def
  252.  } if
  253.  
  254. %**************** BACKWARD COMPATIBILITY
  255. /hwsizedict mark /HWSize null .dicttomark readonly def
  256. /copyscanlines {        % <device> <y> <string> copyscanlines <substr>
  257.   0 3 1 roll 3 index //hwsizedict .getdeviceparams
  258.   exch pop exch pop aload pop 3 2 roll
  259.   0 exch null exch .getbitsrect exch pop
  260. } bind odef
  261. currentdict /hwsizedict .undef
  262. /getdeviceprops
  263.  { null .getdeviceparams
  264.  } bind odef
  265. /.putdeviceprops
  266.  { null true counttomark 1 add 3 roll .putdeviceparams
  267.    dup type /booleantype ne
  268.     { dup mark eq { /unknown /rangecheck } if
  269.       counttomark 4 add 1 roll cleartomark pop pop pop
  270.       /.putdeviceprops load exch signalerror
  271.     }
  272.    if
  273.  } bind odef
  274. /max { .max } bind def
  275. /min { .min } bind def
  276. /.currentfilladjust { .currentfilladjust2 pop } bind odef
  277. /.setfilladjust { dup .setfilladjust2 } bind odef
  278. /unread /.unread load def
  279. /.writecvs { 0 .writecvp } bind odef
  280.  
  281. % Define predefined procedures substituting for operators,
  282. % in alphabetical order.
  283.  
  284. userdict /#copies 1 put
  285. % Adobe implementations don't accept /[ or /], so we don't either.
  286. ([) cvn
  287.     /mark load def
  288. (]) cvn
  289.     {counttomark array astore exch pop} odef
  290. % .beginpage is redefined if setpagedevice is present.
  291. /.beginpage { } odef
  292. % In LanguageLevel 3, copypage erases the page.
  293. /copypage {
  294.     .languagelevel 3 ge
  295.     dup { 0 } { 1 } ifelse .endpage {
  296.       .currentnumcopies 1 index .outputpage
  297.       (>>copypage, press <return> to continue<<\n) .confirm
  298.       dup { erasepage } if
  299.     } if pop .beginpage
  300. } odef
  301. /currentmatrix {
  302.     .currentmatrix 6 index astore pop
  303. } odef
  304. % .currentnumcopies is redefined in Level 2.
  305. /.currentnumcopies { #copies } odef
  306. /setcolorscreen where { pop        % not in all Level 1 configurations
  307.    /currentcolorscreen
  308.     { .currenthalftone
  309.        { { 60 exch 0 exch 3 copy 6 copy }    % halftone - not possible
  310.          { 3 copy 6 copy }            % screen
  311.          { }                % colorscreen
  312.        }
  313.       exch get exec
  314.     } odef
  315. } if
  316. /currentscreen
  317.     { .currenthalftone
  318.        { { 60 exch 0 exch }            % halftone - not possible
  319.          { }                % screen
  320.          { 12 3 roll 9 { pop } repeat }    % colorscreen
  321.        }
  322.       exch get exec
  323.     } odef
  324. /.echo /echo load def
  325. userdict /.echo.mode true put
  326. /echo    {dup /.echo.mode exch store .echo} odef
  327. /eexec {
  328.     % Rebind .currentresourcefile if it is the source for the eexec.
  329.   dup 55665 //filterdict /eexecDecode get exec
  330.   cvx exch .currentresourcefile eq
  331.   //systemdict begin { {exec} .execasresource } { exec } ifelse
  332.     % Only pop systemdict if it is still the top element,
  333.     % because this is apparently what Adobe interpreters do.
  334.   currentdict //systemdict eq { end } if
  335. } odef
  336. % .endpage is redefined if setpagedevice is present.
  337. /.endpage { 2 ne } odef
  338. % erasepage mustn't use gsave/grestore, because we call it before
  339. % the graphics state stack has been fully initialized.
  340. /erasepage
  341.     { /currentcolor where
  342.        { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  343.        { /currentcmykcolor where
  344.           { pop currentcmykcolor { setcmykcolor } }
  345.           { currentrgbcolor { setrgbcolor } }
  346.          ifelse
  347.        }
  348.       ifelse 1 setgray .fillpage exec
  349.     } odef
  350. % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
  351. /executive
  352.     { { prompt
  353.          { (%statementedit) (r) file } stopped
  354.          { pop pop $error /errorname get /undefinedfilename eq
  355.         { .clearerror exit } if        % EOF
  356.            handleerror null        % ioerror??
  357.          }
  358.         if
  359.         cvx { .runexec } execute
  360.       } loop
  361.     } bind def
  362. /filter
  363.     { //filterdict 1 index .knownget
  364.        { exch pop exec }
  365.        { /filter load /undefined signalerror }
  366.       ifelse
  367.     } odef
  368. /handleerror
  369.     { /errordict .systemvar /handleerror get exec } bind def
  370. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  371. /identmatrix
  372.     { dup 0 //identmatrix putinterval } odef
  373. /languagelevel 1 def        % gs_lev2.ps may change this
  374. /makeimagedevice { false makewordimagedevice } odef
  375. /matrix    { 6 array identmatrix } odef
  376. /pathbbox
  377.     { false .pathbbox
  378.     } odef
  379. % .promptmsg is redefined if the interpreter includes readline support.
  380. /.promptmsg {
  381.     (GS) print
  382.     count 0 ne { (<) print count =only } if
  383.     (>) print flush
  384. } bind def
  385. /prompt    { flush flushpage NOPROMPT not { .promptmsg } if } bind def
  386. /pstack    { 0 1 count 3 sub { index == } for } bind def
  387. /putdeviceprops
  388.     { .putdeviceprops { erasepage } if } odef
  389. /quit    { /quit load 0 .quit } odef
  390. /run    { dup type /filetype ne { (r) file } if
  391.         % We must close the file when execution terminates,
  392.         % regardless of the state of the stack,
  393.         % and then propagate an error, if any.
  394.       cvx .runexec
  395.     } odef
  396. % Execute a file.
  397. % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
  398. % we detect that here, since we need to handle this even if we start out
  399. % without job control in effect.
  400. %
  401. % What we push on the e-stack is the following to be executed in this order:
  402. %    <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
  403. /.runexec1 {        % <file|fileproc> .runexec1 -
  404.   dup type /filetype ne { cvx exec } if
  405.   cvx null 2 .stopped
  406.     % If we got back here from a startjob, just keep going.
  407.     % startjob replaces the null on the o-stack with a procedure
  408.     % to be executed when we get back here.
  409.   dup null ne { exec true } { pop false } ifelse
  410. } bind def
  411. /.runexec2 {        % <continue> <file|fileproc> .runexec2 -
  412.   exch {
  413.     .runexec
  414.   } {
  415.     dup type /filetype ne { cvx exec } if
  416.     closefile
  417.   } ifelse
  418. } bind def
  419. /.runexec {        % <file|fileproc> .runexec -
  420.   cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
  421. } bind def
  422. % The following is only for compatibility with Adobe interpreters.
  423. /setdash {
  424.     1 index length 11 gt { /setdash load /limitcheck signalerror } if
  425.     //setdash
  426. } odef
  427. /setdevice
  428.     { .setdevice { erasepage } if } odef
  429. /setlinecap {
  430.     dup 2 gt { /setlinecap load /rangecheck signalerror } if
  431.     .setlinecap
  432. } odef
  433. /setlinejoin {
  434.     dup 2 gt { /setlinejoin load /rangecheck signalerror } if
  435.     .setlinejoin
  436. } odef
  437. /setmatrix {
  438.     dup aload pop .setmatrix pop
  439. } odef
  440. /showpage {
  441.     0 .endpage .doneshowpage {
  442.       .currentnumcopies true .outputpage
  443.       (>>showpage, press <return> to continue<<\n) .confirm
  444.       erasepage
  445.     } if initgraphics .beginpage
  446. } odef
  447. % Code output by Adobe Illustrator relies on the fact that
  448. % `stack' is a procedure, not an operator!!!
  449. /stack    { 0 1 count 3 sub { index = } for } bind def
  450. /start    { BATCH { null 0 .quit } { executive } ifelse } def
  451. % Internal uses of stopped that aren't going to do a stop if an error occurs
  452. % should use .internalstopped to avoid setting newerror et al.
  453. /.internalstopped { null 1 .stopped null ne } bind def
  454. /store {    % Don't alter operands before completing.
  455.     1 index where { 2 index 2 index put pop pop } { def } ifelse
  456. } odef
  457. /.typenames mark .typenames counttomark packedarray exch pop def
  458. /type {
  459.     //.typenames .type
  460. } odef
  461. currentdict /.typenames .undef
  462. % When running in Level 1 mode, this interpreter is supposed to be
  463. % compatible with PostScript "version" 54.0 (I think).
  464. /version (54.0) readonly def
  465. /.wheredict 10 dict def
  466. /.where /where load def
  467. /where {
  468.     //.wheredict 1 index .knownget { exec } { .where } ifelse
  469. } odef
  470.  
  471. % internaldict is defined in systemdict, but the dictionary is allocated
  472. % in local VM.  However, the procedure must be global, since it is an
  473. % "operator" and must be bind-able into global procedures.
  474. % We make a procedure for creating it, since we must create a new one
  475. % for each context with private local VM.
  476. /.makeinternaldict {
  477.   .currentglobal true .setglobal
  478.     [ /dup .systemvar 1183615869 /eq .systemvar
  479.     [ /pop .systemvar null ] cvx
  480.     false .setglobal
  481.     dup 1 10 dict .forceput    % proc is global, dict is local
  482.     true .setglobal
  483.     [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
  484.       /ifelse .systemvar
  485.     ] cvx executeonly
  486.   exch .setglobal
  487. } odef
  488. systemdict /internaldict dup .makeinternaldict .makeoperator
  489. .forceput        % proc is local, systemdict is global
  490. % Move superexec to internaldict if superexec is defined.
  491. currentdict /superexec .knownget {
  492.   1183615869 internaldict /superexec 3 -1 roll put
  493.   currentdict /superexec .undef
  494. } if
  495.  
  496. % Define some additional built-in procedures (beyond the ones defined by
  497. % the PostScript Language Reference Manual).
  498. % Warning: these are not guaranteed to stay the same from one release
  499. % to the next!
  500. /concatstrings
  501.     { exch dup length 2 index length add string    % str2 str1 new
  502.       dup dup 4 2 roll copy        % str2 new new new1
  503.       length 4 -1 roll putinterval
  504.     } bind def
  505. /copyarray
  506.     { dup length array copy } bind def
  507. % Copy a dictionary per the Level 2 spec even in Level 1.
  508. /.copydict        % <fromdict> <todict> .copydict <todict>
  509.     { dup 3 -1 roll { put dup } forall pop } bind def
  510. /copystring
  511.     { dup length string copy } bind def
  512. /findlibfile {
  513.     .libfile { dup .filename pop exch true } { false } ifelse
  514. } odef
  515. /.growdictlength    % get size for growing a dictionary
  516.     { length 3 mul 2 idiv 1 add
  517.     } bind def
  518. /.growdict        % grow a dictionary
  519.     { dup .growdictlength .setmaxlength
  520.     } bind def
  521. /.growput        % put, grow the dictionary if needed
  522.     { 2 index length 3 index maxlength eq
  523.        { 3 copy pop known not { 2 index .growdict } if
  524.        } if
  525.       put
  526.     } bind def
  527. % .localvmarray may be an operator: see zsysvm.c.
  528. /.localvmarray where {
  529.   pop
  530. } {
  531.   /.localvmarray {
  532.     .currentglobal false .setglobal
  533.     exch array exch .setglobal
  534.   } bind def
  535. } ifelse
  536. /.localvmdict where {
  537.   pop
  538. } {
  539.   /.localvmdict {
  540.     .currentglobal false .setglobal
  541.     exch dict exch .setglobal
  542.   } bind def
  543. } ifelse
  544. /.packtomark
  545.     { counttomark packedarray exch pop } bind def
  546. /ppstack
  547.     { 0 1 count 3 sub { index === } for } bind def
  548. /runlibfile
  549.     {        % We don't want to bind 'run' into this procedure,
  550.             % since run may get redefined.
  551.       findlibfile
  552.        { exch pop /run .systemvar exec }
  553.        { /undefinedfilename signalerror }
  554.       ifelse
  555.     } bind def
  556. /selectdevice
  557.     { finddevice setdevice .setdefaultscreen } bind def
  558. /signalerror        % <object> <errorname> signalerror -
  559.     { /errordict .systemvar exch get exec } bind def
  560.  
  561. % Define the =[only] procedures.  Also define =print,
  562. % which is used by some PostScript programs even though
  563. % it isn't documented anywhere.
  564. /write=only {
  565.     .writecvs
  566. } bind def
  567. /write= {
  568.     1 index exch write=only (\n) writestring
  569. } bind def
  570. /=only    { (%stdout) (w) file exch write=only } bind def
  571. /=    { =only (\n) print } bind def
  572. /=print    /=only load def
  573. % Temporarily define == as = for the sake of runlibfile0.
  574. /== /= load def
  575.  
  576. % The following procedures are documented.
  577. /copydevice {        % <device> copydevice <newdevice>
  578.   false .copydevice2
  579. } odef
  580. /finddevice {        % <devicename> finddevice <device>
  581.   /devicedict .systemvar exch get
  582.   dup 1 get null eq {
  583.         % This is the first request for this type of device.
  584.         % Create a default instance now.
  585.         % Stack: [proto null]
  586.     .currentglobal true .setglobal exch
  587.     dup dup 0 get copydevice 1 exch put
  588.     exch .setglobal
  589.   } if 1 get
  590. } bind def
  591. /findprotodevice {    % <devicename> findprotodevice <protodevice>
  592.   /devicedict .systemvar exch get 0 get
  593. } bind def
  594.  
  595. % Run a resource file.  This allows us to distinguish resource objects
  596. % from objects coming from input files.
  597. userdict /.currentresourcefile null put
  598. /.execasresource {    % <file> <proc|runfile> .execasresource -
  599.   /stopped .systemvar
  600.   /.currentresourcefile .uservar
  601.         % Stack: file proc -stopped- currfile
  602.   .userdict /.currentresourcefile 5 index cvlit put
  603.   2 .execn        % stopped <file>
  604.   .userdict /.currentresourcefile 3 -1 roll put
  605.   { stop } if
  606. } bind def
  607. /.runresource {        % <file> .runresource -
  608.   { /run .systemvar exec } .execasresource
  609. } bind def
  610.  
  611. % Define procedures for getting and setting the current device resolution.
  612.  
  613. /gsgetdeviceprop    % <device> <propname> gsgetdeviceprop <value>
  614.  { 2 copy mark exch null .dicttomark .getdeviceparams
  615.    dup mark eq        % if true, not found
  616.     { pop dup /undefined signalerror }
  617.     { 5 1 roll pop pop pop pop }
  618.    ifelse
  619.  } bind def
  620. /gscurrentresolution    % - gscurrentresolution <[xres yres]>
  621.  { currentdevice /HWResolution gsgetdeviceprop
  622.  } bind def
  623. /gssetresolution    % <[xres yres]> gssetresolution -
  624.  { 2 array astore mark exch /HWResolution exch
  625.    currentdevice copydevice putdeviceprops setdevice
  626.  } bind def
  627.  
  628. % Define auxiliary procedures needed for the above.
  629. /shellarguments        % -> shell_arguments true (or) false
  630.     { /ARGUMENTS where
  631.        { /ARGUMENTS get dup type /arraytype eq
  632.           { aload pop /ARGUMENTS null store true }
  633.           { pop false }
  634.          ifelse }
  635.        { false } ifelse
  636.     } bind def
  637. /.confirm {
  638.   DISPLAYING NOPAUSE not TTYPAUSE or and {
  639.     % Print a message (unless NOPAGEPROMPT or NOPROMPT is true)
  640.     % and wait for the user to type something.
  641.     % If the user just types a newline, flush it.
  642.     NOPAGEPROMPT NOPROMPT or { pop } { print flush } ifelse
  643.     .confirmread
  644.   } {
  645.     pop
  646.   } ifelse
  647. } bind def
  648. /.confirmread {
  649.   TTYPAUSE {
  650.     (/dev/tty) (r) file dup read pop pop closefile
  651.   } {
  652.     .echo.mode false echo
  653.     (%stdin) (r) file dup read {
  654.       dup (\n) 0 get eq { pop pop } { unread } ifelse
  655.     } {
  656.       pop
  657.     } ifelse echo
  658.   } ifelse
  659. } bind def
  660.  
  661. % Define the procedure used by .runfile, .runstdin and .runstring
  662. % for executing user input.
  663. % This is called with a procedure or executable file on the operand stack.
  664. /.execute {        % <obj> .execute <stopped>
  665.   stopped $error /newerror get and
  666.    { handleerror flush true } { false } ifelse
  667. } bind def
  668. /execute {        % <obj> execute -
  669.   .execute pop
  670. } odef
  671. % Define an execute analogue of runlibfile0.
  672. /execute0 {        % <obj> execute0 -
  673.   .execute { /execute0 cvx 1 .quit } if
  674. } bind def
  675. % Define the procedure that the C code uses for running files
  676. % named on the command line.
  677. /.runfile {
  678.   { runlibfile } execute0
  679. } def
  680. % Define the procedure that the C code uses for running piped input.
  681. % We don't use the obvious { (%stdin) run }, because we want the file to be
  682. % reopened if a startjob does a restore.
  683. /.runstdin {
  684.   { { (%stdin) (r) file cvx } .runexec } execute0
  685. } bind def
  686. % Define the procedure that the C code uses for running commands
  687. % given on the command line with -c.  We turn the string into a file so that
  688. % .runexec can do the right thing with a startjob.
  689. /.runstring {
  690.   .currentglobal exch true .setglobal
  691.   0 () .subfiledecode
  692.   exch .setglobal cvx { .runexec } execute0
  693. } bind def
  694. % Define the procedure that the C code uses to set up for executing
  695. % a string that may be received in pieces.
  696. /.runstringbegin {
  697.   .currentglobal true .setglobal
  698.   { .needinput } bind 0 () .subfiledecode
  699.   exch .setglobal cvx .runexec
  700. } bind def
  701.  
  702. % Define a special version of runlibfile that aborts on errors.
  703. /runlibfile0
  704.     { cvlit dup /.currentfilename exch def
  705.        { findlibfile not { stop } if }
  706.       stopped
  707.        { (Can't find \(or open\) initialization file ) print
  708.          .currentfilename == flush /runlibfile0 cvx 1 .quit
  709.        } if
  710.       exch pop cvx stopped
  711.        { (While reading ) print .currentfilename print (:\n) print flush
  712.          handleerror /runlibfile0 1 .quit
  713.        } if
  714.     } bind def
  715. % Temporarily substitute it for the real runlibfile.
  716. /.runlibfile /runlibfile load def
  717. /runlibfile /runlibfile0 load def
  718.  
  719. % Create the error handling machinery.
  720. % Define the standard error handlers.
  721. % The interpreter has created the ErrorNames array.
  722. /.unstoppederrorhandler    % <command> <errorname> .unstoppederrorhandler -
  723.  {    % This is the handler that gets used for recursive errors,
  724.     % or errors outside the scope of a 'stopped'.
  725.    2 copy SHORTERRORS
  726.     { (%%[ Error: ) print =only flush
  727.       (; OffendingCommand: ) print =only ( ]%%) =
  728.     }
  729.     { (Unrecoverable error: ) print =only flush
  730.       ( in ) print = flush
  731.       count 2 gt
  732.        { (Operand stack:\n  ) print
  733.      2 1 count 3 sub { (  ) print index =only flush } for
  734.      () = flush
  735.        } if
  736.     }
  737.    ifelse
  738.    -1 0 1 //ErrorNames length 1 sub
  739.     { dup //ErrorNames exch get 3 index eq
  740.        { not exch pop exit } { pop } ifelse
  741.     }
  742.    for exch pop .quit
  743.  } bind def
  744. /.errorhandler        % <command> <errorname> .errorhandler -
  745.   {        % Detect an internal 'stopped'.
  746.     1 .instopped { null eq { pop pop stop } if } if
  747.     $error /.inerror get 1 .instopped { pop } { pop true } ifelse
  748.      { .unstoppederrorhandler
  749.      } if    % detect error recursion
  750.     $error /globalmode .currentglobal false .setglobal put
  751.     $error /.inerror true put
  752.     $error /newerror true put
  753.     $error exch /errorname exch put
  754.     $error exch /command exch put
  755.     $error /recordstacks get $error /errorname get /VMerror ne and
  756.      {        % Attempt to store the stack contents atomically.
  757.        count array astore dup $error /ostack 4 -1 roll
  758.        countexecstack array execstack $error /estack 3 -1 roll
  759.        countdictstack array dictstack $error /dstack 3 -1 roll
  760.        put put put aload pop
  761.      }
  762.      { $error /dstack .undef
  763.        $error /estack .undef
  764.        $error /ostack .undef
  765.      }
  766.     ifelse
  767.     $error /position currentfile status
  768.      { currentfile { fileposition } .internalstopped { pop null } if
  769.      }
  770.      {        % If this was a scanner error, the file is no longer current,
  771.         % but the command holds the file, which may still be open.
  772.        $error /command get dup type /filetype eq
  773.         { { fileposition } .internalstopped { pop null } if }
  774.         { pop null }
  775.        ifelse
  776.      }
  777.     ifelse put
  778.         % During initialization, we don't reset the allocation
  779.         % mode on errors.
  780.     $error /globalmode get $error /.nosetlocal get and .setglobal
  781.     $error /.inerror false put
  782.     stop
  783.   } bind def
  784. % Define the standard handleerror.  We break out the printing procedure
  785. % (.printerror) so that it can be extended for binary output
  786. % if the Level 2 facilities are present.
  787.   /.printerror
  788.    { $error begin
  789.        /command load errorname SHORTERRORS
  790.     { (%%[ Error: ) print =only flush
  791.       (; OffendingCommand: ) print =only
  792.       errorinfo dup null eq {
  793.         pop
  794.       } {
  795.         (;\nErrorInfo:) print
  796.         dup type /arraytype eq
  797.           { { ( ) print =only } forall }
  798.           { ( ) print =only }
  799.         ifelse
  800.       } ifelse
  801.           ( ]%%) = flush
  802.     }
  803.     { (Error: ) print ==only flush
  804.       ( in ) print ==only flush
  805.       errorinfo dup null eq {
  806.         pop
  807.       } {
  808.         (\nAdditional information: ) print ==only flush
  809.       } ifelse
  810.       .printerror_long
  811.     }
  812.        ifelse
  813.        .clearerror
  814.      end
  815.      flush
  816.     } bind def     
  817.   /.printerror_long            % long error printout,
  818.                     % $error is on the dict stack
  819.    {    % Push the (anonymous) stack printing procedure.
  820.     %  <heading> <==flag> <override-name> <stackname> proc
  821.        {
  822.      currentdict exch .knownget    % stackname defined in $error?
  823.      {
  824.        4 1 roll            % stack: <stack> <head> <==flag> <over>
  825.        errordict exch .knownget    % overridename defined?
  826.        { 
  827.          exch pop exch pop exec    % call override with <stack>
  828.        }
  829.        { 
  830.          exch print exch        % print heading. stack <==flag> <stack>
  831.          1 index not { () = } if
  832.          { 1 index { (\n    ) } { (   ) } ifelse print
  833.            dup type /dicttype eq
  834.            {
  835.          (--dict:) print
  836.          dup rcheck {
  837.            dup length =only (/) print dup maxlength =only
  838.            dup wcheck not { ((ro)) print } if
  839.          } if
  840.          /gcheck where {
  841.            pop gcheck { ((G)) } { ((L)) } ifelse print
  842.          } {
  843.            pop
  844.          } ifelse (--) print
  845.            }
  846.            {
  847.          dup type /stringtype eq 2 index or
  848.          { ==only } { =only } ifelse
  849.            } ifelse
  850.          } forall
  851.          pop
  852.        }
  853.        ifelse            % overridden
  854.      }
  855.      { pop pop pop
  856.      }
  857.      ifelse                % stack known
  858.        }
  859.  
  860.        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  861.        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  862.        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  863.        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  864.        () =
  865.        pop    % printing procedure
  866.  
  867.        errorname /VMerror eq
  868.     { (VM status:) print mark vmstatus
  869.       counttomark { ( ) print counttomark -1 roll dup =only } repeat
  870.       cleartomark () =
  871.     } if
  872.  
  873.        .languagelevel 2 ge
  874.     { (Current allocation mode is ) print
  875.       globalmode { (global\n) } { (local\n) } ifelse print
  876.     } if
  877.  
  878.        .oserrno dup 0 ne
  879.     { (Last OS error: ) print
  880.       errorname /VMerror ne
  881.        { dup .oserrorstring { = pop } { = } ifelse }
  882.        { = }
  883.       ifelse
  884.     }
  885.     { pop
  886.     }
  887.        ifelse
  888.  
  889.        position null ne
  890.     { (Current file position is ) print position = }
  891.        if
  892.  
  893.    } bind def
  894. % Define a procedure for clearing the error indication.
  895. /.clearerror
  896.  { $error /newerror false put
  897.    $error /errorname null put
  898.    $error /errorinfo null put
  899.    0 .setoserrno
  900.  } bind def
  901.  
  902. % Define $error.  This must be in local VM.
  903. .currentglobal false .setglobal
  904. /$error 40 dict .forcedef    % $error is local, systemdict is global
  905.         % newerror, errorname, command, errorinfo,
  906.         % ostack, estack, dstack, recordstacks,
  907.         % binary, globalmode,
  908.         % .inerror, .nosetlocal, position,
  909.         % plus extra space for badly designed error handers.
  910. $error begin
  911.   /newerror false def
  912.   /recordstacks true def
  913.   /binary false def
  914.   /globalmode .currentglobal def
  915.   /.inerror false def
  916.   /.nosetlocal true def
  917.   /position null def
  918. end
  919. % Define errordict similarly.  It has one entry per error name,
  920. %   plus handleerror.  However, some astonishingly badly written PostScript
  921. %   files require it to have at least one empty slot.
  922. /errordict ErrorNames length 2 add dict
  923. .forcedef        % errordict is local, systemdict is global
  924. .setglobal        % contents of errordict are global
  925. errordict begin
  926.   ErrorNames
  927.    { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
  928.    } forall
  929. % The handlers for interrupt and timeout are special; there is no
  930. % 'current object', so they push their own name.
  931.    { /interrupt /timeout }
  932.    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  933.    } forall
  934. /handleerror
  935.  { /.printerror .systemvar exec
  936.  } bind def
  937. end
  938.  
  939. % Define the [write]==[only] procedures.
  940. /.dict 8 dict dup
  941. begin def
  942.   /.cvp {1 index exch 1 .writecvp} bind def
  943.   /.p {1 index exch writestring} bind def
  944.   /.p1 {2 index exch writestring} bind def
  945.   /.p2 {3 index exch writestring} bind def
  946.   /.print
  947.     { dup type .dict exch .knownget { exec } { .cvp } ifelse
  948.     } bind def
  949.   /arraytype
  950.     {dup rcheck
  951.       {() exch dup xcheck
  952.         {({) .p2
  953.          {exch .p1
  954.           1 index exch .print pop ( )} forall
  955.          (})}
  956.         {([) .p2
  957.          {exch .p1
  958.           1 index exch .print pop ( )} forall
  959.          (])}
  960.        ifelse exch pop .p}
  961.       {.cvp}
  962.      ifelse} bind def
  963.   /packedarraytype /arraytype load def
  964. {//.dict begin .print pop end}
  965.   bind
  966. end
  967.  
  968. /write==only exch def
  969. /write== {1 index exch write==only (\n) writestring} bind def
  970. /==only { (%stdout) (w) file exch write==only } bind def
  971. /== {==only (\n) print} bind def
  972.  
  973. % Define [write]===[only], an extension that prints dictionaries
  974. % in readable form and doesn't truncate strings.
  975. /.dict /write==only load 0 get dup length 2 add dict .copydict dup
  976. begin def
  977.   /dicttype
  978.     { dup rcheck
  979.        { (<< ) .p1
  980.           { 2 index 3 -1 roll .print pop ( ) .p1
  981.         1 index exch .print pop ( ) .p
  982.           }
  983.          forall (>>) .p
  984.        }
  985.        { .cvp
  986.        }
  987.       ifelse
  988.     } bind def
  989.   /stringtype
  990.     { 1 index exch 2 .writecvp
  991.     } bind def
  992.  
  993. {//.dict begin .print pop end}
  994.   bind
  995. end
  996.  
  997. /write===only exch def
  998. /write=== {1 index exch write===only (\n) writestring} bind def
  999. /===only { (%stdout) (w) file exch write===only } bind def
  1000. /=== { ===only (\n) print } bind def
  1001.  
  1002. (END PROCS) VMDEBUG
  1003.  
  1004. % Define the font directory.
  1005. /FontDirectory false .setglobal 100 dict true .setglobal
  1006. .forcedef        % FontDirectory is local, systemdict is global
  1007.  
  1008. % Define the encoding dictionary.
  1009. /EncodingDirectory 16 dict def    % enough for Level 2 + PDF standard encodings
  1010.  
  1011. % Define .findencoding.  (This is redefined in Level 2.)
  1012. /.findencoding
  1013.  { //EncodingDirectory exch get exec
  1014.  } bind def
  1015. /.defineencoding
  1016.  { //EncodingDirectory 3 1 roll put
  1017.  } bind def
  1018. % If we've got the composite font extensions, define findencoding.
  1019. % To satisfy the Genoa FTS, findencoding must be a procedure, not an operator.
  1020. /rootfont where { pop /findencoding { .findencoding } def } if
  1021.  
  1022. % Define .registerencoding.
  1023. % NOTE: the name registeredencodings is known to (initialized by and shared
  1024. % with) the interpreter.
  1025. /.registerencoding {    % <index> <array> .registerencoding -
  1026.     % Check that the array is indexable.
  1027.     % (It might still be a string, but then the .namestring will fail.)
  1028.   dup 0 0 getinterval pop
  1029.     % Check that all the elements of the array are names.
  1030.   dup { .namestring pop } forall
  1031.     % Do the store.
  1032.   //registeredencodings 2 index 2 index readonly put pop pop
  1033. } bind odef
  1034. systemdict /registeredencodings .undef
  1035.  
  1036. % Load StandardEncoding.
  1037. %% Replace 1 (gs_std_e.ps)
  1038. (gs_std_e.ps) dup runlibfile VMDEBUG
  1039.  
  1040. % Load ISOLatin1Encoding.
  1041. %% Replace 1 (gs_il1_e.ps)
  1042. (gs_il1_e.ps) dup runlibfile VMDEBUG
  1043.  
  1044. % Define stubs for the Symbol and Dingbats encodings.
  1045. % Note that the first element of the procedure must be the file name,
  1046. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  1047.  
  1048.   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  1049. %% Replace 3 (gs_sym_e.ps)
  1050.   EncodingDirectory /SymbolEncoding
  1051.    { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  1052.   bind put
  1053.  
  1054.   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  1055. %% Replace 3 (gs_dbt_e.ps)
  1056.   EncodingDirectory /DingbatsEncoding
  1057.    { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  1058.   bind put
  1059.  
  1060. (END FONTDIR/ENCS) VMDEBUG
  1061.  
  1062. % Construct a dictionary of all available devices.
  1063. % These are (read-only) device prototypes that can't be
  1064. % installed or have their parameters changed.  For this reason,
  1065. % the value in the dictionary is actually a 2-element writable array,
  1066. % to allow us to create a default instance of the prototype on demand.
  1067.  
  1068.     % Loop until the .getdevice gets a rangecheck.
  1069. errordict /rangecheck 2 copy get
  1070. errordict /rangecheck { pop stop } put    % pop the command
  1071.   0 { {dup .getdevice exch 1 add} loop} .internalstopped pop
  1072.   1 add dict  /devicedict 1 index def
  1073.   begin            % 2nd copy of count is on stack
  1074.    { dup .devicename exch
  1075.      dup wcheck { dup } { null } ifelse 2 array astore def
  1076.    } repeat
  1077.   end
  1078. put        % errordict /rangecheck
  1079. .clearerror
  1080. /devicenames devicedict { pop } forall devicedict length packedarray def
  1081.  
  1082. % Determine the default device.
  1083. /defaultdevice DISPLAYING
  1084.  { systemdict /DEVICE .knownget
  1085.     { devicedict 1 index known not
  1086.        { (Unknown device: ) print =
  1087.      flush /defaultdevice cvx 1 .quit
  1088.        }
  1089.       if
  1090.     }
  1091.     { 0 .getdevice .devicename
  1092.     }
  1093.    ifelse
  1094.  }
  1095.  { /nullpage
  1096.  }
  1097. ifelse
  1098. /.defaultdevicename 1 index def
  1099. finddevice    % make a copy
  1100. def
  1101. devicedict /Default devicedict .defaultdevicename get put
  1102.  
  1103. (END DEVS) VMDEBUG
  1104.  
  1105. % Define statusdict, for the benefit of programs
  1106. % that think they are running on a LaserWriter or similar printer.
  1107. %% Replace 1 (gs_statd.ps)
  1108. (gs_statd.ps) runlibfile
  1109.  
  1110. (END STATD) VMDEBUG
  1111.  
  1112. % Load the standard font environment.
  1113. %% Replace 1 (gs_fonts.ps)
  1114. (gs_fonts.ps) runlibfile
  1115.  
  1116. (END GS_FONTS) VMDEBUG
  1117.  
  1118. % Define the default halftone screen and BG/UCR functions now, so that
  1119. % it will bind in the original definitions of set[color]screen.
  1120. % We make this a procedure so we can call it again when switching devices.
  1121.  
  1122. % Use an ordered dither for low-resolution devices.
  1123. /.setloreshalftone {    % <dpi> .setloreshalftone -
  1124.     % The following 'ordered dither' spot function was contributed by
  1125.     % Gregg Townsend.  Thanks, Gregg!
  1126.    16.001 div 0            % not 16: avoids rounding problems
  1127.     { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1128.     0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1129.     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1130.     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1131.     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1132.     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1133.     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1134.     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1135.     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1136.     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1137.     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1138.     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1139.     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1140.     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1141.     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1142.     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1143.     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1144.      > exch get 256 div
  1145.     }
  1146.    bind
  1147.         % Use correct, per-plane screens for CMYK devices only.
  1148.    //systemdict /setcolorscreen known processcolors 4 eq and
  1149.     { 3 copy 6 copy //setcolorscreen }
  1150.     { //setscreen }
  1151.    ifelse
  1152. } bind def
  1153. /.setloresscreen {    % <dpi> .setloresscreen -
  1154.   .setloreshalftone
  1155.   0 array cvx settransfer    % Genoa CET won't accept a packed array!
  1156.   /setstrokeadjust where { pop true setstrokeadjust } if
  1157. } bind def
  1158. % Use a 45-degree spot screen for high-resolution devices.
  1159. /.sethireshalftone {    % <dpi> .sethireshalftone <doscreen>
  1160.     % According to information published by Hewlett-Packard,
  1161.     % they use a 60 line screen on 300 DPI printers and
  1162.     % an 85 line screen on 600 DPI printers.
  1163.     % However, we use a 106 line screen, which produces smoother-
  1164.     % looking shades but fewer of them (32 vs. 50).
  1165.     % 46 was suggested as a good frequency value for printers
  1166.     % between 200 and 400 DPI, so we use it for lower resolutions.
  1167.     % Imagesetters need even higher frequency screens.
  1168.    //systemdict /DITHERPPI known
  1169.     { DITHERPPI
  1170.     }
  1171.     { dup cvi 100 idiv 15 .min
  1172.        {null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
  1173.       exch get
  1174.      }
  1175.    ifelse
  1176.    1 index 4.01 div .min    % at least a 4x4 cell
  1177.    45
  1178.     % The following screen algorithm is used by permission of the author.
  1179.     { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
  1180.       1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
  1181.     }
  1182.    bind
  1183.     % Determine whether we have lots of process colors.
  1184.     % If so, don't bother with color screening or gamma correction.
  1185.     % Also don't do gamma correction on very high-resolution devices.
  1186.     % (This should depend on dot gain, not resolution, but we don't
  1187.     % currently have a way to determine this.)
  1188.    currentdevice mark
  1189.      /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1190.    .dicttomark .getdeviceparams
  1191.    counttomark 2 idiv 1 sub { exch pop min } repeat
  1192.    exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
  1193.     % Stack: doscreen dpi freq angle proc
  1194.     % Ghostscript currently doesn't use correct, per-plane halftones
  1195.     % unless setcolorscreen has been executed.  Since these are
  1196.     % computationally much more expensive than binary halftones,
  1197.     % we check to make sure they are really warranted, i.e., we have
  1198.     % a high-resolution CMYK device (i.e., not a display) with
  1199.     % fewer than 5 bits per plane (i.e., not a true-color device).
  1200.    4 -1 roll 150 ge
  1201.     { /setcolorscreen where
  1202.        { pop //systemdict /COLORSCREEN known
  1203.       { COLORSCREEN }
  1204.       { 3 index }
  1205.      ifelse
  1206.      dup false ne
  1207.       { 4 1 roll 3 copy 6 copy 13 -1 roll
  1208.     % For really high-quality screening on printers, we need to
  1209.     % give each plane its own screen angle.  Unfortunately,
  1210.     % this currently has very large space and time costs.
  1211.         true eq        % true => different angles,
  1212.                 % 0 => same angles
  1213.          { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1214.          }
  1215.         if //setcolorscreen
  1216.       }
  1217.       { pop //setscreen    % false => single binary screen
  1218.       }
  1219.      ifelse
  1220.        }
  1221.        { //setscreen        % setcolorscreen not known
  1222.        }
  1223.       ifelse
  1224.     }
  1225.     { //setscreen            % not high resolution
  1226.     }
  1227.    ifelse
  1228. } bind def
  1229. /.sethiresscreen {    % <dpi> .sethiresscreen -
  1230.   .sethireshalftone
  1231.             % Stack: doscreen
  1232.     {    % Set the transfer function to lighten up the grays.
  1233.     % We correct at the high end so that very light grays
  1234.     % don't disappear completely if they darken <1 screen pixel.
  1235.     % Parameter values closer to 1 are better for devices with
  1236.     % less dot spreading; lower values are better with more spreading.
  1237.     % The value 0.8 is a compromise that will probably please no one!
  1238.     %
  1239.     % Because of a bug in FrameMaker, we have to accept operands
  1240.     % outside the valid range of [0..1].
  1241.       { dup dup 0.0 gt exch 1.0 lt and
  1242.      { 0.8 exp dup dup 0.9375 gt exch 0.999 lt and    % > 15/16
  1243.         { .currentscreenlevels 1 sub    % tweak to avoid boundary
  1244.           1 exch div 1 exch sub .min
  1245.         }
  1246.        if
  1247.      }
  1248.     if
  1249.       }
  1250.     }
  1251.     {    % Set the transfer function to the identity.
  1252.       0 array cvx        % Genoa CET won't accept a packed array!
  1253.     }
  1254.    ifelse settransfer
  1255.    /setstrokeadjust where { pop false setstrokeadjust } if
  1256.     % Increase fill adjustment so that we effectively use Adobe's
  1257.     % any-part-of-pixel rule.
  1258.    0.5 .setfilladjust
  1259. } bind def
  1260. % Set the default screen and BG/UCR.
  1261. /.setdefaultbgucr {
  1262.   systemdict /setblackgeneration known {
  1263.     { pop 0 } dup setblackgeneration setundercolorremoval
  1264.   } if
  1265. } bind def
  1266. /.useloresscreen {    % - .useloresscreen <bool>
  1267.     % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1268.   72 72 matrix defaultmatrix dtransform abs exch abs .min
  1269.   dup 150 lt //systemdict /DITHERPPI known not and
  1270. } bind def
  1271.  
  1272. % The following implementation uses LL2 extensions, but only in stopped
  1273. % contexts so that with LL1, the .set??reshalftone will be used.
  1274. %
  1275. %    - .getdefaulthalftone <halftonedict> true    if default found
  1276. %                  false            
  1277. /.getdefaulthalftone {
  1278.   % try the device to see if it has a default halftone
  1279.   { currentdevice /HalftoneDefault gsgetdeviceprop } stopped
  1280.   { pop pop false }        % no device property
  1281.   { dup type /dicttype eq { true } { pop false } ifelse }
  1282.   ifelse
  1283.   % stack: <halftonedict> true    if default found
  1284.   %         false          not found
  1285.   dup not
  1286.   { % device did not provide a default, try Resource
  1287.     pop { /Default /Halftone /findresource .systemvar exec } stopped 
  1288.     { pop pop false } { true } ifelse
  1289.   }
  1290.   if
  1291. } bind def
  1292.  
  1293. /.setdefaulthalftone {
  1294.   .getdefaulthalftone 
  1295.   { sethalftone }
  1296.   { % default not found
  1297.     .useloresscreen { .setloreshalftone } { .sethireshalftone pop } ifelse
  1298.   }
  1299.   ifelse
  1300. } bind def
  1301.  
  1302. /.setdefaultscreen {
  1303.   .useloresscreen { .setloresscreen } { .sethiresscreen } ifelse
  1304.   .setdefaultbgucr
  1305. } bind def
  1306.  
  1307. % Load the initialization files for optional features.
  1308. %% Replace 4 INITFILES
  1309. systemdict /INITFILES known
  1310.  { INITFILES { dup runlibfile VMDEBUG } forall
  1311.  }
  1312. if
  1313.  
  1314. % If Level 2 (or higher) functionality is implemented, enable it now.
  1315. /.setlanguagelevel where {
  1316.   pop 2 .setlanguagelevel
  1317.     % If the resource machinery is loaded, fix up some things now.
  1318.   /.fixresources where { pop .fixresources } if
  1319. } if
  1320. /ll3dict where {
  1321.   pop 3 .setlanguagelevel
  1322. } if
  1323.  
  1324. (END INITFILES) VMDEBUG
  1325.  
  1326. % Create a null font.  This is the initial font.
  1327. 8 dict dup begin
  1328.   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  1329.   /FontType 3 def
  1330.   /FontName () def
  1331.   /Encoding StandardEncoding def
  1332.   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  1333.   /BuildChar { pop pop 0 0 setcharwidth } bind def
  1334.   /PaintType 0 def        % shouldn't be needed!
  1335. end
  1336. /NullFont exch definefont setfont
  1337.  
  1338. % Define NullFont as the font.
  1339. /NullFont currentfont def
  1340.  
  1341. % Load initial fonts from FONTPATH directories, Fontmap file,
  1342. % and/or .getccfont as appropriate.
  1343. .loadinitialfonts
  1344.  
  1345. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  1346. /undefinefont where {
  1347.   pop /NullFont undefinefont
  1348. } {
  1349.   FontDirectory /NullFont .undef
  1350. } ifelse
  1351.  
  1352. (END FONTS) VMDEBUG
  1353.  
  1354. % Restore the real definition of runlibfile.
  1355. /runlibfile /.runlibfile load def
  1356. currentdict /.runlibfile .undef
  1357.  
  1358. % Bind all the operators defined as procedures.
  1359. /.bindoperators        % binds operators in currentdict
  1360.  { % Temporarily disable the typecheck error.
  1361.    errordict /typecheck 2 copy get
  1362.    errordict /typecheck { pop } put    % pop the command
  1363.    currentdict
  1364.     { dup type /operatortype eq
  1365.        { % This might be a real operator, so bind might cause a typecheck,
  1366.      % but we've made the error a no-op temporarily.
  1367.      .bind        % do a real bind even if NOBIND is set
  1368.        }
  1369.       if pop pop
  1370.     } forall
  1371.    put
  1372.  } def
  1373. NOBIND DELAYBIND or not { .bindoperators } if
  1374.  
  1375. % Establish a default environment.
  1376.  
  1377. defaultdevice
  1378. % The following line used to skip setting of page size and resolution if
  1379. % NODISPLAY was selected.  We think this was only to save time and memory,
  1380. % and it is a bad idea because it prevents setting the resolution in this
  1381. % situation, which pstoedit (among other programs) relies on.
  1382. %DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1383. systemdict /DEVICEWIDTH known
  1384. systemdict /DEVICEHEIGHT known or
  1385. systemdict /DEVICEWIDTHPOINTS known or
  1386. systemdict /DEVICEHEIGHTPOINTS known or
  1387. systemdict /DEVICEXRESOLUTION known or
  1388. systemdict /DEVICEYRESOLUTION known or
  1389. systemdict /PAPERSIZE known or
  1390. not { (%END DEVICE) .skipeof } if
  1391. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1392. systemdict /PAPERSIZE known
  1393. systemdict /DEVICEWIDTH known not and
  1394. systemdict /DEVICEHEIGHT known not and
  1395. systemdict /DEVICEWIDTHPOINTS known not and
  1396. systemdict /DEVICEHEIGHTPOINTS known not and
  1397.  {    % Convert the paper size to device dimensions.
  1398.    true statusdict /.pagetypenames get
  1399.     { PAPERSIZE eq
  1400.        { PAPERSIZE load
  1401.          dup 0 get /DEVICEWIDTHPOINTS exch def
  1402.          1 get /DEVICEHEIGHTPOINTS exch def
  1403.          pop false exit
  1404.        }
  1405.       if
  1406.     }
  1407.    forall
  1408.     { (Unknown paper size: ) print PAPERSIZE ==only (.) =
  1409.     }
  1410.    if
  1411.  }
  1412. if
  1413. % Adjust the device parameters per the command line.
  1414. % It is possible to specify resolution, pixel size, and page size;
  1415. % since any two of these determine the third, conflicts are possible.
  1416. % We simply pass them to .setdeviceparams and let it sort things out.
  1417.    mark /HWResolution null /HWSize null /PageSize null .dicttomark
  1418.    .getdeviceparams .dicttomark begin
  1419.    mark
  1420.     % Check for resolution.
  1421.    /DEVICEXRESOLUTION where dup
  1422.     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  1423.    if
  1424.    /DEVICEYRESOLUTION where dup
  1425.     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  1426.    if
  1427.    or { /HWResolution HWResolution } if
  1428.     % Check for device sizes specified in pixels.
  1429.    /DEVICEWIDTH where dup
  1430.     { exch pop HWSize 0 DEVICEWIDTH put }
  1431.    if
  1432.    /DEVICEHEIGHT where dup
  1433.     { exch pop HWSize 1 DEVICEHEIGHT put }
  1434.    if
  1435.    or { /HWSize HWSize } if
  1436.     % Check for device sizes specified in points.
  1437.    /DEVICEWIDTHPOINTS where dup
  1438.     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  1439.    if
  1440.    /DEVICEHEIGHTPOINTS where dup
  1441.     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  1442.    if
  1443.    or { /PageSize PageSize } if
  1444.     % Check whether any parameters were set.
  1445.    dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
  1446.    end
  1447. %END DEVICE
  1448. % Set any device properties defined on the command line.
  1449. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  1450. systemdict /BufferSpace known
  1451. systemdict /MaxBitmap known not and
  1452.  { systemdict /MaxBitmap BufferSpace put
  1453.  } if
  1454. dup getdeviceprops
  1455. counttomark 2 idiv
  1456.  { systemdict 2 index known
  1457.     { pop dup load counttomark 2 roll }
  1458.     { pop pop }
  1459.    ifelse
  1460.  } repeat
  1461. counttomark dup 0 ne
  1462.  { 2 add -1 roll putdeviceprops }
  1463.  { pop pop }
  1464. ifelse
  1465. % If the initial device parameters are invalid, the setdevice may fail.
  1466. % Trap this and produce a reasonable error message.
  1467. { setdevice }        % does an erasepage
  1468. DEBUG { exec false } { .internalstopped } ifelse {
  1469.   (**** Unable to open the initial device, quitting.) = 1 .quit
  1470. } if
  1471.  
  1472. % If the media size is fixed, update the current page device dictionary.
  1473. FIXEDMEDIA
  1474. dup { pop systemdict /.currentpagedevice known } if
  1475. dup { pop .currentpagedevice exch pop } if
  1476. not { (%END MEDIA) .skipeof } if
  1477. currentpagedevice dup length dict .copydict
  1478. dup /Policies
  1479.     % Stack: <pagedevice> <pagedevice> /Policies
  1480. 1 index /InputAttributes
  1481. 2 copy get dup length dict .copydict
  1482.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1483.     %   /InputAttributes <inputattrs'>
  1484. dup 0 2 copy get dup length dict .copydict
  1485.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1486.     %   /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
  1487. dup /PageSize 7 index /PageSize get
  1488. put                % PageSize in 0
  1489. put                % 0 in InputAttributes
  1490. put                % InputAttributes in pagedevice
  1491. % Also change the page size policy so we don't get an error.
  1492.     % Stack: <pagedevice> <pagedevice> /Policies
  1493. 2 copy get dup length dict .copydict
  1494.     % Stack: <pagedevice> <pagedevice> /Policies <policies'>
  1495. dup /PageSize 7 put        % PageSize in Policies
  1496. put                % Policies in pagedevice
  1497. .setpagedevice
  1498. %END MEDIA
  1499. %END DISPLAYING
  1500.  
  1501. (END DEVICE) VMDEBUG
  1502.  
  1503. % Establish a default upper limit in the character cache,
  1504. % namely, enough room for a 18-point character at the resolution
  1505. % of the default device, or for a character consuming 1% of the
  1506. % maximum cache size, whichever is larger.
  1507. mark
  1508.     % Compute limit based on character size.
  1509.   18 dup dtransform
  1510.   exch abs cvi 31 add 32 idiv 4 mul    % X raster
  1511.   exch abs cvi mul        % Y
  1512.     % Compute limit based on allocated space.
  1513.   cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  1514.   .max dup 10 idiv exch
  1515. setcacheparams
  1516. % Conditionally disable the character cache.
  1517. NOCACHE { 0 setcachelimit } if
  1518.  
  1519. (END CONFIG) VMDEBUG
  1520.  
  1521. % Initialize graphics.
  1522.  
  1523. .setdefaultscreen
  1524. initgraphics
  1525.  
  1526. % The interpreter relies on there being at least 2 entries
  1527. % on the graphics stack.  Establish the second one now.
  1528. gsave
  1529.  
  1530. % Define some control sequences as no-ops.
  1531. % This is a hack to get around problems
  1532. % in some common PostScript-generating applications.
  1533. <04> cvn { } def        % Apple job separator
  1534. <0404> cvn { } def        % two of the same
  1535. <1b> cvn { } def        % MS Windows LaserJet 4 prologue
  1536.                 % (UEL = ESC %-12345X)
  1537. <1b45> cvn { } def        % PJL reset prologue (ESC E)
  1538. <1b451b> cvn { } def        % PJL reset epilogue (ESC E + UEL)
  1539. <041b> cvn { } def        % MS Windows LaserJet 4 epilogue (^D + UEL)
  1540. (\001M) cvn            % TBCP initiator
  1541.  { currentfile /TBCPDecode filter cvx exec
  1542.  } bind def
  1543. /@PJL                % H-P job control
  1544.  { currentfile //=string readline { pop } if
  1545.  } bind def
  1546.  
  1547. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1548. SAFER not { (%END SAFER) .skipeof } if
  1549.  
  1550. .currentglobal true .setglobal
  1551. /SAFETY 1 dict dup /safe DELAYSAFER not put readonly def
  1552. .setglobal
  1553.  
  1554. /.setsafe
  1555.   { //SAFETY /safe //true .forceput % overrides readonly
  1556.   } .bind executeonly odef
  1557.  
  1558. /file
  1559.  { //SAFETY /safe get {
  1560.      dup (r) eq 2 index (%pipe*) .stringmatch not and
  1561.      2 index (%std*) .stringmatch or
  1562.        { file }
  1563.        { /invalidfileaccess //signalerror exec }
  1564.      ifelse
  1565.    } {
  1566.      file
  1567.    } ifelse
  1568.  } .bind executeonly odef
  1569.  
  1570. /renamefile
  1571.   { //SAFETY /safe get
  1572.       { /invalidfileaccess //signalerror exec }
  1573.       { renamefile }
  1574.     ifelse
  1575.   } .bind executeonly odef
  1576.  
  1577.  
  1578. /deletefile
  1579.   { //SAFETY /safe get
  1580.       { /invalidfileaccess //signalerror exec }
  1581.       { deletefile }
  1582.     ifelse
  1583.   } .bind executeonly odef
  1584.  
  1585. /putdeviceprops
  1586.  { //SAFETY /safe get { 
  1587.      counttomark
  1588.      dup 2 mod 0 eq { pop /rangecheck //signalerror exec } if
  1589.      3 2 3 2 roll
  1590.       { dup index /OutputFile eq  
  1591.          { -2 roll 
  1592.            dup () ne
  1593.              { /putdeviceprops load /invalidfileaccess //signalerror exec
  1594.              } if
  1595.          3 -1 roll
  1596.          }
  1597.          { pop
  1598.          }
  1599.         ifelse
  1600.       } for
  1601.      putdeviceprops
  1602.    } {
  1603.      putdeviceprops
  1604.    } ifelse
  1605.  } .bind executeonly odef
  1606.  
  1607. currentdict /SAFETY undef
  1608.  
  1609. %END SAFER
  1610.  
  1611. % If we delayed binding, make it possible to do it later.
  1612. /.bindnow {
  1613.   //systemdict begin .bindoperators end
  1614.   % Temporarily disable the typecheck error.
  1615.   errordict /typecheck 2 copy get
  1616.   errordict /typecheck { pop } put    % pop the command
  1617.   0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  1618.   //systemdict /.delaybind {} .forceput    % reclaim the space
  1619.   //systemdict /.bindnow .forceundef    % ditto
  1620.   put
  1621.   //systemdict /.forcedef .forceundef        % remove temptation
  1622.   //systemdict /.forceput .forceundef        % ditto
  1623.   //systemdict /.forceundef .forceundef        % ditto
  1624. } .bind odef
  1625.  
  1626. % Turn off array packing, since some PostScript code assumes that
  1627. % procedures are writable.
  1628. false setpacking
  1629.  
  1630. (END INIT) VMDEBUG
  1631.  
  1632. /.currentuserparams where {
  1633.   pop
  1634.     % Remove real user params from psuserparams.
  1635.   mark .currentuserparams counttomark 2 idiv {
  1636.     pop psuserparams exch undef
  1637.   } repeat pop
  1638.     % Update the copy of the user parameters.
  1639.   mark .currentuserparams counttomark 2 idiv {
  1640.     userparams 3 1 roll .forceput    % userparams is read-only
  1641.   } repeat pop
  1642.     % Turn on idiom recognition, if available.
  1643.   currentuserparams /IdiomRecognition known {
  1644.     /IdiomRecognition true .definepsuserparam
  1645.   } if
  1646.   psuserparams readonly pop
  1647.   systemdict /.definepsuserparam undef
  1648.     % Save a copy of userparams for use with save/restore
  1649.     % (and, if implemented, context switching).
  1650.   .currentglobal false .setglobal
  1651.      mark userparams { } forall .dicttomark readonly
  1652.      /userparams exch .forcedef        % systemdict is read-only
  1653.   .setglobal
  1654. } if
  1655. /.currentsystemparams where {
  1656.   pop
  1657.     % Remove real system params from pssystemparams.
  1658.   mark .currentsystemparams counttomark 2 idiv {
  1659.     pop pssystemparams exch .forceundef
  1660.   } repeat pop
  1661. } if
  1662.  
  1663. % Conditionally turn image interpolation on or off.
  1664. currentdict /INTERPOLATE known not { (%END INTERPOLATE) .skipeof } if
  1665.  
  1666. /.interpolate {
  1667.   dup /Interpolate .knownget not { //false } if
  1668.   /INTERPOLATE .systemvar ne {
  1669.     dup gcheck .currentglobal exch .setglobal
  1670.     exch dup length dict copy
  1671.     dup /Interpolate /INTERPOLATE .systemvar put
  1672.     exch .setglobal
  1673.   } if
  1674. } bind odef
  1675.  
  1676. /colorimage
  1677.   { /INTERPOLATE .systemvar
  1678.       { .currentglobal                    % w h bit [] {}...{} multi ncomp glob
  1679.         //false .setglobal
  1680.         9 dict begin                      % w h bit [] {}...{} multi ncomp glob
  1681.         2 index { 1 index 7 add } { 8 } ifelse
  1682.         copy gsave pop                    % preserve the arguments
  1683.         { 0 /DeviceGray 0 /DeviceRGB /DeviceCMYK }
  1684.         1 index get setcolorspace         % ... glob w h bit [] {}...{} multi ncomp
  1685.         {0 1 0 1 0 1 0 1}
  1686.         1 index 2 mul 0 exch              % ... glob w h bit [] {}...{} multi ncomp {0 1 ...} 0 2*ncomp
  1687.         getinterval /Decode exch def      % ... glob w h bit [] {}...{} multi ncomp
  1688.         exch dup                          % ... glob w h bit [] {}...{} ncomp multi multi
  1689.         /MultipleDataSources exch def     % ... glob w h bit [] {}...{} ncomp multi
  1690.         { array astore} { pop } ifelse    % ... glob w h bit [] [{}...{}]
  1691.         /DataSource exch def              % ... glob w h bit []
  1692.         /ImageMatrix exch def             % ... glob w h bit
  1693.         /BitsPerComponent exch def        % ... glob w h
  1694.         /Height exch def                  % ... glob w
  1695.         /Width exch def                   % ... glob 
  1696.         /ImageType 1 def
  1697.         /Interpolate //true def
  1698.         .setglobal currentdict end        % ... <<>>
  1699.         image grestore
  1700.         exch { 4 add } { 6 } ifelse
  1701.         { pop } repeat                    % -
  1702.       }
  1703.       { colorimage
  1704.       }
  1705.     ifelse
  1706.   } bind odef
  1707.  
  1708. /image
  1709.   { dup type /dicttype eq
  1710.       { dup /ImageType get 3 eq
  1711.           { .currentglobal //false .setglobal exch
  1712.             dup length dict copy begin .setglobal 
  1713.             /DataDict DataDict .interpolate def
  1714.             /MaskDict MaskDict .interpolate def
  1715.             currentdict end
  1716.           }
  1717.           { .interpolate 
  1718.           }
  1719.         ifelse
  1720.         image
  1721.       }
  1722.       { /INTERPOLATE .systemvar
  1723.           { .currentglobal //false .setglobal
  1724.             8 dict begin .setglobal
  1725.             /ImageType 1 def
  1726.             /DataSource 1 index def
  1727.             /ImageMatrix 2 index def
  1728.             /BitsPerComponent 3 index def
  1729.             /Decode {0 1} def
  1730.             /Height 4 index def
  1731.             /Width 5 index def
  1732.             /Interpolate //true def
  1733.             currentdict end
  1734.             gsave /DeviceGray setcolorspace image grestore
  1735.             5 { pop } repeat
  1736.           }
  1737.           { image
  1738.           }
  1739.         ifelse
  1740.       }
  1741.     ifelse
  1742.   } bind odef
  1743.  
  1744. /imagemask {
  1745.   dup type /dicttype eq {
  1746.     .interpolate imagemask
  1747.   } {
  1748.     /INTERPOLATE .systemvar {
  1749.       .currentglobal //false .setglobal
  1750.       8 dict begin .setglobal
  1751.       /ImageType 1 def
  1752.       /DataSource 1 index def
  1753.       /ImageMatrix 2 index def
  1754.       /BitsPerComponent 1 def
  1755.       2 index { {1 0} } { {0 1} } ifelse /Decode exch def
  1756.       /Height 4 index def
  1757.       /Width 5 index def
  1758.       /Interpolate //true def
  1759.       currentdict end imagemask 5 { pop } repeat
  1760.     } {
  1761.       imagemask
  1762.     } ifelse
  1763.   } ifelse
  1764. } bind odef
  1765.  
  1766. currentdict /.interpolate undef
  1767.  
  1768. %END INTERPOLATE
  1769.  
  1770. % Establish local VM as the default.
  1771. false /setglobal where { pop setglobal } { .setglobal } ifelse
  1772. $error /.nosetlocal false put
  1773.  
  1774. (END GLOBAL) VMDEBUG
  1775.  
  1776. /.savelocalstate where {
  1777.     % If we might create new contexts, save away copies of all dictionaries
  1778.     % referenced from systemdict that are stored in local VM,
  1779.     % and also save a copy of the initial gstate.
  1780.   pop .savelocalstate
  1781. } {
  1782.     % If we're *not* running in a multi-context system and FAKEFONTS is
  1783.     % defined, add the fake fonts to LocalFontDirectory.
  1784.   .definefakefonts    % current VM is local
  1785. } ifelse
  1786.  
  1787. % Remove systemdict entries for things that have been bound in where used
  1788. % and that shouldn't be accessible by name, and close up systemdict.
  1789. currentdict /filterdict .undef
  1790. currentdict /.cidfonttypes .undef
  1791. currentdict /.colorrenderingtypes .undef
  1792. currentdict /.formtypes .undef
  1793. currentdict /.halftonetypes .undef
  1794. currentdict /.imagetypes .undef
  1795. currentdict /.imagemasktypes .undef
  1796. currentdict /.patterntypes .undef
  1797. currentdict /.shadingtypes .undef
  1798. currentdict /.wheredict .undef
  1799. end
  1800.  
  1801. % Clean up VM, and enable GC.
  1802. /vmreclaim where
  1803.  { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  1804.  } if
  1805. DELAYBIND not {
  1806.   systemdict /.forcedef .undef        % remove temptation
  1807.   systemdict /.forceput .undef        % ditto
  1808.   systemdict /.forceundef .undef    % ditto
  1809. } if
  1810. WRITESYSTEMDICT not { systemdict readonly pop } if
  1811.  
  1812. (END GC) VMDEBUG
  1813.  
  1814. % The interpreter will run the initial procedure (start).
  1815.