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.

254 lines
8.7 KiB

1 month ago
  1. % Copyright (C) 2001-2023 Artifex Software, Inc.
  2. % All Rights Reserved.
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  7. % This software is distributed under license and may not be copied,
  8. % modified or distributed except as expressly authorized under the terms
  9. % of the license contained in the file LICENSE in this distribution.
  10. %
  11. % Refer to licensing information at http://www.artifex.com or contact
  12. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  13. % CA 94129, USA, for further information.
  14. %
  15. % Initialization file for basic Display PostScript functions
  16. % that are also included in Level 2.
  17. level2dict begin
  18. % ------ Errors ------ %
  19. % These errors are only defined in Level 2 and DPS.
  20. { /configurationerror /undefinedresource /unregistered }
  21. { .registererror } forall
  22. % ------ Halftones ------ %
  23. /.makestackdict
  24. { { counttomark -1 roll } forall .dicttomark
  25. } .internalbind def
  26. /currenthalftone % - currenthalftone <dict>
  27. { mark .currenthalftone
  28. { { exch pop } % halftone
  29. { /HalftoneType 1 % screen
  30. { /Frequency /Angle /SpotFunction }
  31. //.makestackdict exec readonly
  32. }
  33. { /HalftoneType 2 % colorscreen
  34. { /RedFrequency /RedAngle /RedSpotFunction
  35. /GreenFrequency /GreenAngle /GreenSpotFunction
  36. /BlueFrequency /BlueAngle /BlueSpotFunction
  37. /GrayFrequency /GrayAngle /GraySpotFunction
  38. }
  39. //.makestackdict exec readonly
  40. }
  41. }
  42. exch get exec
  43. } odef
  44. currentdict /.makestackdict undef
  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. } .internalbind 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. } .internalbind 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 exec
  77. } .internalbind def
  78. 3 {
  79. mark exch /Default exch .dicttomark { .sethalftone5 }
  80. } .internalbind 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 exec
  88. } .internalbind 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. } .internalbind def
  110. end
  111. end
  112. currentdict /.makehalftoneRGBV undef
  113. /sethalftone { % <dict> sethalftone -
  114. % We must create the new dictionary in the same VM as the
  115. % operand; otherwise, invalidaccess errors may occur.
  116. .currentglobal 1 .argindex dup gcheck .setglobal
  117. dup //.halftonetypes 1 index /HalftoneType get
  118. dup type /integertype ne {
  119. /sethalftone .systemvar /typecheck signalerror
  120. } if
  121. .knownget not {
  122. /sethalftone .systemvar /rangecheck signalerror
  123. } if
  124. exec exec
  125. .setglobal pop
  126. } .forcebind odef
  127. % Redefine setscreen and setcolorscreen to recognize halftone dictionaries,
  128. % and to insert the Frequency and Angle into Type 1 halftones, per
  129. % Adobe TN 5085.
  130. /.fixsethalftonescreen % <freq> <angle> <dict> .fix...screen
  131. % <freq> <angle> <dict> <dict'>
  132. { dup dup /HalftoneType get 1 eq
  133. { dup wcheck not { dup length dict .copydict } if
  134. dup /Frequency 5 index put
  135. dup /Angle 4 index put
  136. languagelevel 3 ge { dup /AccurateScreens dup getuserparam put } if
  137. }
  138. if
  139. } .internalbind def
  140. /setscreen % <ignore*2> <dict> setscreen -
  141. { dup type /dicttype eq
  142. { //.fixsethalftonescreen exec sethalftone pop pop pop }
  143. { //setscreen }
  144. ifelse
  145. } .forcebind odef
  146. /setcolorscreen % <ignore*11> <dict> setcolorscreen -
  147. { dup type /dicttype eq
  148. { //.fixsethalftonescreen exec sethalftone 12 { pop } repeat }
  149. { //setcolorscreen }
  150. ifelse
  151. } .forcebind odef
  152. currentdict /.fixsethalftonescreen undef
  153. % Redefine currentscreen and currentcolorscreen to extract the Frequency
  154. % and Angle from Type 1 halftones, per Adobe TN 5085.
  155. /.fixcurrenthalftonescreen % <dict> .fix... <freq> <angle> <proc>
  156. { dup /HalftoneType get 1 eq
  157. { dup /Frequency get 1 index /Angle get }
  158. { 60.0 0.0 } % Adobe returns these as reals
  159. ifelse 3 2 roll
  160. } .internalbind def
  161. /currentscreen % - currentscreen 60 0 <dict>
  162. { .currenthalftone
  163. { { //.fixcurrenthalftonescreen exec }% halftone
  164. { } % screen
  165. { 12 3 roll 9 { pop } repeat % colorscreen
  166. dup type /dicttype eq { //.fixcurrenthalftonescreen exec } if
  167. }
  168. }
  169. exch get exec
  170. } odef
  171. /currentcolorscreen % - currentcolorscreen (60 0 <dict>)*4
  172. { .currenthalftone
  173. { { //.fixcurrenthalftonescreen exec 3 copy 6 copy } % halftone
  174. { % screen
  175. % The procedure might not be readable....
  176. dup rcheck { dup length array copy cvx } if
  177. 3 copy 6 copy
  178. }
  179. { } % colorscreen
  180. }
  181. exch get exec
  182. } odef
  183. currentdict /.fixcurrenthalftonescreen undef
  184. % ------ User objects ------ %
  185. /.UserObjects {
  186. .userdict /UserObjects
  187. } .internalbind odef
  188. % In order to get proper error recovery behavior, we need to be careful
  189. % not to pop any operands from the stack until we're done.
  190. % The code below faithfully duplicates the apparent array-growing
  191. % behavior of Adobe interpreters.
  192. /defineuserobject { % <index> <value> defineuserobject -
  193. 1 index 65535 gt {
  194. % .localvmarray throws limitcheck but CET 31-02 wants rangecheck
  195. /defineuserobject .systemvar /rangecheck signalerror
  196. } if
  197. .UserObjects .knownget {
  198. length dup 3 .argindex le {
  199. % Stack: index value len
  200. 2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
  201. .localvmarray .UserObjects get
  202. 1 index copy pop
  203. .UserObjects 3 -1 roll put
  204. } {
  205. pop
  206. } ifelse
  207. } {
  208. .UserObjects 3 .argindex 1 add 10 .max .localvmarray put
  209. } ifelse
  210. .UserObjects get 2 .argindex 2 index put pop pop
  211. } .forcebind odef
  212. /execuserobject { % <index> execuserobject -
  213. dup type /integertype ne {
  214. % Adobe validates the argument before accessing UserObjects - CET 31-03
  215. /execuserobject .systemvar /typecheck signalerror
  216. } if
  217. .UserObjects get 1 .argindex get exch pop exec
  218. } .forcebind odef
  219. /undefineuserobject { % <index> undefineuserobject -
  220. dup type /integertype ne {
  221. % Adobe validates the argument before accessing UserObjects - CET 31-11
  222. /undefineuserobject .systemvar /typecheck signalerror
  223. } if
  224. .UserObjects get 1 .argindex //null put pop
  225. } .forcebind odef
  226. currentdict /.UserObjects undef
  227. % ------ Cache control ------ %
  228. % Dummy definitions for cache control operators
  229. /ucachestatus { % - ucachestatus -mark- ? ? ? ? <size>
  230. mark 0 0 0 0 /MaxUPathItem getuserparam
  231. } odef
  232. /setucacheparams { % -mark- ... <size> setucacheparams -
  233. % Provoke an appropriate error if needed.
  234. counttomark 1 lt { () 0 get } if
  235. dup 0 or /MaxUPathItem getuserparam .max
  236. 1 dict dup /MaxUPathItem 4 -1 roll put setuserparams cleartomark
  237. } odef
  238. end % level2dict