星火微课系统客户端
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_dps2.ps 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. % Copyright (C) 1990, 1996, 1997, 1998, 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_dps2.ps 8954 2008-08-08 04:22:38Z ray $
  16. % Initialization file for basic Display PostScript functions
  17. % that are also included in Level 2.
  18. level2dict begin
  19. % ------ Errors ------ %
  20. % These errors are only defined in Level 2 and DPS.
  21. { /configurationerror /undefinedresource /unregistered }
  22. { .registererror } forall
  23. % ------ Halftones ------ %
  24. /.makestackdict
  25. { { counttomark -1 roll } forall .dicttomark
  26. } bind def
  27. /currenthalftone % - currenthalftone <dict>
  28. { mark .currenthalftone
  29. { { exch pop } % halftone
  30. { /HalftoneType 1 % screen
  31. { /Frequency /Angle /SpotFunction }
  32. .makestackdict readonly
  33. }
  34. { /HalftoneType 2 % colorscreen
  35. { /RedFrequency /RedAngle /RedSpotFunction
  36. /GreenFrequency /GreenAngle /GreenSpotFunction
  37. /BlueFrequency /BlueAngle /BlueSpotFunction
  38. /GrayFrequency /GrayAngle /GraySpotFunction
  39. }
  40. .makestackdict readonly
  41. }
  42. }
  43. exch get exec
  44. } odef
  45. % Define sethalftone so it converts types 1-4 to type 5.
  46. /.makehalftoneRGBV { % <dict> <type> <keys> <keysRGBV>
  47. 4 -1 roll exch { 1 index exch get exch } forall 15 1 roll
  48. 14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red } {
  49. % stack: v0 v1 v2 type keys comp
  50. mark
  51. 2 index 0 get 8 -1 roll
  52. 4 index 1 get 9 -1 roll
  53. 6 index 2 get 10 -1 roll
  54. % stack: type keys comp mark k0 v0 k1 v1 k2 v2
  55. /HalftoneType 10 index .dicttomark
  56. counttomark 2 roll
  57. } forall pop pop
  58. /Default 1 index .dicttomark exch pop { .sethalftone5 }
  59. } bind def
  60. % The value of each entry in .halftonetypes is a procedure:
  61. % <setdict> <htdict> <<proc>> <setdict'> <htdict'> <sethalftoneproc>
  62. % This allows us to use these procedures both for actually implementing
  63. % sethalftone and for converting subsidiary dictionaries of HalftoneType 5
  64. % halftones.
  65. systemdict begin
  66. 15 dict /.halftonetypes 1 index def begin
  67. 1 {
  68. mark exch /Default exch .dicttomark { .sethalftone5 }
  69. } bind def
  70. 2 {
  71. 1 { /Frequency /Angle /SpotFunction } {
  72. /RedFrequency /RedAngle /RedSpotFunction
  73. /GreenFrequency /GreenAngle /GreenSpotFunction
  74. /BlueFrequency /BlueAngle /BlueSpotFunction
  75. /GrayFrequency /GrayAngle /GraySpotFunction
  76. } .makehalftoneRGBV
  77. } bind def
  78. 3 {
  79. mark exch /Default exch .dicttomark { .sethalftone5 }
  80. } bind def
  81. 4 {
  82. 3 { /Width /Height /Thresholds } {
  83. /RedWidth /RedHeight /RedThresholds
  84. /GreenWidth /GreenHeight /GreenThresholds
  85. /BlueWidth /BlueHeight /BlueThresholds
  86. /GrayWidth /GrayHeight /GrayThresholds
  87. } .makehalftoneRGBV
  88. } bind def
  89. 5 {
  90. pop dup length dict copy
  91. mark 1 index {
  92. % Even HalftoneType 5 dictionaries have entries other than
  93. % subsidiary halftone dictionaries.
  94. dup type /dicttype ne {
  95. 0
  96. } {
  97. dup /HalftoneType .knownget not { 0 } if
  98. } ifelse dup 5 gt {
  99. % Stack: dict mark ... keyN dictN httypeN
  100. % Assume that all HalftoneTypes > 5 convert to 5.
  101. 1 index 3 1 roll
  102. //.halftonetypes exch get exec pop /Default get
  103. % Stack: dict mark ... keyN setdict'N htdict'N
  104. counttomark 1 add index 3 index 4 -1 roll put
  105. } {
  106. pop
  107. } ifelse
  108. } forall .dicttomark { .sethalftone5 }
  109. } bind def
  110. end
  111. end
  112. /sethalftone { % <dict> sethalftone -
  113. % We must create the new dictionary in the same VM as the
  114. % operand; otherwise, invalidaccess errors may occur.
  115. .currentglobal 1 .argindex dup gcheck .setglobal
  116. dup //.halftonetypes 1 index /HalftoneType get
  117. dup type /integertype ne {
  118. /sethalftone .systemvar /typecheck signalerror
  119. } if
  120. .knownget not {
  121. /sethalftone .systemvar /rangecheck signalerror
  122. } if
  123. exec exec
  124. .setglobal pop
  125. } .bind odef
  126. % Redefine setscreen and setcolorscreen to recognize halftone dictionaries,
  127. % and to insert the Frequency and Angle into Type 1 halftones, per
  128. % Adobe TN 5085.
  129. /.fixsethalftonescreen % <freq> <angle> <dict> .fix...screen
  130. % <freq> <angle> <dict> <dict'>
  131. { dup dup /HalftoneType get 1 eq
  132. { dup wcheck not { dup length .copydict } if
  133. dup /Frequency 5 index put
  134. dup /Angle 4 index put
  135. languagelevel 3 ge { dup /AccurateScreens dup getuserparam put } if
  136. }
  137. if
  138. } bind def
  139. /setscreen % <ignore*2> <dict> setscreen -
  140. { dup type /dicttype eq
  141. { .fixsethalftonescreen sethalftone pop pop pop }
  142. { //setscreen }
  143. ifelse
  144. } .bind odef
  145. /setcolorscreen % <ignore*11> <dict> setcolorscreen -
  146. { dup type /dicttype eq
  147. { .fixsethalftonescreen sethalftone 12 { pop } repeat }
  148. { //setcolorscreen }
  149. ifelse
  150. } .bind odef
  151. % Redefine currentscreen and currentcolorscreen to extract the Frequency
  152. % and Angle from Type 1 halftones, per Adobe TN 5085.
  153. /.fixcurrenthalftonescreen % <dict> .fix... <freq> <angle> <proc>
  154. { dup /HalftoneType get 1 eq
  155. { dup /Frequency get 1 index /Angle get }
  156. { 60.0 0.0 } % Adobe returns these as reals
  157. ifelse 3 2 roll
  158. } bind def
  159. /currentscreen % - currentscreen 60 0 <dict>
  160. { .currenthalftone
  161. { { .fixcurrenthalftonescreen } % halftone
  162. { } % screen
  163. { 12 3 roll 9 { pop } repeat % colorscreen
  164. dup type /dicttype eq { .fixcurrenthalftonescreen } if
  165. }
  166. }
  167. exch get exec
  168. } odef
  169. /currentcolorscreen % - currentcolorscreen (60 0 <dict>)*4
  170. { .currenthalftone
  171. { { .fixcurrenthalftonescreen 3 copy 6 copy } % halftone
  172. { % screen
  173. % The procedure might not be readable....
  174. dup rcheck { dup length array copy cvx } if
  175. 3 copy 6 copy
  176. }
  177. { } % colorscreen
  178. }
  179. exch get exec
  180. } odef
  181. % ------ User objects ------ %
  182. /.UserObjects {
  183. .userdict /UserObjects
  184. } odef
  185. % In order to get proper error recovery behavior, we need to be careful
  186. % not to pop any operands from the stack until we're done.
  187. % The code below faithfully duplicates the apparent array-growing
  188. % behavior of Adobe interpreters.
  189. /defineuserobject { % <index> <value> defineuserobject -
  190. 1 index 65535 gt {
  191. % .localvmarray throws limitcheck but CET 31-02 wants rangecheck
  192. /defineuserobject .systemvar /rangecheck signalerror
  193. } if
  194. .UserObjects .knownget {
  195. length dup 3 .argindex le {
  196. % Stack: index value len
  197. 2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
  198. .localvmarray .UserObjects get
  199. 1 index copy pop
  200. .UserObjects 3 -1 roll put
  201. } {
  202. pop
  203. } ifelse
  204. } {
  205. .UserObjects 3 .argindex 1 add 10 .max .localvmarray put
  206. } ifelse
  207. .UserObjects get 2 .argindex 2 index put pop pop
  208. } odef
  209. /execuserobject { % <index> execuserobject -
  210. dup type /integertype ne {
  211. % Adobe validates the argument before accessing UserObjects - CET 31-03
  212. /execuserobject .systemvar /typecheck signalerror
  213. } if
  214. .UserObjects get 1 .argindex get exch pop exec
  215. } odef
  216. /undefineuserobject { % <index> undefineuserobject -
  217. dup type /integertype ne {
  218. % Adobe validates the argument before accessing UserObjects - CET 31-11
  219. /undefineuserobject .systemvar /typecheck signalerror
  220. } if
  221. .UserObjects get 1 .argindex //null put pop
  222. } odef
  223. % ------ Cache control ------ %
  224. % Dummy definitions for cache control operators
  225. /ucachestatus { % - ucachestatus -mark- ? ? ? ? <size>
  226. mark 0 0 0 0 /MaxUPathItem getuserparam
  227. } odef
  228. /setucacheparams { % -mark- ... <size> setucacheparams -
  229. % Provoke an appropriate error if needed.
  230. counttomark 1 lt { () 0 get } if
  231. dup 0 or /MaxUPathItem getuserparam .max
  232. 1 dict dup /MaxUPathItem 4 -1 roll put setuserparams cleartomark
  233. } odef
  234. end % level2dict