home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / gs_dps.ps < prev    next >
Text File  |  2000-03-09  |  7KB  |  200 lines

  1. %    Copyright (C) 1997, 1998 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. % $Id: gs_dps.ps,v 1.1 2000/03/09 08:40:39 lpd Exp $
  16. % Initialization file for Display PostScript functions.
  17.  
  18. % ------ Contexts ------ %
  19.  
  20. % To create a context with private local VM, we use the .localfork
  21. % operator to actually create the context, the new VM, and an empty
  22. % userdict, and then we call the .initlocaldicts procedure to make
  23. % local copies of the initial contents of the dictionaries in local VM.
  24. % savedlocaldicts in systemdict is a global read-only dictionary whose
  25. % elements are global read-only copies of these initial contents;
  26. % we just copy its elements into local VM and install them in systemdict.
  27. % userdict and internaldict require special handling.
  28.  
  29. % Switching between contexts with different local VMs requires
  30. % changing the bindings in systemdict that reference local objects.
  31. % For this purpose, each userdict has an entry called localdicts
  32. % which holds the local copies of the elements of savedlocaldicts,
  33. % plus internaldict.  The context switching code in the interpreter
  34. % effectively copies this dictionary into systemdict.
  35. % NOTE: the name localdicts is known to the interpreter.
  36.  
  37. % Switching between contexts also requires resetting the user parameters.
  38. % The interpreter records the value of userparams (a local dictionary
  39. % referenced from systemdict) for each context, and uses it for this.
  40. % See gs_lev2.ps for more details.
  41. % NOTE: the name userparams is known to the interpreter.
  42.  
  43. % Save copies of local dictionaries at the end of system initialization.
  44. % Also save the initial gstate.
  45. /.savelocalstate {
  46.   .currentglobal true .setglobal
  47.   //systemdict /savedlocaldicts mark //systemdict {
  48.     dup gcheck {
  49.       pop pop
  50.     } {
  51.       dup type /dicttype eq {
  52.         % Save a copy of this dictionary in global VM.
  53.     dup maxlength dict .copydict readonly
  54.       } {
  55.     pop pop
  56.       } ifelse
  57.     } ifelse
  58.   } forall .dicttomark readonly .forceput    % systemdict is read-only
  59.         % Create localdicts for the current context.
  60.   false .setglobal
  61.   userdict /localdicts mark savedlocaldicts {
  62.     pop dup load
  63.   } forall /internaldict dup load
  64.   .dicttomark readonly put
  65.         % Save a copy of the initial gstate.
  66.   true .setglobal
  67.   //systemdict /savedinitialgstate gstate readonly put
  68.   .setglobal
  69. } .bind def
  70.  
  71. % Initialize local dictionaries and gstate when creating a new context.
  72. % Note that until this completes, we are in the anomalous situation of
  73. % having systemdict point to dictionaries that are in a non-current
  74. % local VM.  Because of this, we turn off garbage collection temporarily.
  75. /.copylocal {        % <name> <dict> .copylocal <name> <dict'>
  76.         % Copy a dictionary to the current (local) VM,
  77.         % and make it read-only if its current definition is.
  78.   dup maxlength dict .copydict
  79.   1 index load wcheck not { readonly } if
  80. } .bind def
  81. % When this is called, the dictionary stack is in its initial state,
  82. % and there is (anomalously) only one gstate on the gstate stack.
  83. /.initlocaldicts {        % - .initlocaldicts -
  84.   -2 vmreclaim
  85.   .currentglobal //systemdict begin
  86.   false .setglobal
  87.         % Since localdicts doesn't exist yet, references from
  88.         % systemdict to local objects won't get restored if
  89.         % a context switch happens in this code.  Therefore,
  90.         % until localdicts is defined, we have to keep all our
  91.         % state on the operand stack.
  92.  
  93.         % Acquire userdict.
  94.         %****** WRONG IF NON-STANDARD INITIAL DSTACK ******
  95.   countdictstack array dictstack
  96.    { dup gcheck not { exit } if pop } forall
  97.         % Create localdicts with a local copy of each dictionary,
  98.         % except for userdict and userparams, which just need
  99.         % to be filled in.
  100.   mark savedlocaldicts {
  101.     1 index /userdict eq {
  102.         % Stack: userdict mark ... /userdict inituserdict
  103.       counttomark 1 add index exch .copydict
  104.     } {
  105.       1 index /userparams eq {
  106.         % Stack: userparams mark ... /userparams inituserparams
  107.     userparams .copydict
  108.       } {
  109.     .copylocal
  110.       } ifelse
  111.     } ifelse
  112.   } forall /internaldict dup .makeinternaldict .makeoperator
  113.   .dicttomark readonly /localdicts exch put
  114.         % localdicts is now defined in userdict.
  115.         % Copy the definitions into systemdict.
  116.   localdicts { .forcedef } forall
  117.         % Set the user parameters.
  118.   userparams readonly .setuserparams
  119.         % Establish the initial gstate(s).
  120.   /savedinitialgstate .systemvar setgstate gsave
  121.         % Wrap up.
  122.   end .setglobal
  123. } odef
  124.  
  125. % Create a context with private local VM.
  126. % The .localfork operator does all the work, but we must ensure that
  127. % .initlocaldicts gets called when the new context starts up.
  128. /localfork {            % <mark> <obj1> ... <objN> <proc>
  129.                 %   <stdin|null> <stdout|null>
  130.                 %   localfork <context>
  131.   .currentglobal true .setglobal 3 index
  132.   dup dup xcheck
  133.   exch type dup /arraytype eq exch /packedarraytype eq or and not {
  134.     pop .setglobal /localfork cvx /typecheck signalerror
  135.   } if
  136.   {exec .initlocaldicts} aload pop
  137.   3 1 roll 3 packedarray cvx
  138.   4 1 roll 5 -1 roll pop .setglobal .localfork
  139. } odef
  140.  
  141. % Fork a context that shares VM.  We still need to fill in userparams
  142. % when the new context starts up.
  143. /.postfork {        % - .postfork -
  144.     % Initialize the user parameters.
  145.   savedlocaldicts /userparams get userparams .copydict readonly pop
  146. } odef
  147. /fork {            % <mark> <obj1> ... <objN> <proc> fork <context>
  148.   .currentglobal false .setglobal 1 index
  149.   dup dup xcheck
  150.   exch type dup /arraytype eq exch /packedarraytype eq or and not {
  151.     pop .setglobal /fork cvx /typecheck signalerror
  152.   } if
  153.   {exec .postfork} aload pop
  154.   3 1 roll 3 packedarray cvx
  155.   3 1 roll exch pop .setglobal .fork
  156. } odef
  157.  
  158. % ------ Halftone phase ------ %
  159.  
  160. /sethalftonephase {        % <x> <y> sethalftonephase -
  161.   -1 2 index 2 index .setscreenphase pop pop
  162. } odef
  163. /currenthalftonephase {        % - currenthalftonephase <x> <y>
  164.   0 .currentscreenphase
  165. } odef
  166.  
  167. % ------ Device-source images ------ */
  168.  
  169. .imagetypes 2 /.image2 load put
  170.  
  171. % ------ Device information ------ %
  172.  
  173. /.deviceinfodict mark
  174.   /Colors null /GrayValues null /RedValues null /GreenValues null
  175.   /BlueValues null /ColorValues null
  176. .dicttomark readonly def
  177. /deviceinfo {            % - deviceinfo <dict>
  178.   currentdevice //.deviceinfodict .getdeviceparams .dicttomark readonly
  179. } odef
  180.  
  181. % The current implementation allocates a 2-element array each time.
  182. % Perhaps we should change this to 2 separate parameters for X and Y?
  183. /.wtdict mark
  184.   /wtranslation null
  185. .dicttomark readonly def
  186. /wtranslation {            % - wtranslation <x> <y>
  187.   currentdevice //.wtdict .getdeviceparams exch pop exch pop aload pop
  188. } odef
  189. currentdict /.wtdict .undef
  190.  
  191. % ------ View clipping ------ %
  192.  
  193. /rectviewclip {            % <x> <y> <width> <height> rectviewclip -
  194.                 % <numarray|numstring> rectviewclip -
  195.   newpath .rectappend viewclip
  196. } odef
  197.