gs_dps2.ps 6.8 KB

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