home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / gs-esp / 8.15 / lib / gs_init.ps < prev    next >
Encoding:
Text File  |  2006-07-06  |  71.1 KB  |  2,249 lines

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