星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

gs_ll3.ps 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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 10300 2009-11-09 18:42:04Z alexcher $
  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. } def
  53. /.bind /.bind_ load odef % note that .bind_ will get bound
  54. currentdict /.bindscratch .undef
  55. DELAYBIND NOBIND or not {
  56. % We can't just do
  57. % /bind /.bind load def
  58. % because then /bind load == prints --.bind-- .
  59. /bind {//.bind_ exec} odef
  60. } if
  61. currentdict /.bind_ undef
  62. % ------ HalftoneTypes 6, 10, 16 and HalftoneMode ------ %
  63. % This code depends on an internal HalftoneType 7 with the following keys:
  64. % Width, Height, Width2, Height2, TransferFunction:
  65. % as for HalftoneType 16.
  66. % Thresholds: a string or bytestring holding the thresholds,
  67. % (Width x Height + Width2 x Height2) x BitsPerSample / 8 bytes,
  68. % as for HalftoneType 16 except that the samples may be either
  69. % 8 or 16 bits wide.
  70. % BitsPerSample: 8 or 16.
  71. % Note that this HalftoneType never appears in halftone dictionaries given
  72. % to sethalftone, only as a component in those given to .sethalftone5,
  73. % so its numeric value can be chosen ad lib as long as it differs from the
  74. % other values that are legal in component dictionaries for .sethalftone5
  75. % (currently only 1 and 3).
  76. /.makehalftone7 { % <dict> <dict> <source> <Width> <Height>
  77. % (<Width2> <Height2> | null) <BPS> .makehalftone7
  78. % <setdict> <dict5> { .sethalftone5 }
  79. 8 dict begin
  80. /HalftoneType 7 def
  81. /BitsPerSample exch def
  82. dup null eq {
  83. pop 0
  84. } {
  85. /Height2 1 index def /Width2 2 index def mul
  86. } ifelse 3 1 roll
  87. /Height 1 index def
  88. /Width 2 index def
  89. mul add BitsPerSample 8 idiv mul .bigstring
  90. % Stack: dict dict source str
  91. dup type /stringtype eq { readstring } { .readbytestring } ifelse
  92. not { /sethalftone .systemvar /rangecheck signalerror exit } if
  93. readonly /Thresholds exch def
  94. /TransferFunction .knownget { /TransferFunction exch def } if
  95. % If the original Thresholds was a file, replace it with
  96. % a new one.
  97. dup /Thresholds get type /filetype eq {
  98. dup /Thresholds [ Thresholds ] cvx 0 () .subfiledecode put
  99. } if
  100. mark /HalftoneType 5 /Default currentdict end .dicttomark
  101. { .sethalftone5 }
  102. } bind def
  103. /.bigstring { % <size> .bigstring <string|bytestring>
  104. dup 65400 gt { .bytestring } { string } ifelse
  105. } bind def
  106. /.readbytestring { % <source> <bytestring> .readbytestring
  107. % <bytestring> <filled>
  108. % Note that since bytestrings don't implement getinterval,
  109. % if filled is false, there is no way to tell how much
  110. % was read.
  111. true exch 0 1 2 index length 1 sub {
  112. % Stack: source true str index
  113. 3 index read not { pop exch not exch exit } if
  114. 3 copy put pop pop
  115. } for 3 -1 roll pop exch
  116. } bind def
  117. /.sethalftone6 { % <dict> <dict> .sethalftone6 <setdict> <dict5>
  118. % { .sethalftone5 }
  119. % Keys: Width, Height, Thresholds, T'Function
  120. dup /Thresholds get
  121. 1 index /Width get 2 index /Height get
  122. null 8 .makehalftone7
  123. } bind def
  124. /.sethalftone10 { % <dict> <dict> .sethalftone10 <setdict> <dict5>
  125. % { .sethalftone5 }
  126. % Keys: Xsquare, Ysquare, Thresholds, T'Function
  127. % Note that this is the only one of these three HalftoneTypes
  128. % that allows either a file or a string for Thresholds.
  129. dup /Thresholds get dup type /stringtype eq { 0 () .subfiledecode } if
  130. 1 index /Xsquare get dup 3 index /Ysquare get dup
  131. 8 .makehalftone7
  132. } bind def
  133. /.sethalftone16 { % <dict> <dict> .sethalftone16 <setdict> <dict5>
  134. % { .sethalftone5 }
  135. % Keys: Width, Height, Width2, Height2,
  136. % Thresholds, T'Function
  137. dup /Thresholds get
  138. 1 index /Width get 2 index /Height get
  139. 3 index /Width2 .knownget { % 2-rectangle case
  140. 4 index /Height2 get
  141. } { % 1-rectangle case
  142. null
  143. } ifelse 16 .makehalftone7
  144. } bind def
  145. .halftonetypes begin
  146. 6 /.sethalftone6 load def
  147. 10 /.sethalftone10 load def
  148. 16 /.sethalftone16 load def
  149. end
  150. % Redefine the halftone-setting operators to honor HalftoneMode.
  151. /setcolorscreen {
  152. /HalftoneMode getuserparam 0 eq {
  153. //setcolorscreen
  154. } {
  155. 12 { pop } repeat .getdefaulthalftone
  156. { //sethalftone }
  157. { .setdefaulthalftone }
  158. ifelse
  159. } ifelse
  160. } odef
  161. /setscreen {
  162. /HalftoneMode getuserparam 0 eq {
  163. //setscreen
  164. } {
  165. pop pop pop .getdefaulthalftone
  166. { //sethalftone }
  167. { .setdefaulthalftone }
  168. ifelse
  169. } ifelse
  170. } odef
  171. /sethalftone {
  172. /HalftoneMode getuserparam 0 eq {
  173. //sethalftone
  174. } {
  175. gsave //sethalftone grestore
  176. .getdefaulthalftone
  177. { //sethalftone }
  178. { .setdefaulthalftone }
  179. ifelse
  180. } ifelse
  181. } odef
  182. % ------ ImageTypes 3 and 4 (masked images) ------ %
  183. % Put the new data source in the requested dictionary.
  184. % Copy the updated dictionary because it nay be used elsewhere.
  185. % <dict> <data> <name> update_image3 <dict'>
  186. /update_image3 {
  187. 3 -1 roll dup length dict copy dup % [data] /name <<image>> <<image>>
  188. 2 index get % [data] /name <<image>> <<sub-image>>
  189. dup length dict copy dup % [data] /name <<image>> <<sub-image>> <<sub-image>>
  190. /DataSource 6 -1 roll put % /name <<image>> <<sub-image>>
  191. exch dup % /name <<sub-image>> <<image>> <<image>>
  192. 4 2 roll % <<image>> <<image>> /name <<sub-image>>
  193. put % <<image>>
  194. } bind def
  195. % Copy mask data source to a reusable stream
  196. % <dict> <source> buffer_mask <dict> <file>
  197. /buffer_mask {
  198. 1 index /MaskDict get
  199. dup /Width get
  200. 1 index /BitsPerComponent get mul 7 add 8 idiv
  201. exch /Height get mul () /SubFileDecode filter
  202. /ReusableStreamDecode filter
  203. } bind def
  204. % Data type vs. mask type decission table.
  205. % All procedures have the signature:
  206. % <image dict> <data DataSource> <mask DataSource> proc <image dict'>
  207. /data_mask_dict mark
  208. /stringtype mark % data is a string
  209. /stringtype { pop pop } bind
  210. /arraytype { % convert data to proc, don't buffer mask
  211. pop
  212. dup type dup /arraytype eq exch /packedarraytype eq or {
  213. [ exch { 1 array astore cvx } forall ]
  214. } {
  215. 1 array astore cvx
  216. } ifelse
  217. /DataDict //update_image3 exec
  218. } bind
  219. /packedarraytype 1 index
  220. /filetype { % convert data to file, don't buffer mask
  221. pop
  222. dup type dup /arraytype eq exch /packedarraytype eq or {
  223. [ exch { 1 array astore cvx 0 () /SubFileDecode filter } forall ]
  224. } {
  225. 1 array astore cvx 0 () /SubFileDecode filter
  226. } ifelse
  227. /DataDict //update_image3 exec
  228. } bind
  229. .dicttomark readonly
  230. /arraytype mark % data is a proc
  231. /stringtype { % convert mask to proc
  232. exch pop
  233. 1 array astore cvx
  234. /MaskDict //update_image3 exec
  235. } bind
  236. /arraytype { % buffer mask in reusable stream and convert back to proc
  237. exch pop
  238. //buffer_mask exec
  239. 500 string
  240. { readstring pop } aload pop
  241. 4 packedarray cvx
  242. /MaskDict //update_image3 exec
  243. } bind
  244. /packedarraytype 1 index
  245. /filetype 1 index
  246. .dicttomark readonly
  247. /packedarraytype 1 index
  248. /filetype mark % data is a file
  249. /stringtype { % convert mask to file
  250. exch pop
  251. 1 array astore cvx 0 () /SubFileDecode filter
  252. /MaskDict //update_image3 exec
  253. } bind
  254. /arraytype { % buffer the mask and convert to file
  255. exch pop
  256. //buffer_mask exec
  257. /MaskDict //update_image3 exec
  258. } bind
  259. /packedarraytype 1 index
  260. /filetype {
  261. //systemdict /userdict get /PDFTopSave known {
  262. pop pop % mask is already buffered by PDF interpreter
  263. } {
  264. exch pop % buffer the mask
  265. //buffer_mask exec
  266. /MaskDict //update_image3 exec
  267. } ifelse
  268. } bind
  269. .dicttomark readonly
  270. .dicttomark readonly def
  271. .imagetypes
  272. dup 3 {
  273. dup /InterleaveType get 3 eq {
  274. % .image3 requires data sources of the image and mask to be of the
  275. % same type. Work around this restriction here.
  276. dup /DataDict get /DataSource get
  277. 1 index /MaskDict get /DataSource get % <<>> data mask
  278. dup type % <<>> data mask mask_type
  279. 2 index
  280. 4 index /DataDict get /MultipleDataSources .knownget {
  281. { 0 get } if
  282. } if
  283. type % <<>> data mask mask_type data_type
  284. //data_mask_dict exch .knownget {
  285. exch .knownget {
  286. exec
  287. } {
  288. pop pop % pass wrong type as is to .image3
  289. } ifelse
  290. } {
  291. pop pop pop % pass wrong type as is to .image3
  292. } ifelse
  293. } if
  294. .image3
  295. } bind put
  296. dup 4 /.image4 load put
  297. % We also detect ImageType 103 here: it isn't worth making a separate file
  298. % just for this.
  299. /.image3x where { pop dup 103 /.image3x load put } if
  300. pop
  301. currentdict /data_mask_dict undef
  302. currentdict /update_image3 undef
  303. currentdict /buffer_mask undef
  304. % ------ Functions ------ %
  305. % Define the FunctionType resource category.
  306. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  307. /InstanceType /integertype def
  308. /FunctionType currentdict end /Category defineresource pop
  309. {0 2 3} { dup /FunctionType defineresource pop } forall
  310. % ------ Smooth shading ------ %
  311. % Define the ShadingType resource category.
  312. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  313. /InstanceType /integertype def
  314. /ShadingType currentdict end /Category defineresource pop
  315. systemdict /.shadingtypes mark % not ll3dict
  316. 1 /.buildshading1 load
  317. 2 /.buildshading2 load
  318. 3 /.buildshading3 load
  319. 4 /.buildshading4 load
  320. 5 /.buildshading5 load
  321. 6 /.buildshading6 load
  322. 7 /.buildshading7 load
  323. .dicttomark put
  324. systemdict /.reuseparamdict mark
  325. /Intent 2
  326. /AsyncRead false
  327. /CloseSource true
  328. .dicttomark readonly put
  329. /.buildshading { % <shadingdict> .buildshading <shading>
  330. dup rcheck not {
  331. % Adobe seems to access ColorSpace first and CET 12-14c checks this.
  332. /$error .systemvar /errorinfo [ /ColorSpace null ] put
  333. /shfill .systemvar /invalidaccess signalerror
  334. } if
  335. % Unfortunately, we always need to make the DataSource reusable,
  336. % because if clipping is involved, even shfill may need to read
  337. % the source data multiple times. If it weren't for this,
  338. % we would only need to create a reusable stream if the ultimate
  339. % source of the data is a procedure (since the library can't
  340. % suspend shading to do a procedure callout).
  341. dup /DataSource .knownget {
  342. dup type /filetype eq {
  343. //.reuseparamdict /ReusableStreamDecode filter
  344. % Copy the dictionary to replace the DataSource, but make sure the
  345. % copy is in the same VM as the original.
  346. .currentglobal 2 index gcheck .setglobal
  347. % Stack: shdict rsdfile saveglobal
  348. 2 index dup length dict copy exch .setglobal
  349. dup /DataSource 4 -1 roll put exch pop
  350. } {
  351. pop
  352. } ifelse
  353. } if
  354. % The .buildshading operators use the current color space
  355. % for ColorSpace.
  356. dup /ShadingType .knownget not { % error handling for CET 12-14b conformance
  357. /$error .systemvar /errorinfo [ /ShadingType //null ] put
  358. /shfill .systemvar /undefined signalerror
  359. } if
  360. dup type /integertype ne {
  361. /$error .systemvar /errorinfo [ /ShadingType 4 index ] put
  362. /shfill .systemvar /typecheck signalerror
  363. } if
  364. //.shadingtypes 1 index .knownget not {
  365. /$error .systemvar /errorinfo [ /ShadingType 4 index ] put
  366. /shfill .systemvar /rangecheck signalerror
  367. } if
  368. exch pop 1 index /ColorSpace .knownget {
  369. { setcolorspace } stopped {
  370. /$error .systemvar /errorinfo [ /ColorSpace 4 index ] put
  371. /shfill .systemvar /$error .systemvar /errorname get signalerror
  372. } if
  373. exec
  374. } {
  375. /$error .systemvar /errorinfo [ /ColorSpace //null ] put
  376. /shfill .systemvar /undefined signalerror
  377. } ifelse
  378. } bind def
  379. systemdict /.reuseparamdict undef
  380. /.buildpattern2 { % <template> <matrix> .buildpattern2
  381. % <template> <pattern>
  382. % We want to build the pattern without doing gsave/grestore,
  383. % since we want it to load the CIE caches.
  384. 1 index /Shading get
  385. mark currentcolor currentcolorspace
  386. counttomark 4 add -3 roll mark 4 1 roll
  387. % Stack: -mark- ..color.. cspace -mark- template matrix shadingdict
  388. { .buildshading } stopped {
  389. cleartomark setcolorspace setcolor pop stop
  390. } if
  391. .buildshadingpattern
  392. 3 -1 roll pop counttomark 1 add 2 roll setcolorspace setcolor pop
  393. } bind def
  394. .patterntypes
  395. 2 /.buildpattern2 load put
  396. /shfill { % <shadingdict> shfill -
  397. % Currently, .shfill requires that the color space
  398. % in the pattern be the current color space.
  399. % Disable overprintmode for shfill
  400. { dup gsave 0 .setoverprintmode .buildshading .shfill } stopped
  401. grestore {
  402. /$error .systemvar /errorinfo 2 copy known {
  403. pop pop
  404. } {
  405. //null put % CET 12-14c
  406. } ifelse
  407. stop
  408. } if
  409. pop
  410. } odef
  411. % Establish an initial smoothness value that matches Adobe RIPs.
  412. 0.02 setsmoothness
  413. % ------ DeviceN color space ------ %
  414. % gs_res.ps uses these entries in colorspacedict
  415. % to populate the ColorSpaceFamily resource, so we need
  416. % to add the supported spaces.
  417. %
  418. systemdict /colorspacedict get begin
  419. /CIEBasedDEF [] def
  420. /CIEBasedDEFG [] def
  421. /DeviceN [] def
  422. end
  423. % ------ Miscellaneous ------ %
  424. % Make the setoverprintmode and currentoverprintmode operators visible (3015)
  425. % Because of the requirements of PDF, the .currentoverprintmode and
  426. % .setoverprintmode operators have integer parameters. Thus we need to
  427. % convert the Postscript bool parameters to integers.
  428. %
  429. /setoverprintmode % bool setoverprint -
  430. {
  431. { 1 } { 0 } ifelse % convert bool to integer
  432. //.setoverprintmode
  433. } odef
  434. /currentoverprintmode % - currentoverprintmode bool
  435. {
  436. //.currentoverprintmode
  437. 0 ne % convert integers to bool
  438. } odef
  439. % Define additional user and system parameters.
  440. /HalftoneMode 0 .definepsuserparam
  441. /MaxSuperScreen 1016 .definepsuserparam
  442. pssystemparams begin % read-only, so use .forcedef
  443. /MaxDisplayAndSourceList 160000 .forcedef
  444. end
  445. % Define the IdiomSet resource category.
  446. { /IdiomSet } {
  447. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  448. /InstanceType /dicttype def
  449. currentdict end /Category defineresource pop
  450. } forall
  451. /languagelevel 3 def
  452. % When running in LanguageLevel 3 mode, this interpreter is supposed to be
  453. % compatible with Adobe version 3010.
  454. /version (3010) readonly def
  455. .setlanguagelevel
  456. end % ll3dict