home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / GS_LEV2.PS < prev    next >
Text File  |  1992-06-16  |  8KB  |  261 lines

  1. %    Copyright (C) 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2. %    Distributed by Free Software Foundation, Inc.
  3. %
  4. % This file is part of Ghostscript.
  5. %
  6. % Ghostscript is distributed in the hope that it will be useful, but
  7. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. % to anyone for the consequences of using it or for whether it serves any
  9. % particular purpose or works at all, unless he says so in writing.  Refer
  10. % to the Ghostscript General Public License for full details.
  11. %
  12. % Everyone is granted permission to copy, modify and redistribute
  13. % Ghostscript, but only under the conditions described in the Ghostscript
  14. % General Public License.  A copy of this license is supposed to have been
  15. % given to you along with Ghostscript so you can know your rights and
  16. % responsibilities.  It should be in a file named COPYING.  Among other
  17. % things, the copyright notice and this notice must be preserved on all
  18. % copies.
  19.  
  20. % Initialization file for Ghostscript Level 2 functions.
  21. % When this is run, systemdict is still writable.
  22.  
  23. % ------ Miscellaneous ------ %
  24.  
  25. % We aren't fully Level 2 compatible yet!
  26. %/languagelevel 2 def
  27.  
  28. % ------ Painting ------ %
  29.  
  30. % A straightforward definition of execform that doesn't actually
  31. % do any caching.
  32. /execform
  33.  { dup /Implementation known not
  34.     { dup /FormType get 1 ne { /rangecheck signalerror } if
  35.       dup /Implementation null put readonly
  36.     } if
  37.    gsave dup /Matrix get concat
  38.    dup /BBox get aload pop
  39.    exch 3 index sub exch 2 index sub rectclip
  40.    dup /PaintProc get exec
  41.    grestore
  42.  } odef
  43.  
  44. % Recognize the dictionary form of image and imagemask.
  45.  
  46. /image
  47.  { dup type /dicttype eq { .dictimage } { image } ifelse
  48.  } bind odef    % bind now to incorporate old image
  49.  
  50. /imagemask
  51.  { dup type /dicttype eq { .dictimagemask } { imagemask } ifelse
  52.  } bind odef    % bind now to incorporate old imagemask
  53.  
  54. % ------ Virtual memory ------ %
  55.  
  56. /currentglobal /currentshared load def
  57. /gcheck /scheck load def
  58. /globaldict /shareddict load def
  59.  
  60. % ------ Resources ------ %
  61.  
  62. % Currently, we don't implement resource unloading or global/local
  63. % instance sets, and resourceforall only enumerates loaded instances.
  64. % The standard implementation of resource categories is
  65. % simply to have another entry in the resource dictionary, called Instances,
  66. % that keeps track of all the instances.
  67.  
  68. % Note that the dictionary that defines a resource category is stored
  69. % in global memory.  The PostScript manual says that each category must
  70. % manage global and local instances separately.  However, objects in
  71. % global memory can't reference objects in local memory.  This means
  72. % that the resource category dictionary, which would otherwise be the
  73. % obvious place to keep track of the instances, can't be used to keep
  74. % track of local instances.  Instead, there must be a parallel
  75. % structure in local memory for each resource category.  Needless to
  76. % say, we haven't implemented this yet.
  77.  
  78. % Define the Category category, except for most of the procedures.
  79. % The dictionary we're about to create will become the Category
  80. % category definition dictionary.
  81.  
  82. 10 dict begin
  83. /Category /Category def
  84. /CheckResource
  85.     { true
  86.        { /DefineResource /FindResource /ResourceForAll /ResourceStatus
  87.          /UndefineResource }
  88.        { 2 index exch known and }
  89.       forall exch pop } bind def
  90. /DefineResource
  91.     { dup CheckResource
  92.        { dup /Category 3 index put   Instances 3 1 roll put }
  93.        { /typecheck signalerror }
  94.       ifelse } bind def
  95. /FindResource        % temporary
  96.     { Instances exch get } bind def
  97. /Instances 25 dict def
  98. /InstanceType /dicttype def
  99.  
  100. Instances /Category currentdict put
  101. Instances end begin    % so we can name the Category definition
  102.  
  103. % Define the resource operators.
  104.  
  105. mark
  106. /defineresource
  107.     { /Category findresource dup begin
  108.       /InstanceType known
  109.        { dup type InstanceType ne
  110.          { dup type /packedarraytype eq InstanceType /arraytype eq and
  111.             not { /typecheck signalerror } if } if } if
  112.       DefineResource end
  113.     }
  114. /findresource
  115.     { dup /Category eq
  116.        { pop //Category } { /Category findresource } ifelse
  117.       begin FindResource end }
  118. /resourceforall
  119.     { /Category findresource begin ResourceForAll end }
  120. /resourcestatus
  121.     { /Category findresource begin ResourceStatus end }
  122. /undefineresource
  123.     { /Category findresource begin UndefineResource end }
  124. end        % Instances
  125. counttomark 2 idiv { bind def } repeat pop
  126.  
  127. % Define the Generic category.
  128.  
  129. 12 dict dup begin
  130. /Instances 0 dict def
  131. /CheckResource        % not a standard entry
  132.     { pop true } def
  133. /DefineResource
  134.     { dup CheckResource
  135.        { Instances 3 1 roll put }
  136.        { /typecheck signalerror }
  137.       ifelse
  138.     } bind def
  139. /FindResource
  140.     { dup ResourceStatus
  141.        { pop 1 gt { dup ResourceFile run } if
  142.          Instances exch get }
  143.        { /undefinedresource signalerror }
  144.       ifelse } bind def
  145. /ResourceFile        % not a standard entry
  146.     { currentdict /ResourceFileName get 100 string exch exec
  147.       (r) file } bind def
  148. /ResourceForAll
  149.     { % We construct a new procedure so we don't have to use
  150.       % static resources to hold the iteration state.
  151.       3 1 roll   cvlit 3 1 roll   cvlit 3 1 roll
  152.       { % Stack contains: key, instance, template, proc, scratch
  153.         4 index 3 index stringmatch
  154.          { 4 index type dup /stringtype eq exch /nametype eq or
  155.             { 4 index exch cvs exch 5 2 roll pop pop pop }
  156.         { pop exch pop exch pop }
  157.            ifelse exec }
  158.          { 5 { pop } repeat }
  159.         ifelse
  160.       } /exec cvx 5 packedarray cvx
  161.       Instances exch forall } bind def
  162. /ResourceStatus
  163.     { dup Instances exch known
  164.        { pop 1 0 true }
  165.        { mark exch { ResourceFile } stopped
  166.           { cleartomark false } { closefile cleartomark 0 true }
  167.          ifelse
  168.        } ifelse
  169.     } bind def
  170. /UndefineResource
  171.     { Instances exch undef } bind def
  172. end
  173. /Generic exch /Category defineresource
  174.  
  175. % Fill in the rest of the Category category.
  176. /Category /Category findresource dup
  177. /Generic /Category findresource begin
  178.  { /FindResource /ResourceStatus /ResourceForAll }
  179.  { dup load put dup } forall
  180. pop pop end
  181.  
  182. % Define the fixed categories.
  183.  
  184. 7 dict begin        % 5 procedures, Category, Instances
  185. /DefineResource
  186.     { /invalidaccess signalerror } bind def
  187. /FindResource
  188.     { Instances exch get } bind def
  189. /ResourceForAll
  190.     /Generic /Category findresource /ResourceForAll get def
  191. /ResourceStatus
  192.     { Instances exch known { 0 0 true } { false } ifelse } bind def
  193. /UndefineResource
  194.     { /invalidaccess signalerror } bind def
  195.  
  196. mark
  197.     % Things other than types
  198.  /ColorSpaceFamily {/DeviceRGB /DeviceGray}
  199.  /Emulator {}
  200.  /Filter
  201.    [ .filterdict { pop } forall ]
  202.  /IODevice {(%os%)}
  203.     % Types
  204.  /ColorRenderingType {}
  205.  /FMapType {2 3 4 5 6 7 8}
  206.  /FontType {1 3}
  207.  /FormType {1}
  208.  /HalftoneType {}
  209.  /ImageType {1}
  210.  /PatternType {}
  211. counttomark 2 idiv
  212.  { currentdict dup maxlength dict copy begin
  213.    dup length dict dup begin exch { dup def } forall end readonly
  214.    /Instances exch def
  215.    currentdict /Category defineresource
  216.    currentdict end readonly pop
  217.  } repeat pop end
  218.  
  219. % Define the other built-in categories.
  220.  
  221. mark
  222.   /ColorRendering /dicttype /ColorSpace /arraytype /Encoding /arraytype
  223.   /Font /dicttype /Form /dicttype /Halftone /dicttype /Pattern /dicttype
  224.   /ProcSet /dicttype
  225. counttomark 2 idiv
  226.  { /Generic /Category findresource dup maxlength dict copy begin
  227.    /InstanceType exch def
  228.    /Instances 10 dict def
  229.    currentdict end /Category defineresource
  230.  } repeat pop
  231.  
  232. % Complete the Encoding category.
  233.  
  234. /findencoding
  235.     { /Encoding findresource } bind def
  236. /ISOLatin1Encoding ISOLatin1Encoding /Encoding defineresource
  237. /StandardEncoding StandardEncoding /Encoding defineresource
  238. /SymbolEncoding SymbolEncoding /Encoding defineresource
  239.  
  240. % Complete the Font category.
  241. % INCOMPLETE.
  242.  
  243. /Font /Category findresource begin
  244. /..definefont /definefont load def
  245. /..findfont /findfont load def
  246. /DefineResource
  247.     { 2 copy ..definefont exch pop 2 copy
  248.       Instances 3 1 roll put exch pop
  249.     } bind def
  250. /FindResource
  251.     { ..findfont
  252.     } bind def
  253. end
  254.  
  255. /definefont
  256.     { /Font defineresource } bind def
  257. /findfont
  258.     { /Font findresource } bind def
  259. /undefinefont
  260.     { /Font undefineresource } bind def
  261.