星火微课系统客户端
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.

gs_lev2.ps 34KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. % Copyright (C) 1990, 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_lev2.ps 8962 2008-08-11 14:16:18Z ken $
  16. % Initialization file for Level 2 functions.
  17. % When this is run, systemdict is still writable,
  18. % but (almost) everything defined here goes into level2dict.
  19. level2dict begin
  20. % ------ System and user parameters ------ %
  21. % User parameters must obey save/restore, and must also be maintained
  22. % per-context. We implement the former, and some of the latter, here
  23. % with PostScript code. NOTE: our implementation assumes that user
  24. % parameters change only as a result of setuserparams -- that there are
  25. % no user parameters that are ever changed dynamically by the interpreter
  26. % (although the interpreter may adjust the value presented to setuserparams)
  27. %
  28. % There are two types of user parameters: those which are actually
  29. % maintained in the interpreter, and those which exist only at the
  30. % PostScript level. We maintain the current state of both types in
  31. % a read-only local dictionary named userparams, defined in systemdict.
  32. % In a multi-context system, each context has its own copy of this
  33. % dictionary. In addition, there is a constant dictionary named
  34. % psuserparams where each key is the name of a user parameter that exists
  35. % only in PostScript and the value is a procedure to check that the value
  36. % is legal: setuserparams uses this for checking the values.
  37. % setuserparams updates userparams explicitly, in addition to setting
  38. % any user parameters in the interpreter; thus we can use userparams
  39. % to reset those parameters after a restore or a context switch.
  40. % NOTE: the name userparams is known to the interpreter, and in fact
  41. % the interpreter creates the userparams dictionary.
  42. % Check parameters that are managed at the PostScript level.
  43. /.checkparamtype { % <newvalue> <type> .checkparamtype <bool>
  44. exch type eq
  45. } .bind def
  46. /.checksetparams { % <newdict> <opname> <checkdict>
  47. % .checksetparams <newdict>
  48. 2 .argindex {
  49. % Stack: newdict opname checkdict key newvalue
  50. 3 copy 3 1 roll .knownget {
  51. exec not {
  52. pop pop pop load /typecheck signalerror
  53. } if
  54. dup type /stringtype eq {
  55. dup rcheck not {
  56. pop pop pop load /invalidaccess signalerror
  57. } if
  58. } if
  59. } {
  60. pop
  61. } ifelse pop pop
  62. } forall pop pop
  63. } .bind def % not odef, shouldn't reset stacks
  64. % currentuser/systemparams creates and returns a dictionary in the
  65. % current VM. The easiest way to make this work is to copy any composite
  66. % PostScript-level parameters to global VM. Currently we have strings
  67. % as well as arrays. For arrays, we also need to copy any contents that
  68. % are in VM. Also copying string parameters insures the contents won't
  69. % be changed. Also be careful to preserve 'executable' state.
  70. /.copyparam { % <value> .copyparam <value'>
  71. dup type /arraytype eq {
  72. .currentglobal true .setglobal exch
  73. dup wcheck exch dup xcheck exch % original attributes
  74. dup length array exch dup { % stack: destination_array original_array original_array
  75. dup type /arraytype eq {
  76. dup 2 index ne { % avoid recursion
  77. .copyparam % recurse to handle composite array elements
  78. } {
  79. % this array self referenced, do it again (yuk!)
  80. pop 1 index % get copy of destination array
  81. } ifelse
  82. } {
  83. dup type /stringtype eq {
  84. .copyparam
  85. } if
  86. }
  87. ifelse 3 1 roll % keep arrays on top
  88. } forall pop astore
  89. exch { cvx } if % set executable state
  90. exch not { readonly } if % set readonly attribute as original
  91. exch .setglobal
  92. } if
  93. dup type /stringtype eq {
  94. dup wcheck exch % save attr for setting readonly
  95. .currentglobal true .setglobal
  96. 1 index length string exch .setglobal
  97. copy exch not { readonly } if
  98. } if
  99. } .bind def
  100. % Some user parameters are managed entirely at the PostScript level.
  101. % We take care of that here.
  102. systemdict begin
  103. /psuserparams 48 dict def
  104. /getuserparam { % <name> getuserparam <value>
  105. /userparams .systemvar 1 .argindex get exch pop
  106. } odef
  107. % Fill in userparams (created by the interpreter) with current values.
  108. mark .currentuserparams
  109. counttomark 2 idiv {
  110. userparams 3 1 roll put
  111. } repeat pop
  112. /.definepsuserparam { % <name> <value> .definepsuserparam -
  113. psuserparams 3 copy pop
  114. type cvlit /.checkparamtype cvx 2 packedarray cvx put
  115. userparams 3 1 roll put
  116. } .bind def
  117. end
  118. /currentuserparams { % - currentuserparams <dict>
  119. /userparams .systemvar dup length dict .copydict
  120. } odef
  121. % We break out setuserparams into a separate procedure so that setvmxxx
  122. % can use it without affecting the command in case of an error.
  123. /.setuserparams2 {
  124. % Check that we will be able to set the PostScript-level
  125. % user parameters.
  126. /setuserparams /psuserparams .systemvar .checksetparams
  127. % Set the C-level user params. If this succeeds, we know that
  128. % the password check succeeded.
  129. dup .setuserparams
  130. % Now set the PostScript-level params.
  131. % The interpreter may have adjusted the values of some of the
  132. % parameters, so we have to read them back.
  133. dup {
  134. /userparams .systemvar 2 index known {
  135. psuserparams 2 index known not {
  136. pop dup .getuserparam
  137. } if
  138. .copyparam
  139. % special protection for the security related parameters
  140. [ /PermitFileReading /PermitFileWriting /PermitFileControl ]
  141. { 2 index eq { % force all strings to readonly but make sure the
  142. % array is in the correct VM space (local/global).
  143. currentglobal exch dup gcheck setglobal
  144. dup length array exch { readonly exch } forall astore
  145. exch setglobal
  146. } if
  147. } forall
  148. % protect top level of parameters that we copied
  149. dup type dup /arraytype eq exch /stringtype eq or { readonly } if
  150. /userparams .systemvar 3 1 roll .forceput % userparams is read-only
  151. } {
  152. pop pop
  153. } ifelse
  154. } forall
  155. % A context switch might have occurred during the above loop,
  156. % causing the interpreter-level parameters to be reset.
  157. % Set them again to the new values. From here on, we are safe,
  158. % since a context switch will consult userparams.
  159. .setuserparams
  160. } .bind def
  161. /setuserparams { % <dict> setuserparams -
  162. .setuserparams2
  163. } .bind odef
  164. % Initialize user parameters managed here.
  165. /JobName () .definepsuserparam
  166. % Restore must restore the user parameters.
  167. % (Since userparams is in local VM, save takes care of saving them.)
  168. /restore { % <save> restore -
  169. //restore /userparams .systemvar .setuserparams
  170. } .bind odef
  171. % The pssystemparams dictionary holds some system parameters that
  172. % are managed entirely at the PostScript level.
  173. systemdict begin
  174. currentdict /pssystemparams known not {
  175. /pssystemparams 40 dict readonly def
  176. } if
  177. /getsystemparam { % <name> getsystemparam <value>
  178. //pssystemparams 1 .argindex .knownget { exch pop } { .getsystemparam } ifelse
  179. } odef
  180. end
  181. /currentsystemparams { % - currentsystemparams <dict>
  182. mark .currentsystemparams //pssystemparams { } forall .dicttomark
  183. } odef
  184. /setsystemparams { % <dict> setsystemparams -
  185. % Check that we will be able to set the PostScript-level
  186. % system parameters.
  187. dup pop % check # of args
  188. /SAFETY .systemvar /safe get {
  189. % SAFER mode disallows some changes
  190. [ /GenericResourceDir /FontResourceDir /GenericResourcePathSep ] {
  191. 2 copy .knownget {
  192. exch //pssystemparams exch .knownget {
  193. ne { /setsystemparams /invalidaccess signalerror } if
  194. } {
  195. pop
  196. } ifelse
  197. } {
  198. pop
  199. } ifelse
  200. } forall
  201. } if
  202. /setsystemparams //pssystemparams mark exch {
  203. type cvlit /.checkparamtype cvx 2 packedarray cvx
  204. } forall .dicttomark .checksetparams
  205. % Set the C-level system params. If this succeeds, we know that
  206. % the password check succeeded.
  207. dup .setsystemparams
  208. % Now set the PostScript-level params. We must copy local strings
  209. % into global VM.
  210. dup
  211. { //pssystemparams 2 index known
  212. { % Stack: key newvalue
  213. .copyparam
  214. % protect top level parameters that we copied
  215. dup type dup /arraytype eq exch /stringtype eq or { readonly } if
  216. //pssystemparams 3 1 roll .forceput % pssystemparams is read-only
  217. }
  218. { pop pop
  219. }
  220. ifelse
  221. }
  222. forall pop
  223. } .bind odef
  224. % Initialize the passwords.
  225. % NOTE: the names StartJobPassword and SystemParamsPassword are known to
  226. % the interpreter, and must be bound to noaccess strings.
  227. % The length of these strings must be max_password (iutil2.h) + 1.
  228. /StartJobPassword 65 string noaccess def
  229. /SystemParamsPassword 65 string noaccess def
  230. % Redefine cache parameter setting to interact properly with userparams.
  231. /setcachelimit {
  232. { mark /MaxFontItem 2 .argindex .dicttomark setuserparams pop }
  233. stopped
  234. { /setcachelimit .systemvar $error /errorname get signalerror
  235. } if
  236. } .bind odef
  237. /setcacheparams {
  238. % The MaxFontCache parameter is a system parameter, which we might
  239. % not be able to set. Fortunately, this doesn't matter, because
  240. % system parameters don't have to be synchronized between this code
  241. % and the VM.
  242. counttomark 1 add copy setcacheparams
  243. currentcacheparams % mark size lower upper
  244. 3 -1 roll pop
  245. /MinFontCompress 3 1 roll
  246. /MaxFontItem exch
  247. .dicttomark { setuserparams cleartomark } stopped {
  248. /setcacheparams .systemvar $error /errorname get signalerror
  249. } if
  250. } .bind odef
  251. % Add bogus user and system parameters to satisfy badly written PostScript
  252. % programs that incorrectly assume the existence of all the parameters
  253. % listed in Appendix C of the Red Book. Note that some of these may become
  254. % real parameters later: code near the end of gs_init.ps takes care of
  255. % removing any such parameters from ps{user,system}params.
  256. % psuserparams
  257. /MaxFormItem 100000 .definepsuserparam
  258. /MaxPatternItem 20000 .definepsuserparam
  259. /MaxScreenItem 48000 .definepsuserparam
  260. /MaxUPathItem 0 .definepsuserparam
  261. % File Access Permission parameters
  262. .currentglobal true .setglobal
  263. /.checkFilePermitparams {
  264. type /arraytype eq {
  265. currentuserparams /LockFilePermissions get {
  266. 5 { pop } repeat /setuserparams /invalidaccess signalerror
  267. }{
  268. % in addition to validating the value, ensure the value is read/only
  269. dup { readonly exch } forall
  270. .currentglobal exch dup gcheck .setglobal length array exch .setglobal
  271. astore readonly
  272. }
  273. ifelse
  274. } {
  275. 5 { pop } repeat /setuserparams /typecheck signalerror
  276. }
  277. ifelse
  278. true
  279. } .bind def
  280. % Initialize the File Permission access control to wide open
  281. % These will only be accessed via current/set userparams.
  282. % Values are a string containing multiple nul terminated path strings
  283. /PermitFileReading dup [ (*) ] .definepsuserparam
  284. psuserparams exch /.checkFilePermitparams load put
  285. /PermitFileWriting dup [ (*) ] .definepsuserparam
  286. psuserparams exch /.checkFilePermitparams load put
  287. /PermitFileControl dup [ (*) ] .definepsuserparam
  288. psuserparams exch /.checkFilePermitparams load put
  289. .setglobal
  290. pssystemparams begin
  291. /CurDisplayList 0 .forcedef
  292. /CurFormCache 0 .forcedef
  293. /CurInputDevice () .forcedef
  294. /CurOutlineCache 0 .forcedef
  295. /CurOutputDevice () .forcedef
  296. /CurPatternCache 0 .forcedef
  297. /CurUPathCache 0 .forcedef
  298. /CurScreenStorage 0 .forcedef
  299. /CurSourceList 0 .forcedef
  300. /DoPrintErrors false .forcedef
  301. /JobTimeout 0 .forcedef
  302. /LicenseID (LN-001) .forcedef % bogus
  303. /MaxDisplayList 140000 .forcedef
  304. /MaxFormCache 100000 .forcedef
  305. /MaxImageBuffer 524288 .forcedef
  306. /MaxOutlineCache 65000 .forcedef
  307. /MaxPatternCache 100000 .forcedef
  308. /MaxUPathCache 300000 .forcedef
  309. /MaxScreenStorage 84000 .forcedef
  310. /MaxSourceList 25000 .forcedef
  311. /PrinterName product .forcedef
  312. /RamSize 4194304 .forcedef
  313. /WaitTimeout 40 .forcedef
  314. end
  315. % Define the procedures for handling comment scanning. The names
  316. % %ProcessComment and %ProcessDSCComment are known to the interpreter.
  317. % These procedures take the file and comment string and file as operands.
  318. /.checkprocesscomment {
  319. dup null eq {
  320. pop true
  321. } {
  322. dup xcheck {
  323. type dup /arraytype eq exch /packedarraytype eq or
  324. } {
  325. pop false
  326. } ifelse
  327. } ifelse
  328. } .bind def
  329. /ProcessComment null .definepsuserparam
  330. psuserparams /ProcessComment {.checkprocesscomment} put
  331. (%ProcessComment) cvn {
  332. /ProcessComment getuserparam
  333. dup null eq { pop pop pop } { exec } ifelse
  334. } bind def
  335. /ProcessDSCComment null .definepsuserparam
  336. psuserparams /ProcessDSCComment {.checkprocesscomment} put
  337. /.loadingfont false def
  338. (%ProcessDSCComment) cvn {
  339. /ProcessDSCComment getuserparam
  340. dup null eq .loadingfont or { pop pop pop } { exec } ifelse
  341. } bind def
  342. % ------ Miscellaneous ------ %
  343. (<<) cvn % - << -mark-
  344. /mark load def
  345. % (>> is defined primitively.)
  346. /languagelevel 2 def
  347. % When running in Level 2 mode, this interpreter is supposed to be
  348. % compatible with Adobe version 2017.
  349. /version (2017) readonly def
  350. % If binary tokens are supported by this interpreter,
  351. % set an appropriate default binary object format.
  352. /setobjectformat where
  353. { pop
  354. /RealFormat getsystemparam (IEEE) eq { 1 } { 3 } ifelse
  355. /ByteOrder getsystemparam { 1 add } if
  356. setobjectformat
  357. } if
  358. % Aldus Freehand versions 2.x check for the presence of the
  359. % setcolor operator, and if it is missing, substitute a procedure.
  360. % Unfortunately, the procedure takes different parameters from
  361. % the operator. As a result, files produced by this application
  362. % cause an error if the setcolor operator is actually defined
  363. % and 'bind' is ever used. Aldus fixed this bug in Freehand 3.0,
  364. % but there are a lot of files created by the older versions
  365. % still floating around. Therefore, at Adobe's suggestion,
  366. % we implement the following dreadful hack in the 'where' operator:
  367. % If the key is /setcolor, and
  368. % there is a dictionary named FreeHandDict, and
  369. % currentdict is that dictionary,
  370. % then "where" consults only that dictionary and not any other
  371. % dictionaries on the dictionary stack.
  372. .wheredict /setcolor {
  373. /FreeHandDict .where {
  374. /FreeHandDict get currentdict eq {
  375. pop currentdict /setcolor known { currentdict true } { false } ifelse
  376. } {
  377. .where
  378. } ifelse
  379. } {
  380. .where
  381. } ifelse
  382. } bind put
  383. % ------ Virtual memory ------ %
  384. /currentglobal % - currentglobal <bool>
  385. /currentshared load def
  386. /gcheck % <obj> gcheck <bool>
  387. /scheck load def
  388. /setglobal % <bool> setglobal -
  389. /setshared load def
  390. % We can make the global dictionaries very small, because they auto-expand.
  391. /globaldict currentdict /shareddict .knownget not { 4 dict } if def
  392. /GlobalFontDirectory SharedFontDirectory def
  393. % VMReclaim and VMThreshold are user parameters.
  394. /setvmthreshold { % <int> setvmthreshold -
  395. mark /VMThreshold 2 .argindex .dicttomark .setuserparams2 pop
  396. } odef
  397. /vmreclaim { % <int> vmreclaim -
  398. dup 0 gt {
  399. .vmreclaim
  400. } {
  401. mark /VMReclaim 2 index .dicttomark .setuserparams2 pop
  402. } ifelse
  403. } odef
  404. -1 setvmthreshold
  405. % ------ IODevices ------ %
  406. /.getdevparams where {
  407. pop /currentdevparams { % <iodevice> currentdevparams <dict>
  408. .getdevparams .dicttomark
  409. } odef
  410. } if
  411. /.putdevparams where {
  412. pop /setdevparams { % <iodevice> <dict> setdevparams -
  413. dup type /dicttype ne { /setdevparams .systemvar /typecheck signalerror } if
  414. mark 1 index { } forall counttomark 2 add index
  415. .putdevparams pop pop
  416. } odef
  417. } if
  418. % ------ Job control ------ %
  419. serverdict begin
  420. % We could protect the job information better, but we aren't attempting
  421. % (currently) to protect ourselves against maliciousness.
  422. /.jobsave //null def % top-level save object
  423. /.jobsavelevel 0 def % save depth of job (0 if .jobsave is null,
  424. % 1 otherwise)
  425. /.adminjob //true def % status of current unencapsulated job
  426. end % serverdict
  427. % Because there may be objects on the e-stack created since the job save,
  428. % we have to clear the e-stack before doing the end-of-job restore.
  429. % We do this by executing a 2 .stop, which is caught by the 2 .stopped
  430. % in .runexec; we leave on the o-stack a procedure to execute aftewards.
  431. %
  432. %**************** The definition of startjob is not complete yet, since
  433. % it doesn't reset stdin/stdout.
  434. /.startnewjob { % <exit_bool> <password_level>
  435. % .startnewjob -
  436. serverdict /.jobsave get dup //null eq { pop } { restore } ifelse
  437. exch {
  438. % Unencapsulated job
  439. serverdict /.jobsave //null put
  440. serverdict /.jobsavelevel 0 put
  441. serverdict /.adminjob 3 -1 roll 1 gt put
  442. } {
  443. % Encapsulated job
  444. pop
  445. serverdict /.jobsave save put
  446. serverdict /.jobsavelevel 1 put
  447. .userdict /quit { stop } .bind put % CET 28-10 requires a procedure
  448. } ifelse
  449. % Reset the interpreter state.
  450. clear cleardictstack
  451. initgraphics
  452. //false setglobal
  453. 2 vmreclaim % Make sure GC'ed memory is reclaimed and freed.
  454. } bind def
  455. /.startjob { % <exit_bool> <password> <finish_proc>
  456. % .startjob <ok_bool>
  457. vmstatus pop pop serverdict /.jobsavelevel get eq
  458. 2 .argindex .checkpassword 0 gt and {
  459. exch .checkpassword exch count 3 roll count 3 sub { pop } repeat
  460. cleardictstack
  461. % Reset the e-stack back to the 2 .stopped in .runexec,
  462. % passing the finish_proc to be executed afterwards.
  463. 2 .stop
  464. } { % Password check failed
  465. pop pop pop //false
  466. } ifelse
  467. } odef
  468. /startjob { % <exit_bool> <password> startjob <ok_bool>
  469. % This is a hack. We really need some way to indicate explicitly
  470. % to the interpreter that we are under control of a job server.
  471. 1 .argindex type /booleantype ne {
  472. /startjob .systemvar /typecheck signalerror
  473. } if
  474. { .startnewjob //true } .startjob
  475. } odef
  476. % The procedure to undo the job encapsulation
  477. /.endjob {
  478. clear cleardictstack
  479. serverdict /.jobsave get dup //null eq { pop } { restore } ifelse
  480. serverdict /.jobsave //null put
  481. 2 vmreclaim % recover local and global VM
  482. } odef
  483. systemdict begin
  484. /quit { % - quit -
  485. //systemdict begin serverdict /.jobsave get null eq
  486. { end //quit }
  487. { /quit .systemvar /invalidaccess /signalerror load end exec }
  488. ifelse
  489. } bind odef
  490. end
  491. % We would like to define exitserver as a procedure, using the code
  492. % that the Red Book says is equivalent to it. However, since startjob
  493. % resets the exec stack, we can't do this, because control would never
  494. % proceed past the call on startjob if the exitserver is successful.
  495. % Instead, we need to construct exitserver out of pieces of startjob.
  496. serverdict begin
  497. /exitserver { % <password> exitserver -
  498. //true exch { .startnewjob } .startjob not {
  499. /exitserver /invalidaccess signalerror
  500. } if
  501. } bind def
  502. end % serverdict
  503. % ------ Compatibility ------ %
  504. % In Level 2 mode, the following replace the definitions that gs_statd.ps
  505. % installs in statusdict and serverdict.
  506. % Note that statusdict must be allocated in local VM.
  507. % We don't bother with many of these yet.
  508. /.dict1 { exch mark 3 1 roll .dicttomark } bind def
  509. currentglobal false setglobal 25 dict exch setglobal begin
  510. currentsystemparams
  511. % The following do not depend on the presence of setpagedevice.
  512. /buildtime 1 index /BuildTime get def
  513. % Also define /buildtime in systemdict because Adobe does so and some fonts use it as ID
  514. systemdict /buildtime dup load put
  515. /byteorder 1 index /ByteOrder get def
  516. /checkpassword { .checkpassword 0 gt } bind def
  517. dup /DoStartPage known
  518. { /dostartpage { /DoStartPage getsystemparam } bind def
  519. /setdostartpage { /DoStartPage .dict1 setsystemparams } bind def
  520. } if
  521. dup /StartupMode known
  522. { /dosysstart { /StartupMode getsystemparam 0 ne } bind def
  523. /setdosysstart { { 1 } { 0 } ifelse /StartupMode .dict1 setsystemparams } bind def
  524. } if
  525. %****** Setting jobname is supposed to set userparams.JobName, too.
  526. /jobname { /JobName getuserparam } bind def
  527. /jobtimeout { /JobTimeout getuserparam } bind def
  528. /ramsize { /RamSize getsystemparam } bind def
  529. /realformat 1 index /RealFormat get def
  530. dup /PrinterName known
  531. { /setprintername { /PrinterName .dict1 setsystemparams } bind def
  532. } if
  533. /printername
  534. { currentsystemparams /PrinterName .knownget not { () } if exch copy
  535. } bind def
  536. currentuserparams /WaitTimeout known
  537. { /waittimeout { /WaitTimeout getuserparam } bind def
  538. } if
  539. % The following do require setpagedevice.
  540. /.setpagedevice where { pop } { (%END PAGEDEVICE) .skipeof } ifelse
  541. /defaulttimeouts
  542. { currentsystemparams dup
  543. /JobTimeout .knownget not { 0 } if
  544. exch /WaitTimeout .knownget not { 0 } if
  545. currentpagedevice /ManualFeedTimeout .knownget not { 0 } if
  546. } bind def
  547. /margins
  548. { currentpagedevice /Margins .knownget { exch } { [0 0] } ifelse
  549. } bind def
  550. /pagemargin
  551. { currentpagedevice /PageOffset .knownget { 0 get } { 0 } ifelse
  552. } bind def
  553. /pageparams
  554. { currentpagedevice
  555. dup /Orientation .knownget { 1 and ORIENT1 { 1 xor } if } { 0 } ifelse exch
  556. dup /PageSize get aload pop 3 index 0 ne { exch } if 3 2 roll
  557. /PageOffset .knownget { 0 get } { 0 } ifelse 4 -1 roll
  558. } bind def
  559. /setdefaulttimeouts
  560. { exch mark /ManualFeedTimeout 3 -1 roll
  561. /Policies mark /ManualFeedTimeout 1 .dicttomark
  562. .dicttomark setpagedevice
  563. /WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams
  564. } bind def
  565. /.setpagesize { 2 array astore /PageSize .dict1 setpagedevice } bind def
  566. /setduplexmode { /Duplex .dict1 setpagedevice } bind def
  567. /setmargins
  568. { exch 2 array astore /Margins .dict1 setpagedevice
  569. } bind def
  570. /setpagemargin { 0 2 array astore /PageOffset .dict1 setpagedevice } bind def
  571. /setpageparams
  572. { mark /PageSize 6 -2 roll
  573. 4 index 1 and ORIENT1 { 1 } { 0 } ifelse ne { exch } if 2 array astore
  574. /Orientation 5 -1 roll ORIENT1 { 1 xor } if
  575. /PageOffset counttomark 2 add -1 roll 0 2 array astore
  576. .dicttomark setpagedevice
  577. } bind def
  578. /setresolution
  579. { dup 2 array astore /HWResolution .dict1 setpagedevice
  580. } bind def
  581. %END PAGEDEVICE
  582. % The following are not implemented yet.
  583. %manualfeed
  584. %manualfeedtimeout
  585. %pagecount
  586. %pagestackorder
  587. %setpagestackorder
  588. pop % currentsystemparams
  589. % Flag the current dictionary so it will be swapped when we
  590. % change language levels. (See zmisc2.c for more information.)
  591. /statusdict currentdict def
  592. currentdict end
  593. /statusdict exch .forcedef % statusdict is local, systemdict is global
  594. % The following compatibility operators are in systemdict. They are
  595. % defined here, rather than in gs_init.ps, because they require the
  596. % resource machinery.
  597. /devforall { % <proc> <scratch> devforall -
  598. exch {
  599. 1 index currentdevparams
  600. /Type .knownget { /FileSystem eq } { false } ifelse
  601. { exec } { pop pop } ifelse
  602. } /exec load 3 packedarray cvx exch
  603. (*) 3 1 roll /IODevice resourceforall
  604. } odef
  605. /devstatus { % <(%disk*%)> devstatus <searchable> <writable>
  606. % <hasNames> <mounted> <removable> <searchOrder>
  607. % <freePages> <size> true
  608. % <string> devstatus false
  609. dup length 5 ge {
  610. dup 0 5 getinterval (%disk) eq {
  611. dup /IODevice resourcestatus {
  612. pop pop dup currentdevparams
  613. dup /Searchable get
  614. exch dup /Writeable get
  615. exch dup /HasNames get
  616. exch dup /Mounted get
  617. exch dup /Removable get
  618. exch dup /SearchOrder get
  619. exch dup /Free get
  620. exch /LogicalSize get
  621. 9 -1 roll pop true
  622. } {
  623. pop false
  624. } ifelse
  625. } {
  626. pop false
  627. } ifelse
  628. } {
  629. pop false
  630. } ifelse
  631. } odef
  632. % ------ Color spaces ------ %
  633. % gs_res.ps uses these entries in colorspacedict
  634. % to populate the ColorSpaceFamily resource, so we need
  635. % to add the supported spaces.
  636. %
  637. systemdict /colorspacedict get begin
  638. /CIEBasedA [] def
  639. /CIEBasedABC [] def
  640. /DevicePixel [] def
  641. /Indexed [] def
  642. /Pattern [] def
  643. /Separation [] def
  644. end
  645. % ------ CIE color rendering ------ %
  646. % Define findcolorrendering and a default ColorRendering ProcSet.
  647. /findcolorrendering { % <intentname> findcolorrendering
  648. % <crdname> <found>
  649. % Adobe interpreters report /findcolorrendering (literal name), not the
  650. % operator itself, if an error occurs in findcolorrendering.
  651. /findcolorrendering {
  652. /ColorRendering /ProcSet findresource
  653. 1 .argindex dup type /nametype eq { .namestring } if (.) concatstrings
  654. 1 index /GetPageDeviceName get exec dup type /nametype eq { .namestring } if (.) concatstrings
  655. 2 index /GetHalftoneName get exec dup type /nametype eq { .namestring } if
  656. concatstrings concatstrings cvn % stack: intentname procset crdname
  657. dup /ColorRendering resourcestatus {
  658. pop pop exch pop exch pop true
  659. } {
  660. pop /GetSubstituteCRD get exec false
  661. } ifelse
  662. } .errorexec
  663. } odef
  664. 5 dict dup begin
  665. /GetPageDeviceName { % - GetPageDeviceName <name>
  666. currentpagedevice dup /PageDeviceName .knownget {
  667. exch pop dup null eq { pop /none } if
  668. } {
  669. pop /none
  670. } ifelse
  671. } bind def
  672. /GetHalftoneName { % - GetHalftoneName <name>
  673. currenthalftone /HalftoneName .knownget not { /none } if
  674. } bind def
  675. /GetSubstituteCRD { % <intentname> GetSubstituteCRD <crdname>
  676. pop /DefaultColorRendering
  677. } bind def
  678. end
  679. % The resource machinery hasn't been activated, so just save the ProcSet
  680. % and let .fixresources finish the installation process.
  681. /ColorRendering exch def
  682. % Define setcolorrendering.
  683. /.colorrenderingtypes 5 dict def
  684. /setcolorrendering { % <crd> setcolorrendering -
  685. dup /ColorRenderingType get
  686. dup type /integertype ne {
  687. /setcolorrendering .systemvar /typecheck signalerror
  688. } if
  689. //.colorrenderingtypes exch .knownget {
  690. exec
  691. } {
  692. /setcolorrendering .systemvar /rangecheck signalerror
  693. } ifelse
  694. } odef
  695. /.setcolorrendering1 where { pop } { (%END CRD) .skipeof } ifelse
  696. .colorrenderingtypes 1 {
  697. % Adobe ProcSet "Adobe_AGM_Core 2.0 0" places an /Intent key into CRD's
  698. dup /Intent .knownget {
  699. //.renderingintentdict exch .knownget { .setrenderingintent } if
  700. } if
  701. dup .buildcolorrendering1 .setcolorrendering1
  702. } .bind put
  703. % Note: the value 101 in the next line must be the same as the value of
  704. % GX_DEVICE_CRD1_TYPE in gscrdp.h.
  705. .colorrenderingtypes 101 {
  706. dup .builddevicecolorrendering1 .setdevicecolorrendering1
  707. } .bind put
  708. % sRGB output CRD, D65 white point
  709. mark
  710. /ColorRenderingType 1
  711. /RangePQR [ -0.5 2 -0.5 2 -0.5 2 ] readonly
  712. % Bradford Cone Space
  713. /MatrixPQR [ 0.8951 -0.7502 0.0389
  714. 0.2664 1.7135 -0.0685
  715. -0.1614 0.0367 1.0296] readonly
  716. /MatrixLMN [ 3.240449 -0.969265 0.055643
  717. -1.537136 1.876011 -0.204026
  718. -0.498531 0.041556 1.057229 ] readonly
  719. % Inverse sRGB gamma transform
  720. /EncodeABC [ { dup 0.00304 le
  721. { 12.92321 mul }
  722. { 1 2.4 div exp 1.055 mul 0.055 sub }
  723. ifelse
  724. } bind dup dup
  725. ] readonly
  726. /WhitePoint [ 0.9505 1 1.0890 ] readonly % D65
  727. /BlackPoint [ 0 0 0 ] readonly
  728. % VonKries-like transform in Bradford Cone Space
  729. /TransformPQR
  730. % The implementations have been moved to C for performance.
  731. [ { .TransformPQR_scale_WB0 } bind
  732. { .TransformPQR_scale_WB1 } bind
  733. { .TransformPQR_scale_WB2 } bind
  734. ] readonly
  735. .dicttomark setcolorrendering
  736. %END CRD
  737. % Initialize a CIEBased color space for sRGB.
  738. /CIEsRGB [ /CIEBasedABC
  739. mark
  740. /DecodeLMN [ {
  741. dup 0.03928 le { 12.92321 div } { 0.055 add 1.055 div 2.4 exp } ifelse
  742. } bind dup dup ] readonly
  743. /MatrixLMN [
  744. 0.412457 0.212673 0.019334
  745. 0.357576 0.715152 0.119192
  746. 0.180437 0.072175 0.950301
  747. ] readonly
  748. /WhitePoint [0.9505 1.0 1.0890] readonly
  749. .dicttomark readonly
  750. ] readonly def
  751. % ------ Painting ------ %
  752. % A straightforward definition of execform that doesn't actually
  753. % do any caching.
  754. /.execform1 {
  755. % This is a separate operator so that the stacks will be restored
  756. % properly if an error occurs.
  757. dup /Matrix get concat
  758. dup /BBox get aload pop
  759. exch 3 index sub exch 2 index sub rectclip
  760. dup /PaintProc get
  761. 1 index /Implementation known not {
  762. 1 index dup /Implementation null .forceput readonly pop
  763. } if
  764. exec
  765. } .bind odef % must bind .forceput
  766. /.formtypes 5 dict
  767. dup 1 /.execform1 load put
  768. def
  769. /execform { % <form> execform -
  770. gsave {
  771. dup /FormType get //.formtypes exch get exec
  772. } stopped grestore { stop } if
  773. } odef
  774. /.patterntypes 5 dict
  775. dup 1 /.buildpattern1 load put
  776. def
  777. /makepattern { % <proto_dict> <matrix> makepattern <pattern>
  778. dup type /dicttype eq {
  779. % "<dict> makepattern" reports /typecheck on Adobe
  780. /makepattern .systemvar /typecheck signalerror
  781. } if
  782. //.patterntypes 2 .argindex /PatternType get .knownget not {
  783. /makepattern .systemvar /rangecheck signalerror
  784. } if
  785. .currentglobal false .setglobal exch
  786. % Stack: proto matrix global buildproc
  787. 3 index dup length 1 add dict .copydict
  788. % Stack: proto matrix global buildproc newdict
  789. 3 index 3 -1 roll exec
  790. % Stack: proto matrix global newdict instance
  791. % Create an 'Implementation' entry for the pattern dict. The PRLM 3rd says
  792. % this about the contents of Implementation: "The type and value of this
  793. % entry are implementation-dependent." The CET (page 2 of 18-02f) expects
  794. % that this entry be an array and that the second element of the array be a
  795. % gstate. We put our pattern instance struct into the first element of the
  796. % array.
  797. 1 index /Implementation 3 -1 roll
  798. .getCPSImode { gstate } { //null } ifelse 2 array astore
  799. put % put Implementation into the pattern dict.
  800. % Stack: proto matrix global newdict
  801. readonly exch .setglobal exch pop exch pop
  802. } odef
  803. /setpattern { % [<comp1> ...] <pattern> setpattern -
  804. { currentcolorspace 0 get /Pattern ne {
  805. [ /Pattern currentcolorspace ] setcolorspace
  806. } if setcolor
  807. } stopped {
  808. /setpattern .systemvar $error /errorname get signalerror
  809. } if
  810. } odef
  811. % The following functions emulate the actions of findcmykcustomcolor and
  812. % setcustomcolor. These functions are described in Adobe's TN 5044. That
  813. % same document also says "The following operators are not defined in the
  814. % PostScript Language Reference Manual, but should be used as pseudo-operators
  815. % in your PostScript language output. Separation applications from Adobe
  816. % Systems and other vendors will redefine these convention operators to
  817. % separate your documents. Your application should conditionally define
  818. % procedures with these special names, as shown later in this document."
  819. %
  820. % We are providing these functions because we have found files created by
  821. % "QuarkXPress: pictwpstops filter 1.0" which produce bad shading dictionaries
  822. % if these operators are not defined.
  823. % Conditionally disable the TN 5044 psuedo-ops if NO_TN5044 specified
  824. /NO_TN5044 where { pop (%END TN 5044 psuedo-ops) .skipeof } if
  825. % TN 5044 does not define the contents of the array. We are simply putting
  826. % the values given into an array. This is consistent with what we see when
  827. % testing with Adobe Distiller 6.0.
  828. % <cyan> <magenta> <yellow> <black> <key> findcmykcustomcolor <array>
  829. /findcmykcustomcolor { 5 array astore } bind def
  830. % Build a tint transform function for use by setcustomcolor. This function
  831. % is for a Separation color space which has a DeviceCMYK base color space
  832. % (i.e. 1 input and 4 outputs). The input to buildcustomtinttransform is the
  833. % array created by findcmykcustomcolor. The resulting function is:
  834. % { dup cyan mul exch dup magenta mul exch dup yellow mul exch black mul }
  835. % Where cyan, magenta, yellow, and black are values from the array.
  836. /buildcustomtinttransform % <array> buildcustomtinttransform <function>
  837. { [ /dup load 2 index 0 get /mul load
  838. /exch load /dup load 6 index 1 get /mul load
  839. /exch load /dup load 10 index 2 get /mul load
  840. /exch load 13 index 3 get /mul load
  841. ] cvx bind
  842. exch pop % Remove the input array
  843. } bind def
  844. % Set a custom color based upon a tint and array which describes the custom
  845. % color. See findcmykcustomcolor. First we create and then set a Separation
  846. % colorspace. Then we set the specified color.
  847. % Note that older Adobe ProcSets apparently allow for 'null' as the tint
  848. % for some reason, so an alternate operational mode is tolerated:
  849. % null setcustomcolor -
  850. /setcustomcolor % <array> <tint> setcustomcolor -
  851. { dup //null ne {
  852. % Start building Separation colorspace
  853. [ /Separation 3 index 4 get % Get separation name from array's key
  854. /DeviceCMYK
  855. 5 index //buildcustomtinttransform exec] % build the tint transform function
  856. setcolorspace % Set the Separation color space as current
  857. setcolor % Set the tint as the current color
  858. pop % Remove the input array
  859. }
  860. { pop } % 'null' as the tint is ignored
  861. ifelse
  862. } bind def
  863. % This proc is supposed to implement a version of overprinting. TN 5044 says
  864. % that this proc is not used by any shipping host-based application. We have
  865. % only found it being used in a proc set in files by Canvas from Deneba Systems.
  866. % Even their proc set does not actually do any overprinting. However their
  867. % files crash if this is not defined. Thus we have a copy of this proc but
  868. % we are simply checking for inputs being -1 and if so then we set the value
  869. % to 0.
  870. /setcmykoverprint {
  871. 4 { dup -1 eq { pop 0 } if 4 1 roll } repeat setcmykcolor
  872. } bind def
  873. /separation_all [/Separation /All /DeviceCMYK { dup dup dup } bind ] readonly def
  874. % Collect the arguments into the image dictionary
  875. % <width> <height> <bits/sample> <matrix> <proc> args2dict <dict>
  876. /args2dict {
  877. 10 dict begin
  878. {1 0} 1
  879. { /ImageType /Decode /DataSource /ImageMatrix /BitsPerComponent /Height /Width
  880. } { exch def } forall
  881. currentdict end
  882. } bind def
  883. % Prints (1-gray) on all separations.
  884. % <gray> setseparationgray -
  885. /setseparationgray {
  886. //separation_all setcolorspace
  887. 1 exch sub setcolor
  888. } bind def
  889. % Renders an image whose sample values specify the amount of the custom color.
  890. % <width> <height> <bits/sample> <matrix> <proc> <array> customcolorimage -
  891. /customcolorimage {
  892. gsave
  893. [ /Separation 2 index 4 get /DeviceCMYK 5 -1 roll //buildcustomtinttransform exec] setcolorspace
  894. //args2dict exec image
  895. grestore
  896. } bind def
  897. % Renders an image on all process and custom color plates.
  898. % <width> <height> <bits/sample> <matrix> <proc>
  899. /separationimage {
  900. gsave
  901. //separation_all setcolorspace
  902. //args2dict exec image
  903. grestore
  904. } bind def
  905. { /buildcustomtinttransform /separation_all /args2dict }
  906. { currentdict exch undef } forall
  907. %END TN 5044 psuedo-ops
  908. end % level2dict