星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gs_dps.ps 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. % Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  6. % This software is distributed under license and may not be copied,
  7. % modified or distributed except as expressly authorized under the terms
  8. % of the license contained in the file LICENSE in this distribution.
  9. %
  10. % For more information about licensing, please refer to
  11. % http://www.ghostscript.com/licensing/. For information on
  12. % commercial licensing, go to http://www.artifex.com/licensing/ or
  13. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  14. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  15. % $Id: gs_dps.ps 8954 2008-08-08 04:22:38Z ray $
  16. % Initialization file for Display PostScript functions.
  17. % ------ Errors ------ %
  18. % These errors are only defined in DPS.
  19. { /invalidcontext /invalidid } { .registererror } forall
  20. % ------ Contexts ------ %
  21. % To create a context with private local VM, we use the .localfork
  22. % operator to actually create the context, the new VM, and an empty
  23. % userdict, and then we call the .initlocaldicts procedure to make
  24. % local copies of the initial contents of the dictionaries in local VM.
  25. % savedlocaldicts in systemdict is a global read-only dictionary whose
  26. % elements are global read-only copies of these initial contents;
  27. % we just copy its elements into local VM and install them in systemdict.
  28. % userdict and internaldict require special handling.
  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. % Switching between contexts also requires resetting the user parameters.
  37. % The interpreter records the value of userparams (a local dictionary
  38. % referenced from systemdict) for each context, and uses it for this.
  39. % See gs_lev2.ps for more details.
  40. % NOTE: the name userparams is known to the interpreter.
  41. % Save copies of local dictionaries at the end of system initialization.
  42. % Also save the initial gstate.
  43. /.savelocalstate {
  44. .currentglobal true .setglobal
  45. //systemdict /savedlocaldicts mark //systemdict {
  46. dup gcheck {
  47. pop pop
  48. } {
  49. dup type /dicttype eq {
  50. % Save a copy of this dictionary in global VM.
  51. dup maxlength dict .copydict readonly
  52. } {
  53. pop pop
  54. } ifelse
  55. } ifelse
  56. } forall .dicttomark readonly put
  57. % Create localdicts for the current context.
  58. false .setglobal
  59. userdict /localdicts mark savedlocaldicts {
  60. pop dup load
  61. } forall /internaldict dup load
  62. .dicttomark readonly put
  63. % Save a copy of the initial gstate.
  64. true .setglobal
  65. //systemdict /savedinitialgstate gstate readonly put
  66. .setglobal
  67. } .bind def
  68. % Initialize local dictionaries and gstate when creating a new context.
  69. % Note that until this completes, we are in the anomalous situation of
  70. % having systemdict point to dictionaries that are in a non-current
  71. % local VM. Because of this, we turn off garbage collection temporarily.
  72. /.copylocal { % <name> <dict> .copylocal <name> <dict'>
  73. % Copy a dictionary to the current (local) VM,
  74. % and make it read-only if its current definition is.
  75. dup maxlength dict .copydict
  76. 1 index load wcheck not { readonly } if
  77. } .bind def
  78. % When this is called, the dictionary stack is in its initial state,
  79. % and there is (anomalously) only one gstate on the gstate stack.
  80. /.initlocaldicts { % - .initlocaldicts -
  81. -2 vmreclaim
  82. .currentglobal //systemdict begin
  83. false .setglobal
  84. % Since localdicts doesn't exist yet, references from
  85. % systemdict to local objects won't get restored if
  86. % a context switch happens in this code. Therefore,
  87. % until localdicts is defined, we have to keep all our
  88. % state on the operand stack.
  89. % Acquire userdict.
  90. %****** WRONG IF NON-STANDARD INITIAL DSTACK ******
  91. countdictstack array dictstack
  92. { dup gcheck not { exit } if pop } forall
  93. % Create localdicts with a local copy of each dictionary,
  94. % except for userdict and userparams, which just need
  95. % to be filled in.
  96. mark savedlocaldicts {
  97. 1 index /userdict eq {
  98. % Stack: userdict mark ... /userdict inituserdict
  99. counttomark 1 add index .copydict
  100. } {
  101. 1 index /userparams eq {
  102. % Stack: userdict mark ... /userparams inituserparams
  103. userparams .copydict
  104. } {
  105. .copylocal
  106. } ifelse
  107. } ifelse
  108. } forall /internaldict dup .makeinternaldict .makeoperator
  109. .dicttomark readonly /localdicts exch put
  110. % localdicts is now defined in userdict.
  111. % Copy the definitions into systemdict.
  112. localdicts { .forcedef } forall
  113. % Set the user parameters.
  114. userparams readonly .setuserparams
  115. % Establish the initial gstate(s).
  116. /savedinitialgstate .systemvar setgstate gsave
  117. % Wrap up.
  118. end .setglobal
  119. } odef
  120. % Check whether an object is a procedure.
  121. /.proccheck { % <obj> .proccheck <bool>
  122. dup xcheck
  123. exch type dup /arraytype eq exch /packedarraytype eq or and
  124. } bind def
  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 .proccheck not {
  133. pop .setglobal /localfork .systemvar /typecheck signalerror
  134. } if
  135. {exec .initlocaldicts} aload pop
  136. 3 1 roll 3 packedarray cvx
  137. 4 1 roll 5 -1 roll pop .setglobal .localfork
  138. } odef
  139. % Fork a context that shares VM. The .fork operator creates an empty
  140. % userparams dictionary for the context, but we still need to initialize
  141. % this dictionary when the new context starts up.
  142. /.postfork { % - .postfork -
  143. % Initialize the user parameters.
  144. savedlocaldicts /userparams get userparams .copydict readonly pop
  145. } odef
  146. /fork { % <mark> <obj1> ... <objN> <proc> fork <context>
  147. .currentglobal false .setglobal 1 index
  148. dup .proccheck not {
  149. pop .setglobal /fork .systemvar /typecheck signalerror
  150. } if
  151. {exec .postfork} aload pop
  152. 3 1 roll 3 packedarray cvx
  153. 3 1 roll exch pop .setglobal .fork
  154. } odef
  155. % ------ Halftone phase ------ %
  156. /sethalftonephase { % <x> <y> sethalftonephase -
  157. -1 2 index 2 index .setscreenphase pop pop
  158. } odef
  159. /currenthalftonephase { % - currenthalftonephase <x> <y>
  160. 0 .currentscreenphase
  161. } odef
  162. % ------ Device-source images ------ */
  163. .imagetypes 2 /.image2 load put
  164. % ------ Device information ------ %
  165. /.deviceinfodict mark
  166. /Colors null /GrayValues null /RedValues null /GreenValues null
  167. /BlueValues null /ColorValues null
  168. .dicttomark readonly def
  169. /deviceinfo { % - deviceinfo <dict>
  170. currentdevice //.deviceinfodict .getdeviceparams .dicttomark
  171. dup begin
  172. /ColorValues .knownget {
  173. 0 le
  174. { currentdict /ColorValues undef }
  175. {
  176. % hack around devices that incorrect set GrayValues
  177. Colors 3 eq { 1 } { GrayValues } ifelse
  178. RedValues mul GreenValues mul BlueValues mul ColorValues ne
  179. { currentdict /GrayValues undef
  180. currentdict /RedValues undef
  181. currentdict /GreenValues undef
  182. currentdict /BlueValues undef
  183. } if
  184. }
  185. ifelse
  186. } if
  187. currentdict end readonly
  188. } odef
  189. % The current implementation allocates a 2-element array each time.
  190. % Perhaps we should change this to 2 separate parameters for X and Y?
  191. /.wtdict mark
  192. /wtranslation null
  193. .dicttomark readonly def
  194. /wtranslation { % - wtranslation <x> <y>
  195. currentdevice //.wtdict .getdeviceparams exch pop exch pop aload pop
  196. } odef
  197. currentdict /.wtdict .undef
  198. % ------ View clipping ------ %
  199. /rectviewclip { % <x> <y> <width> <height> rectviewclip -
  200. % <numarray|numstring> rectviewclip -
  201. newpath .rectappend viewclip
  202. } odef