home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gs333ini / gs3.33 / gs_lev2.ps < prev    next >
Text File  |  1995-12-09  |  10KB  |  312 lines

  1. %    Copyright (C) 1990, 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % Initialization file for Level 2 functions.
  16. % When this is run, systemdict is still writable,
  17. % but (almost) everything defined here goes into level2dict.
  18.  
  19. level2dict begin
  20.  
  21. % ------ Miscellaneous ------ %
  22.  
  23. (<<) cvn /mark load def
  24. (>>) cvn /.dicttomark load odef
  25. /currentsystemparams { mark .currentsystemparams .dicttomark } odef
  26. /currentuserparams { mark .currentuserparams .dicttomark } odef
  27. /deviceinfo { currentdevice getdeviceprops .dicttomark } odef
  28. /languagelevel 2 def
  29. /realtime /usertime load def
  30. % When running in Level 2 mode, this interpreter is supposed to be
  31. % compatible with PostScript version 2010 (I think).
  32. /version (2010) def
  33.  
  34. % If binary tokens are supported by this interpreter,
  35. % set an appropriate default binary object format.
  36. /setobjectformat where
  37.  { pop
  38.    currentsystemparams dup
  39.    /RealFormat get (IEEE) eq { 1 } { 3 } ifelse
  40.    exch /ByteOrder get { 1 add } if
  41.    setobjectformat
  42.  } if
  43.  
  44. % ------ Virtual memory ------ %
  45.  
  46. /currentglobal /currentshared load def
  47. /gcheck /scheck load def
  48. /setglobal /setshared load def
  49. % We can make the global dictionaries very small, because they auto-expand.
  50. /globaldict currentdict /shareddict .knownget not { 4 dict } if def
  51. /GlobalFontDirectory SharedFontDirectory def
  52.  
  53. % ------ IODevices ------ %
  54.  
  55. /.getdevparams where
  56.  { pop /currentdevparams { .getdevparams .dicttomark } odef
  57.  } if
  58. /.putdevparams where
  59.  { pop /setdevparams { mark { } forall counttomark 2 add -1 roll .putdevparams } odef
  60.  } if
  61.  
  62. % ------ Job control ------ %
  63.  
  64. serverdict begin
  65.  
  66. % We could protect the job information better, but we aren't attempting
  67. % (currently) to protect ourselves against maliciousness.
  68.  
  69. /.jobsave null def        % top-level save object
  70. /.jobsavelevel 0 def        % save depth of job (0 if .jobsave is null,
  71.                 % 1 otherwise)
  72. /.adminjob true def        % status of current unencapsulated job
  73.  
  74. /exitserver
  75.  { true exch startjob not { /exitserver /invalidaccess signalerror } if
  76.  } bind def
  77.  
  78. end        % serverdict
  79.  
  80. %**************** The definition of startjob is not complete yet, since
  81. % it doesn't clear the exec stack, doesn't reset stdin/stdout,
  82. % doesn't run the job under its own control, and doesn't reset
  83. % other aspects of the interpreter.
  84. /startjob
  85.  { vmstatus pop pop serverdict /.jobsavelevel get eq
  86.    1 index .checkpassword 0 gt and
  87.     { .checkpassword count 2 roll count 2 sub { pop } repeat
  88.       cleardictstack
  89.       serverdict /.jobsave get dup null eq { pop } { restore } ifelse
  90.       exch
  91.        {    % unencapsulated job
  92.      serverdict /.jobsave null put
  93.      serverdict /.jobsavelevel 0 put
  94.      serverdict /.adminjob 3 -1 roll 1 gt put
  95.        }
  96.        {    % encapsulated job
  97.      serverdict /.jobsave save put
  98.      serverdict /.jobsavelevel 1 put
  99.      userdict /quit /stop load put
  100.      pop
  101.        }
  102.       ifelse true
  103.     }
  104.     { pop pop false
  105.     }
  106.    ifelse
  107.  } odef
  108.  
  109. systemdict begin
  110. /quit
  111.  { //systemdict /serverdict get /.jobsave get null eq
  112.     { //quit }
  113.     { //systemdict /quit get /invalidaccess signalerror }
  114.    ifelse
  115.  } bind odef
  116. end
  117.  
  118. % ------ Compatibility ------ %
  119.  
  120. % In Level 2 mode, the following replace the definitions that gs_statd.ps
  121. % installs in statusdict and serverdict.
  122. % Note that statusdict must be allocated in local VM.
  123. % We don't bother with many of these yet, and the ones defined in terms
  124. % of currentsystemparams are cavalier about allocating a dictionary
  125. % in order to retrieve a single element from it....
  126.  
  127. /.dict1 { exch mark 3 1 roll .dicttomark } bind def
  128.  
  129. currentglobal false setglobal 25 dict exch setglobal begin
  130. currentsystemparams
  131.  
  132. /buildtime 1 index /BuildTime get def
  133. /byteorder 1 index /ByteOrder get def
  134. /checkpassword { .checkpassword 0 gt } bind def
  135. /defaulttimeouts
  136.  { currentsystemparams dup
  137.    /JobTimeout .knownget not { 0 } if
  138.    exch /WaitTimeout .knownget not { 0 } if
  139.    currentpagedevice /ManualFeedTimeout .knownget not { 0 } if
  140.  } bind def
  141. dup /DoStartPage known
  142.  { /dostartpage { currentsystemparams /DoStartPage get } bind def
  143.    /setdostartpage { /DoStartPage .dict1 setsystemparams } bind def
  144.  } if
  145. dup /StartupMode known
  146.  { /dosysstart { currentsystemparams /StartupMode get 0 ne } bind def
  147.    /setdosysstart { { 1 } { 0 } ifelse /StartupMode .dict1 setsystemparams } bind def
  148.  } if
  149. %****** Setting jobname is supposed to set userparams.JobName, too.
  150. /jobname { currentuserparams /JobName get } bind def
  151. /jobtimeout { currentuserparams /JobTimeout get } bind def
  152. %manualfeed
  153. %manualfeedtimeout
  154. /margins
  155.  { currentpagedevice /Margins .knownget { exch } { [0 0] } ifelse
  156.  } bind def
  157. %pagecount
  158. %pagestackorder
  159. /printername
  160.  { currentsystemparams /PrinterName .knownget not { () } if exch copy
  161.  } bind def
  162. %/ramsize { currentsystemparams /RamSize get } bind def
  163. /realformat 1 index /RealFormat get def
  164.  
  165. /.setpagedevice where
  166.  { pop
  167.    /setdefaulttimeouts
  168.     { exch mark /ManualFeedTimeout 3 -1 roll
  169.       /Policies mark /ManualFeedTimeout 1 .dicttomark
  170.       .dicttomark setpagedevice
  171.       /WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams
  172.     } bind def
  173.    /setmargins
  174.     { exch 2 array astore /Margins .dict1 setpagedevice
  175.     } bind def
  176.  }
  177. if
  178. %setpagestackorder
  179. dup /PrinterName known
  180.  { /setprintername { /PrinterName .dict1 setsystemparams } bind def
  181.  } if
  182. currentuserparams /WaitTimeout known
  183.  { /waittimeout { currentuserparams /WaitTimeout get } bind def
  184.  } if
  185.  
  186. /.setpagedevice where
  187.  { pop 
  188.    /.setpagesize { 2 array astore /PageSize .dict1 setpagedevice } bind def
  189.    /setduplexmode { /Duplex .dict1 setpagedevice } bind def
  190.    /setpageparams
  191.     {    % We don't actually set the orientation yet.
  192.     %currentpagedevice /Orientation known not { pop 0 } if
  193.       mark /PageSize 6 -2 roll
  194.       4 index ORIENT1 { 1 } { 0 } ifelse ne { exch } if 2 array astore
  195.       /Orientation 5 -1 roll
  196.     pop pop %
  197.       /Margins counttomark 2 add -1 roll 0 2 array astore
  198.       .dicttomark setpagedevice
  199.     } bind def
  200.    /setresolution
  201.     { dup 2 array astore /HWResolution .dict1 setpagedevice
  202.     } bind def
  203.  }
  204. if
  205.  
  206. pop        % currentsystemparams
  207.  
  208. % Flag the current dictionary so it will be swapped when we
  209. % change language levels.  (See zmisc2.c for more information.)
  210. /statusdict currentdict def
  211.  
  212. currentdict end
  213. /statusdict exch def
  214.  
  215. % ------ Color spaces ------ %
  216.  
  217. % Define the setcolorspace procedures.
  218. /colorspacedict mark
  219.   /DeviceGray { pop 0 setgray } bind
  220.   /DeviceRGB { pop 0 0 0 setrgbcolor } bind
  221.   /setcmykcolor where
  222.    { pop /DeviceCMYK { pop 0 0 0 1 setcmykcolor } bind
  223.    } if
  224.   /.setcieaspace where
  225.    { pop /CIEBasedA { NOCIE { pop 0 setgray } { 1 get .setcieaspace } ifelse } bind
  226.    } if
  227.   /.setcieabcspace where
  228.    { pop /CIEBasedABC { NOCIE { pop 0 0 0 setrgbcolor } { 1 get .setcieabcspace } ifelse } bind
  229.    } if
  230.   /.setseparationspace where
  231.    { pop /Separation { dup 2 get setcolorspace .setseparationspace } bind
  232.    } if
  233.   /.setindexedspace where
  234.    { pop /Indexed { dup 1 get setcolorspace .setindexedspace } bind
  235.    } if
  236.   /.setpatternspace where
  237.    { pop /Pattern
  238.       { dup length 1 gt { dup 1 get setcolorspace } if
  239.         .setpatternspace
  240.       } bind
  241.    } if
  242. .dicttomark def
  243.  
  244. /.devcs [/DeviceGray /DeviceRGB /DeviceCMYK] readonly def
  245. /currentcolorspace
  246.  { .currentcolorspace dup type /integertype eq
  247.     { //.devcs exch 1 getinterval
  248.     } if
  249.  } odef
  250. currentdict /.devcs undef
  251.  
  252. /setcolorspace
  253.  { dup type /nametype eq { 1 array astore } if
  254.    dup //colorspacedict 1 index 0 get get exec
  255.    .setcolorspace
  256.  } odef
  257.  
  258. % Initialize the CIE rendering dictionary if necessary.
  259. % The most common CIE files seem to assume the "calibrated RGB color space"
  260. % described on p. 189 of the PostScript Language Reference Manual,
  261. % 2nd Edition; we simply invert this transformation back to RGB.
  262. /setcolorrendering where
  263.  { pop mark
  264.    /ColorRenderingType 1
  265.    /MatrixABC
  266.     [ 3.24063 -0.96893  0.05571
  267.      -1.53721  1.87576 -0.20402
  268.      -0.49863  0.04152  1.05700
  269.     ]
  270.    /EncodeABC [{0 max 0.45 exp} bind dup dup]
  271.    /WhitePoint [0.9505 1 1.0890]
  272.    /TransformPQR [ { 4 { exch pop } repeat } dup dup ]
  273.    .dicttomark setcolorrendering
  274.  } if
  275.  
  276. % ------ Painting ------ %
  277.  
  278. % A straightforward definition of execform that doesn't actually
  279. % do any caching.
  280. /execform
  281.  { dup /Implementation known not
  282.     { dup /FormType get 1 ne { /rangecheck signalerror } if
  283.       dup /Implementation null put readonly
  284.     } if
  285.    gsave dup /Matrix get concat
  286.    dup /BBox get aload pop
  287.    exch 3 index sub exch 2 index sub rectclip
  288.    dup /PaintProc get exec
  289.    grestore
  290.  } odef
  291.  
  292. /makepattern
  293.  { currentglobal
  294.     { false setglobal .buildpattern true setglobal }
  295.     { .buildpattern }
  296.    ifelse
  297.    exch dup length 1 add dict copy
  298.    dup /Implementation 4 -1 roll put
  299.    readonly
  300.  } odef
  301.  
  302. /setpattern
  303.  { currentcolorspace 0 get /Pattern ne
  304.     { [ /Pattern currentcolorspace ] setcolorspace } if
  305.    setcolor
  306.  } odef
  307.  
  308. end                % level2dict
  309.