1
0

gs_ll3.ps 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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_ll3.ps,v 1.20 2003/10/22 11:22:29 alexcher Exp $
  16. % Initialization file for PostScript LanguageLevel 3 functions.
  17. % This file must be loaded after gs_lev2.ps and gs_res.ps.
  18. % These definitions go into ll3dict or various ProcSets.
  19. % NOTE: the interpreter creates ll3dict.
  20. ll3dict begin
  21. % We need LanguageLevel 2 or higher in order to have setuserparams and
  22. % defineresource.
  23. languagelevel dup 2 .max .setlanguagelevel
  24. % ------ Idiom recognition ------ %
  25. /IdiomRecognition false .definepsuserparam
  26. % Modify `bind' to apply idiom recognition afterwards.
  27. /.bindscratch 128 string def
  28. % Note that since this definition of `bind' may get bound in,
  29. % it has to function properly even at lower language levels,
  30. % where IdiomRecognition may not be defined.
  31. /.bind { % <proc> .bind <proc'>
  32. //.bind currentuserparams /IdiomRecognition
  33. .knownget not { false } if {
  34. (*) {
  35. /IdiomSet findresource
  36. false exch {
  37. % Stack: proc false dummykey [template substitute]
  38. exch pop dup 1 get exch 0 get
  39. % Stack: proc false substitute template
  40. 3 index .eqproc {
  41. 2 index gcheck 1 index gcheck not and {
  42. pop
  43. } {
  44. 3 -1 roll pop exch not exit
  45. } ifelse
  46. } {
  47. pop
  48. } ifelse
  49. } forall { exit } if
  50. } //.bindscratch /IdiomSet resourceforall
  51. } if
  52. } odef
  53. currentdict /.bindscratch .undef
  54. DELAYBIND NOBIND or not {
  55. /bind /.bind load def
  56. } if
  57. % ------ HalftoneTypes 6, 10, 16 and HalftoneMode ------ %
  58. % This code depends on an internal HalftoneType 7 with the following keys:
  59. % Width, Height, Width2, Height2, TransferFunction:
  60. % as for HalftoneType 16.
  61. % Thresholds: a string or bytestring holding the thresholds,
  62. % (Width x Height + Width2 x Height2) x BitsPerSample / 8 bytes,
  63. % as for HalftoneType 16 except that the samples may be either
  64. % 8 or 16 bits wide.
  65. % BitsPerSample: 8 or 16.
  66. % Note that this HalftoneType never appears in halftone dictionaries given
  67. % to sethalftone, only as a component in those given to .sethalftone5,
  68. % so its numeric value can be chosen ad lib as long as it differs from the
  69. % other values that are legal in component dictionaries for .sethalftone5
  70. % (currently only 1 and 3).
  71. /.makehalftone7 { % <dict> <dict> <source> <Width> <Height>
  72. % (<Width2> <Height2> | null) <BPS> .makehalftone7
  73. % <setdict> <dict5> { .sethalftone5 }
  74. 8 dict begin
  75. /HalftoneType 7 def
  76. /BitsPerSample exch def
  77. dup null eq {
  78. pop 0
  79. } {
  80. /Height2 1 index def /Width2 2 index def mul
  81. } ifelse 3 1 roll
  82. /Height 1 index def
  83. /Width 2 index def
  84. mul add BitsPerSample 8 idiv mul .bigstring
  85. % Stack: dict dict source str
  86. dup type /stringtype eq { readstring } { .readbytestring } ifelse
  87. not { /sethalftone load /rangecheck signalerror exit } if
  88. readonly /Thresholds exch def
  89. /TransferFunction .knownget { /TransferFunction exch def } if
  90. % If the original Thresholds was a file, replace it with
  91. % a new one.
  92. dup /Thresholds get type /filetype eq {
  93. dup /Thresholds [ Thresholds ] cvx 0 () .subfiledecode put
  94. } if
  95. mark /HalftoneType 5 /Default currentdict end .dicttomark
  96. { .sethalftone5 }
  97. } bind def
  98. /.bigstring { % <size> .bigstring <string|bytestring>
  99. dup 65400 gt { .bytestring } { string } ifelse
  100. } bind def
  101. /.readbytestring { % <source> <bytestring> .readbytestring
  102. % <bytestring> <filled>
  103. % Note that since bytestrings don't implement getinterval,
  104. % if filled is false, there is no way to tell how much
  105. % was read.
  106. true exch 0 1 2 index length 1 sub {
  107. % Stack: source true str index
  108. 3 index read not { pop exch not exch exit } if
  109. 3 copy put pop pop
  110. } for 3 -1 roll pop exch
  111. } bind def
  112. /.sethalftone6 { % <dict> <dict> .sethalftone6 <setdict> <dict5>
  113. % { .sethalftone5 }
  114. % Keys: Width, Height, Thresholds, T'Function
  115. dup /Thresholds get
  116. 1 index /Width get 2 index /Height get
  117. null 8 .makehalftone7
  118. } bind def
  119. /.sethalftone10 { % <dict> <dict> .sethalftone10 <setdict> <dict5>
  120. % { .sethalftone5 }
  121. % Keys: Xsquare, Ysquare, Thresholds, T'Function
  122. % Note that this is the only one of these three HalftoneTypes
  123. % that allows either a file or a string for Thresholds.
  124. dup /Thresholds get dup type /stringtype eq { 0 () .subfiledecode } if
  125. 1 index /Xsquare get dup 3 index /Ysquare get dup
  126. 8 .makehalftone7
  127. } bind def
  128. /.sethalftone16 { % <dict> <dict> .sethalftone16 <setdict> <dict5>
  129. % { .sethalftone5 }
  130. % Keys: Width, Height, Width2, Height2,
  131. % Thresholds, T'Function
  132. dup /Thresholds get
  133. 1 index /Width get 2 index /Height get
  134. 3 index /Width2 .knownget { % 2-rectangle case
  135. 4 index /Height2 get
  136. } { % 1-rectangle case
  137. null
  138. } ifelse 16 .makehalftone7
  139. } bind def
  140. .halftonetypes begin
  141. 6 /.sethalftone6 load def
  142. 10 /.sethalftone10 load def
  143. 16 /.sethalftone16 load def
  144. end
  145. % Redefine the halftone-setting operators to honor HalftoneMode.
  146. /setcolorscreen {
  147. /HalftoneMode getuserparam 0 eq {
  148. //setcolorscreen
  149. } {
  150. 12 { pop } repeat .getdefaulthalftone
  151. { //sethalftone }
  152. { .setdefaulthalftone }
  153. ifelse
  154. } ifelse
  155. } odef
  156. /setscreen {
  157. /HalftoneMode getuserparam 0 eq {
  158. //setscreen
  159. } {
  160. pop pop pop .getdefaulthalftone
  161. { //sethalftone }
  162. { .setdefaulthalftone }
  163. ifelse
  164. } ifelse
  165. } odef
  166. /sethalftone {
  167. /HalftoneMode getuserparam 0 eq {
  168. //sethalftone
  169. } {
  170. pop .getdefaulthalftone
  171. { //sethalftone }
  172. { .setdefaulthalftone }
  173. ifelse
  174. } ifelse
  175. } odef
  176. % ------ ImageTypes 3 and 4 (masked images) ------ %
  177. .imagetypes
  178. dup 3 /.image3 load put
  179. dup 4 /.image4 load put
  180. % We also detect ImageType 103 here: it isn't worth making a separate file
  181. % just for this.
  182. /.image3x where { pop dup 103 /.image3x load put } if
  183. pop
  184. % ------ Functions ------ %
  185. % Define the FunctionType resource category.
  186. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  187. /InstanceType /integertype def
  188. /FunctionType currentdict end /Category defineresource pop
  189. {0 2 3} { dup /FunctionType defineresource pop } forall
  190. % ------ Smooth shading ------ %
  191. % Define the ShadingType resource category.
  192. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  193. /InstanceType /integertype def
  194. /ShadingType currentdict end /Category defineresource pop
  195. systemdict /.shadingtypes mark % not ll3dict
  196. 1 /.buildshading1 load
  197. 2 /.buildshading2 load
  198. 3 /.buildshading3 load
  199. 4 /.buildshading4 load
  200. 5 /.buildshading5 load
  201. 6 /.buildshading6 load
  202. 7 /.buildshading7 load
  203. .dicttomark put
  204. systemdict /.reuseparamdict mark
  205. /Intent 2
  206. /AsyncRead false
  207. /CloseSource true
  208. .dicttomark readonly put
  209. /.buildshading { % <shadingdict> .buildshading <shading>
  210. % Unfortunately, we always need to make the DataSource reusable,
  211. % because if clipping is involved, even shfill may need to read
  212. % the source data multiple times. If it weren't for this,
  213. % we would only need to create a reusable stream if the ultimate
  214. % source of the data is a procedure (since the library can't
  215. % suspend shading to do a procedure callout).
  216. dup /DataSource .knownget {
  217. dup type /filetype eq {
  218. //.reuseparamdict /ReusableStreamDecode filter
  219. .currentglobal 1 index gcheck .setglobal
  220. % Stack: shdict rsdfile saveglobal
  221. 2 index dup length dict copy exch .setglobal
  222. dup /DataSource 4 -1 roll put exch pop
  223. } {
  224. pop
  225. } ifelse
  226. } if
  227. % The .buildshading operators use the current color space
  228. % for ColorSpace.
  229. dup /ShadingType get //.shadingtypes exch get
  230. 1 index /ColorSpace get setcolorspace exec
  231. } bind def
  232. systemdict /.reuseparamdict undef
  233. /.buildpattern2 { % <template> <matrix> .buildpattern2
  234. % <template> <pattern>
  235. % We want to build the pattern without doing gsave/grestore,
  236. % since we want it to load the CIE caches.
  237. 1 index /Shading get
  238. mark currentcolor currentcolorspace
  239. counttomark 4 add -3 roll mark 4 1 roll
  240. % Stack: -mark- ..color.. cspace -mark- template matrix shadingdict
  241. { .buildshading } stopped {
  242. cleartomark setcolorspace setcolor pop stop
  243. } if
  244. .buildshadingpattern
  245. 3 -1 roll pop counttomark 1 add 2 roll setcolorspace setcolor pop
  246. } bind def
  247. .patterntypes
  248. 2 /.buildpattern2 load put
  249. /shfill { % <shadingdict> shfill -
  250. % Currently, .shfill requires that the color space
  251. % in the pattern be the current color space.
  252. % Disable overprintmode for shfill
  253. dup gsave
  254. 0 .setoverprintmode { .buildshading .shfill } stopped
  255. grestore { stop } if
  256. pop
  257. } odef
  258. % Establish an initial smoothness value that matches Adobe RIPs.
  259. 0.02 setsmoothness
  260. % ------ DeviceN color space ------ %
  261. %% Replace 1 (gs_ciecs3.ps)
  262. (gs_ciecs3.ps) runlibfile
  263. %% Replace 1 (gs_devn.ps)
  264. (gs_devn.ps) runlibfile
  265. % ------ Miscellaneous ------ %
  266. % Make the setoverprintmode and currentoverprintmode operators visible (3015)
  267. % Because of the requirements of PDF, the .currentoverprintmode and
  268. % .setoverprintmode operators have integer parameters. Thus wee need to
  269. % convert the Postscript bool parameters to integers.
  270. %
  271. /setoverprintmode % bool setoverprint -
  272. {
  273. { 1 } { 0 } ifelse % convert bool to integer
  274. //.setoverprintmode
  275. } odef
  276. /currentoverprintmode % - currentoverprintmode bool
  277. {
  278. //.currentoverprintmode
  279. 0 ne % convert integers to bool
  280. } odef
  281. % Define additional user and system parameters.
  282. /HalftoneMode 0 .definepsuserparam
  283. /MaxSuperScreen 1016 .definepsuserparam
  284. pssystemparams begin % read-only, so use .forcedef
  285. /MaxDisplayAndSourceList 160000 .forcedef
  286. end
  287. % Define the IdiomSet resource category.
  288. { /IdiomSet } {
  289. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  290. /InstanceType /dicttype def
  291. currentdict end /Category defineresource pop
  292. } forall
  293. /languagelevel 3 def
  294. % When running in LanguageLevel 3 mode, this interpreter is supposed to be
  295. % compatible with Adobe version 3010.
  296. /version (3010) readonly def
  297. .setlanguagelevel
  298. end % ll3dict