gs_dps2.ps 7.0 KB

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