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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  1. % Copyright (C) 1989-2009 Artifex Software, Inc. 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_init.ps 10601 2010-01-10 15:51:48Z alexcher $
  16. % Initialization file for the interpreter.
  17. % When this is run, systemdict is still writable.
  18. % Comment lines of the form
  19. % %% Replace <n> <file(s)>
  20. % indicate places where the next <n> lines should be replaced by
  21. % the contents of <file(s)>, when creating a single merged init file.
  22. % The interpreter can call out to PostScript code. All procedures
  23. % called in this way, and no other procedures defined in these
  24. % initialization files, have names that begin with %, e.g.,
  25. % (%Type1BuildChar) cvn.
  26. % Interpreter library version number
  27. % NOTE: the interpreter code requires that the first non-comment token
  28. % in this file be an integer, and that it match the compiled-in version!
  29. 871
  30. % Check the interpreter revision.
  31. dup revision ne
  32. { (gs: Interpreter revision \() print revision 10 string cvs print
  33. (\) does not match gs_init.ps revision \() print 10 string cvs print
  34. (\).\n) print flush //null 1 .quit
  35. }
  36. if pop
  37. % Acquire userdict, and set its length if necessary.
  38. /userdict where
  39. { pop userdict maxlength 0 eq }
  40. { true }
  41. ifelse
  42. systemdict exch
  43. { % userdict wasn't already set up by iinit.c.
  44. dup /userdict
  45. currentdict dup 200 .setmaxlength % userdict
  46. .forceput % userdict is local, systemdict is global
  47. }
  48. if begin
  49. % Define dummy local/global operators if needed.
  50. systemdict /.setglobal known
  51. { true .setglobal
  52. }
  53. { /.setglobal { pop } bind def
  54. /.currentglobal { false } bind def
  55. /.gcheck { pop false } bind def
  56. }
  57. ifelse
  58. % Define .languagelevel if needed.
  59. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  60. % Optionally choose a default paper size other than U.S. letter.
  61. % The default page size for many devices is set at compile time to
  62. % letter, but this can be changed to A4 although this is rarely done.
  63. % Some devices such as bbox have a different default page size,
  64. % and should not be set to A4 or letter.
  65. % When ghostscript is used in countries that use the international
  66. % standard page size A4 rather than US letter, the page size of
  67. % devices that default to letter or A4 can be changed by setting
  68. % DEFAULTPAPERSIZE.
  69. % /DEFAULTPAPERSIZE (a4) def
  70. % Turn on array packing for the rest of initialization.
  71. true setpacking
  72. % Define the old MS-DOS EOF character as a no-op.
  73. % This is a hack to get around the absurd habit of MS-DOS editors
  74. % of adding an EOF character at the end of the file.
  75. <1a> cvn { } def
  76. % Acquire the debugging flags.
  77. currentdict /DEBUG known /DEBUG exch def
  78. % if DEBUG is set, set ALL of the subset debugging flags
  79. mark % '[' isn't defined yet
  80. /CCFONTDEBUG % Compiled Fonts
  81. /CFFDEBUG % CFF Fonts
  82. /CMAPDEBUG % CMAP
  83. /DOCIEDEBUG % CIE color
  84. /EPSDEBUG % EPS handling
  85. /FAPIDEBUG % Font API
  86. /INITDEBUG % Initialization
  87. /PDFDEBUG % PDF Interpreter
  88. /PDFOPTDEBUG % PDF Optimizer (Linearizer)
  89. /PDFWRDEBUG % PDF Writer
  90. /SETPDDEBUG % setpagedevice
  91. /TTFDEBUG % TTF Fonts
  92. /VGIFDEBUG % ViewGIF
  93. /VJPGDEBUG % ViewJPEG
  94. /RESMPDEBUG % Resource map
  95. counttomark array astore exch pop % ']' isn't defined yet
  96. { dup currentdict exch known DEBUG or def } forall
  97. currentdict /PDFSTEP known /PDFSTEP exch def
  98. % if PDFSTEP is on, turn on PDFDEBUG
  99. PDFSTEP { /PDFDEBUG true def } if
  100. /VMDEBUG
  101. INITDEBUG {{print mark
  102. systemdict /level2dict known
  103. { .currentglobal dup false .setglobal vmstatus
  104. true .setglobal vmstatus 3 -1 roll pop
  105. 6 -2 roll pop .setglobal
  106. }
  107. { vmstatus 3 -1 roll pop
  108. }
  109. ifelse usertime 16#fffff and counttomark
  110. { ( ) print ( ) cvs print }
  111. repeat pop
  112. ( ) print systemdict length ( ) cvs print
  113. ( ) print countdictstack ( ) cvs print
  114. ( <) print count ( ) cvs print (>\n) print flush
  115. }}
  116. {{pop
  117. }}
  118. ifelse
  119. def
  120. currentdict /BATCH known /BATCH exch def
  121. currentdict /DELAYBIND known /DELAYBIND exch def
  122. currentdict /DISKFONTS known /DISKFONTS exch def
  123. currentdict /DOINTERPOLATE .knownget { /INTERPOLATE exch def } if
  124. currentdict /ESTACKPRINT known /ESTACKPRINT exch def
  125. currentdict /FAKEFONTS known /FAKEFONTS exch def
  126. currentdict /FIXEDMEDIA known /FIXEDMEDIA exch def
  127. currentdict /FIXEDRESOLUTION known /FIXEDRESOLUTION exch def
  128. currentdict /LOCALFONTS known /LOCALFONTS exch def
  129. currentdict /JOBSERVER known /JOBSERVER exch def
  130. currentdict /NOBIND known /NOBIND exch def
  131. /.bind /bind load def
  132. NOBIND { /bind { } def } if
  133. currentdict /NOCACHE known /NOCACHE exch def
  134. currentdict /NOCCFONTS known /NOCCFONTS exch def
  135. currentdict /NOCIE known /NOCIE exch def
  136. currentdict /NOPSICC known /NOPSICC exch def
  137. currentdict /NODISPLAY known not /DISPLAYING exch def
  138. currentdict /NOFONTMAP known /NOFONTMAP exch def
  139. currentdict /NOFONTPATH known /NOFONTPATH exch def
  140. currentdict /NOGC known /NOGC exch def
  141. currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
  142. currentdict /NOMEDIAATTRS known /NOMEDIAATTRS exch def
  143. currentdict /NOOUTERSAVE known /NOOUTERSAVE exch def
  144. currentdict /NOPAGEPROMPT known /NOPAGEPROMPT exch def
  145. currentdict /NOPAUSE known /NOPAUSE exch def
  146. currentdict /NOPLATFONTS known /NOPLATFONTS exch def
  147. currentdict /NOPROMPT known /NOPROMPT exch def
  148. currentdict /NOTRANSPARENCY known /NOTRANSPARENCY exch def
  149. currentdict /DOPS known /DOPS exch def
  150. currentdict /NOSUBSTDEVICECOLORS known /NOSUBSTDEVICECOLORS exch def
  151. % The default value of ORIENT1 is true, not false.
  152. currentdict /ORIENT1 known not { /ORIENT1 true def } if
  153. currentdict /OSTACKPRINT known /OSTACKPRINT exch def
  154. currentdict /OUTPUTFILE known % obsolete
  155. { /OutputFile /OUTPUTFILE load def
  156. currentdict /OUTPUTFILE .undef
  157. } if
  158. currentdict /QUIET known /QUIET exch def
  159. % DELAYSAFER is effectively the same as newer NOSAFER
  160. currentdict /DELAYSAFER known { /DELAYSAFER true def /NOSAFER true def } if
  161. /SAFER currentdict /NOSAFER known {
  162. false
  163. } {
  164. currentdict /SAFER known
  165. currentdict /PARANOIDSAFER known or % PARANOIDSAFER is equivalent
  166. }
  167. ifelse def
  168. currentdict /SHORTERRORS known /SHORTERRORS exch def
  169. currentdict /STRICT known /STRICT exch def
  170. currentdict /TTYPAUSE known /TTYPAUSE exch def
  171. currentdict /WRITESYSTEMDICT known /WRITESYSTEMDICT exch def
  172. currentdict /RENDERTTNOTDEF known /RENDERTTNOTDEF exch def
  173. % Acquire environment variables.
  174. currentdict /DEVICE known not
  175. { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  176. (START) VMDEBUG
  177. % Open the standard files, so they will be open at the outermost save level.
  178. (%stdin) (r) file pop
  179. (%stdout) (w) file pop
  180. (%stderr) (w) file pop
  181. /.currentuserparams where {
  182. pop mark
  183. % The Adobe implementations appear to have very large maximum
  184. % stack sizes. This turns out to actually make a difference,
  185. % since some badly-behaved files include extremely long procedures,
  186. % or construct huge arrays on the operand stack.
  187. % We reset the stack sizes now so that we don't have to worry
  188. % about overflowing the (rather small) built-in stack sizes
  189. % during initialization.
  190. /MaxDictStack 500
  191. /MaxExecStack 5000
  192. /MaxOpStack 300000
  193. .dicttomark .setuserparams
  194. } if
  195. % Define a procedure for skipping over an unneeded section of code.
  196. % This avoids allocating space for the skipped procedures.
  197. % We can't use readline, because that imposes a line length limit.
  198. /.skipeof % <string> .skipeof -
  199. { currentfile exch 1 exch .subfiledecode flushfile
  200. } .bind def
  201. % Define procedures to assist users who don't read the documentation.
  202. userdict begin
  203. /help
  204. { (Enter PostScript commands. '(filename) run' runs a file, 'quit' exits.\n)
  205. print flush
  206. } .bind def
  207. end
  208. % Define =string, which is used by some PostScript programs even though
  209. % it isn't documented anywhere.
  210. % Put it in userdict so that each context can have its own copy.
  211. userdict /=string 256 string put
  212. % Print the greeting.
  213. /printgreeting
  214. { mark
  215. product (Ghostscript) search
  216. { pop pop pop
  217. (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
  218. }
  219. { pop
  220. }
  221. ifelse
  222. (\n) copyright
  223. (\)\n) revisiondate 10 mod revisiondate 10 idiv 10 mod (-)
  224. revisiondate 100 idiv 10 mod revisiondate 1000 idiv 10 mod (-)
  225. revisiondate 10000 idiv ( \()
  226. revision 10 mod
  227. revision 100 mod 10 idiv (.)
  228. revision 100 idiv ( )
  229. product
  230. counttomark
  231. { (%stdout) (w) file exch 0 .writecvp
  232. } repeat pop
  233. } .bind def
  234. QUIET not { printgreeting flush } if
  235. % Define a special version of def for making operator procedures.
  236. /obind { % <name> <proc> obind <name> <oper>
  237. 1 index exch .makeoperator
  238. } .bind def
  239. /odef { % <name> <proc> odef -
  240. 1 index exch .makeoperator def
  241. } .bind def
  242. % Define a special version of def for storing local objects into global
  243. % dictionaries. Like .forceput, this exists only during initialization.
  244. /.forcedef { % <key> <value> .forcedef -
  245. 1 .argindex pop % check # of args
  246. currentdict 3 1 roll .forceput
  247. } .bind odef
  248. % Define procedures for accessing variables in systemdict and userdict
  249. % regardless of the contents of the dictionary stack.
  250. /.systemvar { % <name> .systemvar <value>
  251. //systemdict exch get
  252. } .bind odef
  253. /.userdict { % - .userdict <dict>
  254. /userdict .systemvar
  255. } .bind odef
  256. /.uservar { % <name> .uservar <value>
  257. .userdict exch get
  258. } .bind odef
  259. % If we're delaying binding, remember everything that needs to be bound later.
  260. DELAYBIND NOBIND not and
  261. { .currentglobal false .setglobal
  262. systemdict /.delaybind 2000 array .forceput
  263. .setglobal
  264. userdict /.delaycount 0 put
  265. % When we've done the delayed bind, we want to stop saving.
  266. % Detect this by the disappearance of .delaybind.
  267. /bind
  268. { /.delaybind .systemvar dup length 0 ne
  269. { .delaycount 2 index put
  270. .userdict /.delaycount .delaycount 1 add put
  271. }
  272. { pop /.bind cvx exec
  273. }
  274. ifelse
  275. } .bind def
  276. } if
  277. %**************** BACKWARD COMPATIBILITY ****************
  278. /hwsizedict mark /HWSize //null .dicttomark readonly def
  279. /copyscanlines { % <device> <y> <string> copyscanlines <substr>
  280. 0 3 1 roll 3 index //hwsizedict .getdeviceparams
  281. exch pop exch pop aload pop 3 2 roll
  282. 0 exch //null exch .getbitsrect exch pop
  283. } bind odef
  284. currentdict /hwsizedict .undef
  285. /getdeviceprops
  286. { //null .getdeviceparams
  287. } bind odef
  288. /.putdeviceprops
  289. { //null true counttomark 1 add 3 roll .putdeviceparams
  290. dup type /booleantype ne
  291. { dup mark eq { /unknown /rangecheck } if
  292. counttomark 4 add 1 roll cleartomark pop pop pop
  293. /.putdeviceprops .systemvar exch signalerror
  294. }
  295. if
  296. } bind odef
  297. /.currentfilladjust { .currentfilladjust2 pop } bind odef
  298. /.setfilladjust { dup .setfilladjust2 } bind odef
  299. /.writecvs { 0 .writecvp } bind odef
  300. %**************** DEPRECATED PROCEDURES ****************
  301. %**************** DO NOT USE THESE IN NEW CODE ****************
  302. /max { .max } bind def % use .max instead
  303. /min { .min } bind def % use .min instead
  304. /unread /.unread load def % use .peekstring instead
  305. %**************** END OF BACKWARD COMPATIBILITY SECTION ****************
  306. % Utility for removing all entries from a dictionary
  307. /.PurgeDict % <dict> .PurgeDict -
  308. { { true
  309. 1 index { pop exch pop false exit
  310. } forall
  311. { exit
  312. } if
  313. 1 index exch undef
  314. } loop
  315. pop
  316. } bind def
  317. % Define predefined procedures substituting for operators,
  318. % in alphabetical order.
  319. userdict /#copies 1 put
  320. % Adobe implementations don't accept /[ or /], so we don't either.
  321. ([) cvn
  322. /mark load def
  323. (]) cvn
  324. {counttomark array astore exch pop} odef
  325. % .beginpage is redefined if setpagedevice is present.
  326. /.beginpage { } odef
  327. % In LanguageLevel 3, copypage erases the page.
  328. /copypage {
  329. .languagelevel 3 ge
  330. dup { 0 } { 1 } ifelse .endpage .doneshowpage {
  331. .currentnumcopies 1 index .outputpage
  332. (>>copypage, press <return> to continue<<\n) .confirm
  333. dup { erasepage } if
  334. } if pop
  335. systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
  336. .beginpage
  337. } odef
  338. /currentmatrix {
  339. dup type /arraytype ne
  340. { /currentmatrix load /typecheck signalerror } if
  341. dup length 6 ne
  342. { /currentmatrix load /rangecheck signalerror } if
  343. .currentmatrix 6 .argindex astore pop
  344. } odef
  345. % .currentnumcopies is redefined in Level 2.
  346. /.currentnumcopies { #copies } odef
  347. /setcolorscreen where { pop % not in all Level 1 configurations
  348. /currentcolorscreen
  349. { .currenthalftone
  350. { { 60.0 exch 0.0 exch 3 copy 6 copy } % halftone - not possible
  351. { 3 copy 6 copy } % screen
  352. { } % colorscreen
  353. }
  354. exch get exec
  355. } odef
  356. } if
  357. /currentscreen
  358. { .currenthalftone
  359. { { 60.0 exch 0.0 exch } % halftone - not possible
  360. { } % screen
  361. { 12 3 roll 9 { pop } repeat } % colorscreen
  362. }
  363. exch get exec
  364. } odef
  365. /.echo /echo load def
  366. userdict /.echo.mode true put
  367. /echo {dup /.echo.mode exch store .echo} odef
  368. /.eexec_param_dict mark
  369. /eexec true
  370. /seed 55665
  371. .dicttomark readonly def
  372. /eexec {
  373. % Rebind .currentresourcefile if it is the source for the eexec.
  374. dup //.eexec_param_dict //filterdict /eexecDecode get exec
  375. cvx exch .currentresourcefile eq
  376. //systemdict begin { {exec} .execasresource } { exec } ifelse
  377. % Only pop systemdict if it is still the top element,
  378. % because this is apparently what Adobe interpreters do.
  379. currentdict //systemdict eq { end } if
  380. } odef
  381. % .endpage is redefined if setpagedevice is present.
  382. /.endpage { 2 ne } odef
  383. % erasepage mustn't use gsave/grestore, because we call it before
  384. % the graphics state stack has been fully initialized.
  385. /erasepage
  386. { /currentcolor where
  387. { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  388. { /currentcmykcolor where
  389. { pop currentcmykcolor { setcmykcolor } }
  390. { currentrgbcolor { setrgbcolor } }
  391. ifelse
  392. }
  393. ifelse
  394. currentoverprint false setoverprint 1 setgray .fillpage setoverprint
  395. exec
  396. } odef
  397. % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
  398. /executive
  399. { { prompt
  400. { (%statementedit) (r) .systemvmfile } stopped
  401. { pop pop $error /errorname get /undefinedfilename eq
  402. { .clearerror exit } if % EOF
  403. /handleerror .systemvar exec //null % ioerror??
  404. }
  405. if
  406. cvx { .runexec } .execute pop
  407. } loop
  408. } bind def
  409. /filter
  410. { //filterdict 1 .argindex .knownget
  411. { exch pop exec }
  412. { /filter .systemvar /undefined signalerror }
  413. ifelse
  414. } odef
  415. % handleerror procedure as mentioned in the "Operators" section of the PLRM Section 8.2
  416. % This invokes the handleerror procedure from errordict (unless we are running under a
  417. % JOBSERVER where we want to always use a defined error handler (many error handlers in
  418. % 'wild' PostScript files are broken and don't indicate the error in any useful fashion).
  419. %
  420. % We run the handleerror procedure using .internalstopped so that broken error handlers
  421. % won't cause nested errors (Unexpected Error conditions).
  422. /handleerror
  423. JOBSERVER {
  424. { /.GShandleerror .systemvar .internalstopped pop } bind % always use .GShandleerror.
  425. } {
  426. { /errordict .systemvar /handleerror get .internalstopped pop } bind % PLRM standard errorhandling
  427. } ifelse def
  428. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  429. /identmatrix {
  430. dup type /arraytype ne { /identmatrix load /typecheck signalerror } if
  431. dup length 6 ne { /identmatrix load /rangecheck signalerror } if
  432. dup 0 //identmatrix putinterval
  433. } odef
  434. /languagelevel 1 def % gs_lev2.ps may change this
  435. /makeimagedevice { false makewordimagedevice } odef
  436. /matrix { 6 array identmatrix } odef
  437. % .promptmsg is redefined if the interpreter includes readline support.
  438. /.promptmsg {
  439. (GS) print
  440. count 0 ne { (<) print count =only } if
  441. (>) print flush
  442. } bind def
  443. /prompt { flush flushpage NOPROMPT not { .promptmsg } if } bind def
  444. /pstack { 0 1 count 3 sub { index == } for } bind def
  445. /putdeviceprops
  446. { .putdeviceprops { erasepage } if } odef
  447. /quit { /quit load 0 .quit } odef
  448. /run { dup type /filetype ne { (r) .systemvmfile } if
  449. % We must close the file when execution terminates,
  450. % regardless of the state of the stack,
  451. % and then propagate an error, if any.
  452. cvx null {.runexec} .errorexec
  453. } odef
  454. % Execute a file.
  455. % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
  456. % we detect that here, since we need to handle this even if we start out
  457. % without job control in effect.
  458. %
  459. % What we push on the e-stack is the following to be executed in this order:
  460. % <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
  461. /.runexec1 { % <file|fileproc> .runexec1 -
  462. dup type /filetype ne { cvx exec } if
  463. cvx //null 2 .stopped
  464. % If we got back here from a startjob, just keep going.
  465. % startjob replaces the null on the o-stack with a procedure
  466. % to be executed when we get back here.
  467. dup //null ne { exec true } { pop false } ifelse
  468. } bind def
  469. /.runexec2 { % <continue> <file|fileproc> .runexec2 -
  470. exch {
  471. .runexec
  472. } {
  473. dup type /filetype ne { cvx exec } if
  474. closefile
  475. } ifelse
  476. } bind def
  477. /.runexec { % <file|fileproc> .runexec -
  478. cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
  479. } bind def
  480. % The following is only for compatibility with Adobe interpreters.
  481. /setdash {
  482. 0 .argindex type dup /integertype eq exch /realtype eq or not {
  483. /setdash .systemvar /typecheck signalerror
  484. } if
  485. 1 .argindex length 11 gt { /setdash .systemvar /limitcheck signalerror } if
  486. //setdash
  487. } odef
  488. /setdevice
  489. {
  490. .setdevice
  491. {
  492. mark
  493. { % Reset the halftone since the device may differ
  494. currenthalftone
  495. dup type /dicttype eq
  496. { sethalftone }
  497. { pop }
  498. ifelse
  499. }
  500. stopped
  501. cleartomark
  502. erasepage
  503. }
  504. if
  505. }
  506. odef
  507. /setlinecap {
  508. dup 2 gt { /setlinecap .systemvar /rangecheck signalerror } if
  509. .setlinecap
  510. } odef
  511. /setlinejoin {
  512. dup 2 gt { /setlinejoin .systemvar /rangecheck signalerror } if
  513. .setlinejoin
  514. } odef
  515. /setmatrix {
  516. dup type /arraytype ne {
  517. dup type /packedarraytype ne {
  518. /setmatrix load /typecheck signalerror
  519. } if
  520. } if
  521. dup length 6 ne { /setmatrix load /rangecheck signalerror } if
  522. dup aload pop .setmatrix pop
  523. } odef
  524. /showpage {
  525. 0 .endpage .doneshowpage {
  526. .currentnumcopies true .outputpage
  527. (>>showpage, press <return> to continue<<\n) .confirm
  528. initgraphics
  529. currentoverprint false setoverprint 1 setcolor
  530. .fillpage
  531. setoverprint 0 setcolor
  532. }
  533. { initgraphics } ifelse
  534. systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
  535. .beginpage
  536. } odef
  537. % Code output by Adobe Illustrator relies on the fact that
  538. % `stack' is a procedure, not an operator!!!
  539. /stack { 0 1 count 3 sub { index = } for } bind def
  540. /start { BATCH { //null 0 .quit } { executive } ifelse } def
  541. % Internal uses of stopped that aren't going to do a stop if an error occurs
  542. % should use .internalstopped to avoid setting newerror et al.
  543. /.internalstopped { //null 1 .stopped //null ne } bind def
  544. /store { % Don't alter operands before completing.
  545. 1 .argindex where { 2 index 2 index put pop pop } { def } ifelse
  546. } odef
  547. /.typenames mark .typenames counttomark packedarray exch pop def
  548. /type {
  549. //.typenames .type
  550. } odef
  551. currentdict /.typenames .undef
  552. % When running in Level 1 mode, this interpreter is supposed to be
  553. % compatible with PostScript "version" 54.0 (I think).
  554. /version (54.0) readonly def
  555. /.wheredict 10 dict def
  556. /.where /where load def
  557. /where {
  558. //.wheredict 1 .argindex .knownget { exec } { .where } ifelse
  559. } odef
  560. % internaldict is defined in systemdict, but the dictionary is allocated
  561. % in local VM. However, the procedure must be global, since it is an
  562. % "operator" and must be bind-able into global procedures.
  563. % We make a procedure for creating it, since we must create a new one
  564. % for each context with private local VM.
  565. /.makeinternaldict {
  566. .currentglobal true .setglobal
  567. [ /dup .systemvar 1183615869 /eq .systemvar
  568. [ /pop .systemvar //null ] cvx
  569. false .setglobal
  570. dup 1 10 dict .forceput % proc is global, dict is local
  571. true .setglobal
  572. [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
  573. /ifelse .systemvar
  574. ] cvx executeonly
  575. exch .setglobal
  576. } odef
  577. systemdict /internaldict dup .makeinternaldict .makeoperator
  578. .forceput % proc is local, systemdict is global
  579. % Define some additional built-in procedures (beyond the ones defined by
  580. % the PostScript Language Reference Manual).
  581. % Warning: these are not guaranteed to stay the same from one release
  582. % to the next!
  583. /concatstrings % (str1) (str2) concatstrings (str1str2)
  584. { exch dup length 2 index length add string % str2 str1 new
  585. dup dup 4 2 roll copy % str2 new new new1
  586. length 4 -1 roll putinterval
  587. } bind def
  588. /copyarray
  589. { dup length array copy } bind def
  590. % Copy a dictionary per the Level 2 spec even in Level 1.
  591. /.copydict % <fromdict> <todict> .copydict <todict>
  592. { dup 3 -1 roll { put dup } forall pop } bind def
  593. /copystring
  594. { dup length string copy } bind def
  595. /findlibfile {
  596. .systemvmlibfile { dup .filename pop exch true } { false } ifelse
  597. } odef
  598. /.growdictlength % get size for growing a dictionary
  599. { length 3 mul 2 idiv 1 add
  600. } bind def
  601. /.growdict % grow a dictionary
  602. { dup .growdictlength .setmaxlength
  603. } bind def
  604. /.growput % put, grow the dictionary if needed
  605. { 2 index length 3 index maxlength eq
  606. { 3 copy pop known not { 2 index .growdict } if
  607. } if
  608. put
  609. } bind def
  610. % .localvmarray may be an operator: see zsysvm.c.
  611. /.localvmarray where {
  612. pop
  613. } {
  614. /.localvmarray {
  615. .currentglobal false .setglobal
  616. exch array exch .setglobal
  617. } bind def
  618. } ifelse
  619. /.localvmdict where {
  620. pop
  621. } {
  622. /.localvmdict {
  623. .currentglobal false .setglobal
  624. exch dict exch .setglobal
  625. } bind def
  626. } ifelse
  627. /.packtomark
  628. { counttomark packedarray exch pop } bind def
  629. /ppstack
  630. { 0 1 count 3 sub { index === } for } bind def
  631. /runlibfile
  632. { % We don't want to bind 'run' into this procedure,
  633. % since run may get redefined.
  634. findlibfile
  635. { exch pop /run .systemvar exec }
  636. { /undefinedfilename signalerror }
  637. ifelse
  638. } bind def
  639. /selectdevice
  640. { finddevice setdevice .setdefaultscreen } bind def
  641. /signalerror % <object> <errorname> signalerror -
  642. { /errordict .systemvar exch get exec } bind def
  643. /signaloperror { % <object> <errorname> signaloperror -
  644. % Same as signalerror, except that if we are inside a pseudo-operator
  645. % or .errorexec, we use its error object, just as errors generated by
  646. % real operators do.
  647. /errordict .systemvar exch get
  648. .finderrorobject { 3 -1 roll pop exch } if
  649. exec
  650. } bind def
  651. % Define the =[only] procedures. Also define =print,
  652. % which is used by some PostScript programs even though
  653. % it isn't documented anywhere.
  654. /write=only {
  655. .writecvs
  656. } bind def
  657. /write= {
  658. 1 index exch write=only (\n) writestring
  659. } bind def
  660. /=only { (%stdout) (w) file exch write=only } bind def
  661. /= { =only (\n) print } bind def
  662. /=print /=only load def
  663. % Temporarily define == as = for the sake of runlibfile0.
  664. /== /= load def
  665. % The following procedures are documented.
  666. /copydevice { % <device> copydevice <newdevice>
  667. false .copydevice2
  668. } odef
  669. /finddevice { % <devicename> finddevice <device>
  670. /devicedict .systemvar exch get
  671. dup 1 get //null eq {
  672. % This is the first request for this type of device.
  673. % Create a default instance now.
  674. % Stack: [proto null]
  675. .currentglobal true .setglobal exch
  676. dup dup 0 get copydevice 1 exch put
  677. exch .setglobal
  678. } if 1 get
  679. } bind def
  680. /findprotodevice { % <devicename> findprotodevice <protodevice>
  681. /devicedict .systemvar exch get 0 get
  682. } bind def
  683. % Run a resource file. This allows us to distinguish resource objects
  684. % from objects coming from input files.
  685. userdict /.currentresourcefile //null put
  686. /.execasresource { % <file> <proc|runfile> .execasresource -
  687. /stopped .systemvar
  688. /.currentresourcefile .uservar
  689. % Stack: file proc -stopped- currfile
  690. .userdict /.currentresourcefile 5 index cvlit put
  691. 2 .execn % stopped <file>
  692. .userdict /.currentresourcefile 3 -1 roll put
  693. { stop } if
  694. } bind def
  695. /.runresource { % <file> .runresource -
  696. { /run .systemvar exec } .execasresource
  697. } bind def
  698. % Define procedures for getting and setting the current device resolution.
  699. /gsgetdeviceprop % <device> <propname> gsgetdeviceprop <value>
  700. { 2 copy mark exch //null .dicttomark .getdeviceparams
  701. dup mark eq % if true, not found
  702. { pop dup /undefined signalerror }
  703. { 5 1 roll pop pop pop pop }
  704. ifelse
  705. } bind def
  706. /gscurrentresolution % - gscurrentresolution <[xres yres]>
  707. { currentdevice /HWResolution gsgetdeviceprop
  708. } bind def
  709. /gssetresolution % <[xres yres]> gssetresolution -
  710. { 2 array astore mark exch /HWResolution exch
  711. currentdevice copydevice putdeviceprops setdevice
  712. } bind def
  713. % Define auxiliary procedures needed for the above.
  714. /shellarguments % -> shell_arguments true (or) false
  715. { /ARGUMENTS where
  716. { /ARGUMENTS get dup type /arraytype eq
  717. { aload pop /ARGUMENTS //null store true }
  718. { pop false }
  719. ifelse }
  720. { false } ifelse
  721. } bind def
  722. /.confirm {
  723. DISPLAYING NOPAUSE not TTYPAUSE or and {
  724. % Print a message (unless NOPAGEPROMPT or NOPROMPT is true)
  725. % and wait for the user to type something.
  726. % If the user just types a newline, flush it.
  727. NOPAGEPROMPT NOPROMPT or { pop } { print flush } ifelse
  728. .confirmread
  729. } {
  730. pop
  731. } ifelse
  732. } bind def
  733. /.confirmread {
  734. TTYPAUSE {
  735. (/dev/tty) (r) file dup read pop pop closefile
  736. } {
  737. .echo.mode false echo
  738. (%stdin) (r) file dup read {
  739. dup (\n) 0 get eq { pop pop } { unread } ifelse
  740. } {
  741. pop
  742. } ifelse echo
  743. } ifelse
  744. } bind def
  745. % Define the procedure used by .runfile, .runstdin and .runstring
  746. % for executing user input.
  747. % This is called with a procedure or executable file on the operand stack.
  748. /.execute { % <obj> .execute <stopped>
  749. stopped $error /newerror get and
  750. { /handleerror .systemvar exec flush true } { false } ifelse
  751. } bind def
  752. /execute { % <obj> execute -
  753. .execute pop
  754. } odef
  755. % Define an execute analogue of runlibfile0.
  756. /execute0 { % <obj> execute0 -
  757. .execute { /execute0 cvx 1 .quit } if
  758. } bind def
  759. % Define the procedure that the C code uses for running files
  760. % named on the command line.
  761. /.runfile {
  762. { runlibfile } execute0
  763. } def
  764. % Define the procedure that the C code uses for running piped input.
  765. % We don't use the obvious { (%stdin) run }, because we want the file to be
  766. % reopened if a startjob does a restore.
  767. /.runstdin {
  768. { { (%stdin) (r) file cvx } .runexec } execute0
  769. } bind def
  770. % Define the procedure that the C code uses for running commands
  771. % given on the command line with -c. We turn the string into a file so that
  772. % .runexec can do the right thing with a startjob.
  773. /.runstring {
  774. 0 0 .systemvmstring .systemvmSFD cvx { .runexec } execute0
  775. } bind def
  776. % Define the procedure that the C code uses to set up for executing
  777. % a string that may be received in pieces.
  778. /.runstringbegin {
  779. 1 .systemvmarray dup 0 /.needinput load put cvx % { .needinput } in systemvm
  780. 0 0 .systemvmstring .systemvmSFD cvx .runexec
  781. } bind def
  782. % Define a special version of runlibfile that aborts on errors.
  783. /runlibfile0
  784. { cvlit dup dup /.currentfilename exch def
  785. { findlibfile not { stop } if }
  786. stopped
  787. { (Can't find \(or open\) initialization file ) print
  788. .currentfilename == flush /runlibfile0 cvx 1 .quit
  789. } if
  790. exch pop cvx
  791. { stopped } 0 get 3 -1 roll 2 array astore cvx exec
  792. /.currentfilename exch store
  793. { (While reading ) print .currentfilename print (:\n) print flush
  794. /handleerror .systemvar exec /runlibfile0 1 .quit
  795. } if
  796. } bind def
  797. % Temporarily substitute it for the real runlibfile.
  798. /.runlibfile /runlibfile load def
  799. /runlibfile /runlibfile0 load def
  800. % Create the error handling machinery.
  801. % Define the standard error handlers.
  802. % The interpreter has created the ErrorNames array.
  803. /.unstoppederrorhandler % <command> <errorname> .unstoppederrorhandler -
  804. { % This is the handler that gets used for recursive errors,
  805. % or errors outside the scope of a 'stopped'.
  806. 2 copy SHORTERRORS
  807. { (%%[ Error: ) print =only flush
  808. (; OffendingCommand: ) print =only ( ]%%) =
  809. }
  810. { (Unrecoverable error: ) print =only flush
  811. ( in ) print = flush
  812. count 2 gt
  813. { (Operand stack:\n ) print
  814. count 1 sub -1 2 { ( ) print index =only flush } for
  815. () = flush
  816. } if
  817. }
  818. ifelse
  819. -1 0 1 //ErrorNames length 1 sub
  820. { dup //ErrorNames exch get 3 index eq
  821. { not exch pop exit } { pop } ifelse
  822. }
  823. for exch pop .quit
  824. } bind def
  825. /.errorhandler % <command> <errorname> .errorhandler -
  826. { % Detect an internal 'stopped'.
  827. 1 .instopped { //null eq { pop pop stop } if } if
  828. (I) false .setdebug
  829. $error /.inerror get 1 .instopped { pop } { pop true } ifelse
  830. { .unstoppederrorhandler
  831. } if % detect error recursion
  832. $error /globalmode .currentglobal false .setglobal put
  833. $error /.inerror true put
  834. $error /newerror true put
  835. $error exch /errorname exch put
  836. $error exch /command exch put
  837. $error /errorinfo known not { $error /errorinfo //null put } if
  838. $error /recordstacks get $error /errorname get /VMerror ne and
  839. { % Attempt to store the stack contents atomically.
  840. count array astore dup $error /ostack 4 -1 roll
  841. % Grab the execstack, then remove to two elements that are from
  842. % this error handler (not interesting).
  843. countexecstack array execstack dup length 2 sub 0 exch getinterval
  844. $error /estack 3 -1 roll
  845. countdictstack array dictstack $error /dstack 3 -1 roll
  846. put put put aload pop
  847. }
  848. { $error /dstack .undef
  849. $error /estack .undef
  850. $error /ostack .undef
  851. }
  852. ifelse
  853. $error /position currentfile status
  854. { currentfile { fileposition } .internalstopped { pop //null } if
  855. }
  856. { % If this was a scanner error, the file is no longer current,
  857. % but the command holds the file, which may still be open.
  858. $error /command get dup type /filetype eq
  859. { { fileposition } .internalstopped { pop //null } if }
  860. { pop //null }
  861. ifelse
  862. }
  863. ifelse put
  864. % During initialization, we don't reset the allocation
  865. % mode on errors.
  866. $error /globalmode get $error /.nosetlocal get and .setglobal
  867. $error /.inerror false put
  868. stop
  869. } bind def
  870. % Define the standard handleerror. We break out the printing procedure
  871. % (.printerror) so that it can be extended for binary output
  872. % if the Level 2 facilities are present.
  873. /.printerror
  874. { $error begin newerror
  875. {
  876. /command load errorname SHORTERRORS
  877. { (%%[ Error: ) print =only flush
  878. (; OffendingCommand: ) print =only
  879. errorinfo dup //null eq {
  880. pop
  881. } {
  882. (;\nErrorInfo:) print
  883. dup type /arraytype eq
  884. { { ( ) print =only } forall }
  885. { ( ) print =only }
  886. ifelse
  887. } ifelse
  888. ( ]%%) = flush
  889. }
  890. { (Error: ) print ==only flush
  891. ( in ) print ==only flush
  892. errorinfo dup //null eq {
  893. pop
  894. } {
  895. (\nAdditional information: ) print ==only flush
  896. } ifelse
  897. .printerror_long
  898. }
  899. ifelse
  900. .clearerror flush
  901. }
  902. { % newerror is false, test to see if user has set handleerror to a different
  903. % routine, if so execute it, otherwise, just return. This code deals with the
  904. % Genoa issue of setting /handleerror, and then calling it, without an error
  905. % being set. We were erroring in this case, due to /command load failing.
  906. //JOBSERVER {
  907. /errordict .systemvar /handleerror get /.GShandleerror .systemvar ne
  908. } {
  909. false
  910. } ifelse
  911. { /errordict .systemvar begin /handleerror load .internalstopped pop end
  912. }
  913. if
  914. }
  915. ifelse % newerror
  916. end
  917. flush
  918. } bind def
  919. /.printerror_long % long error printout,
  920. % $error is on the dict stack
  921. { % Push the (anonymous) stack printing procedure.
  922. % <heading> <==flag> <override-name> <stackname> proc
  923. {
  924. currentdict exch .knownget % stackname defined in $error?
  925. {
  926. 4 1 roll % stack: <stack> <head> <==flag> <over>
  927. /errordict .systemvar exch .knownget % overridename defined?
  928. {
  929. exch pop exch pop exec % call override with <stack>
  930. }
  931. {
  932. exch print exch % print heading. stack <==flag> <stack>
  933. 1 index not { () = } if
  934. { 1 index { (\n ) } { ( ) } ifelse print
  935. dup type /dicttype eq
  936. {
  937. (--dict:) print
  938. dup rcheck {
  939. dup length =only (/) print dup maxlength =only
  940. dup wcheck not { ((ro)) print } if
  941. } if
  942. /gcheck where {
  943. pop gcheck { ((G)) } { ((L)) } ifelse print
  944. } {
  945. pop
  946. } ifelse (--) print
  947. }
  948. {
  949. dup type /stringtype eq 2 index or
  950. { ==only } { =only } ifelse
  951. } ifelse
  952. } forall
  953. pop
  954. }
  955. ifelse % overridden
  956. }
  957. { pop pop pop
  958. }
  959. ifelse % stack known
  960. }
  961. (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  962. (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  963. (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  964. (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  965. () =
  966. pop % printing procedure
  967. errorname /VMerror eq
  968. { (VM status:) print mark vmstatus
  969. counttomark { ( ) print counttomark -1 roll dup =only } repeat
  970. cleartomark () =
  971. } if
  972. .languagelevel 2 ge
  973. { (Current allocation mode is ) print
  974. globalmode { (global\n) } { (local\n) } ifelse print
  975. } if
  976. .oserrno dup 0 ne
  977. { (Last OS error: ) print
  978. errorname /VMerror ne
  979. { dup .oserrorstring { = pop } { = } ifelse }
  980. { = }
  981. ifelse
  982. }
  983. { pop
  984. }
  985. ifelse
  986. position //null ne
  987. { (Current file position is ) print position = }
  988. if
  989. } bind def
  990. % Define a procedure for clearing the error indication.
  991. /.clearerror
  992. { $error /newerror false put
  993. $error /errorname //null put
  994. $error /errorinfo //null put
  995. 0 .setoserrno
  996. } bind def
  997. % Define $error. This must be in local VM.
  998. .currentglobal false .setglobal
  999. /$error 40 dict .forcedef % $error is local, systemdict is global
  1000. % newerror, errorname, command, errorinfo,
  1001. % ostack, estack, dstack, recordstacks,
  1002. % binary, globalmode,
  1003. % .inerror, .nosetlocal, position,
  1004. % plus extra space for badly designed error handers.
  1005. $error begin
  1006. /newerror false def
  1007. /recordstacks true def
  1008. /binary false def
  1009. /globalmode .currentglobal def
  1010. /.inerror false def
  1011. /.nosetlocal true def
  1012. /position //null def
  1013. /errorinfo //null def
  1014. end
  1015. % Define errordict similarly. It has one entry per error name,
  1016. % plus handleerror. However, some astonishingly badly written PostScript
  1017. % files require it to have at least one empty slot.
  1018. /errordict ErrorNames length 3 add dict
  1019. .forcedef % errordict is local, systemdict is global
  1020. .setglobal % back to global VM
  1021. % For greater Adobe compatibility, we put all non-standard errors in a
  1022. % separate dictionary, gserrordict. It does not need to be in local VM,
  1023. % because PostScript programs do not access it.
  1024. % NOTE: the name gserrordict is known to the interpreter.
  1025. /gserrordict 5 dict def
  1026. % Register an error in errordict. We make this a procedure because we only
  1027. % register the Level 1 errors here: the rest are registered by "feature"
  1028. % files. However, ErrorNames contains all of the error names regardless of
  1029. % what features are included, so we have to "know" that VMerror is the last
  1030. % Level 1 error.
  1031. /.registererror % <name> .registererror -
  1032. { errordict exch .registererror2
  1033. } bind def
  1034. /.registererror2 % <dict> <name> .registererror -
  1035. { .currentglobal true .setglobal % create procs in global VM
  1036. 3 1 roll
  1037. mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx put
  1038. .setglobal
  1039. } bind def
  1040. ErrorNames
  1041. { dup .registererror /VMerror eq {exit} if
  1042. } forall
  1043. errordict begin
  1044. % The handlers for interrupt and timeout are special; there is no
  1045. % 'current object', so they push their own name.
  1046. { /interrupt /timeout }
  1047. { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  1048. } forall
  1049. /handleerror % this key is 'well known' and some PS may redefine it
  1050. { /.printerror .systemvar exec
  1051. } bind def
  1052. end % errordict
  1053. % Put non-standard errors in gserrordict.
  1054. gserrordict /unknownerror errordict /unknownerror get put
  1055. errordict /unknownerror .undef
  1056. % Define a stable private copy of handleerror that we will always use under
  1057. % JOBSERVER mode.
  1058. /.GShandleerror errordict /handleerror get def
  1059. % Define the [write]==[only] procedures.
  1060. /.dict 8 dict dup
  1061. begin def
  1062. /.cvp {1 index exch 1 .writecvp} bind def
  1063. /.p {1 index exch writestring} bind def
  1064. /.p1 {2 index exch writestring} bind def
  1065. /.p2 {3 index exch writestring} bind def
  1066. /.print
  1067. { dup type .dict exch .knownget { exec } { .cvp } ifelse
  1068. } bind def
  1069. /arraytype
  1070. {dup rcheck
  1071. {() exch dup xcheck
  1072. {({) .p2
  1073. {exch .p1
  1074. 1 index exch .print pop ( )} forall
  1075. (})}
  1076. {([) .p2
  1077. {exch .p1
  1078. 1 index exch .print pop ( )} forall
  1079. (])}
  1080. ifelse exch pop .p}
  1081. {.cvp}
  1082. ifelse} bind def
  1083. /packedarraytype /arraytype load def
  1084. {//.dict begin .print pop end}
  1085. bind
  1086. end
  1087. /write==only exch def
  1088. /write== {1 index exch write==only (\n) writestring} bind def
  1089. /==only { (%stdout) (w) file exch write==only } bind def
  1090. /== {==only (\n) print} bind def
  1091. % Define [write]===[only], an extension that prints dictionaries
  1092. % in readable form and doesn't truncate strings.
  1093. /.dict /write==only load 0 get dup length 2 add dict .copydict dup
  1094. begin def
  1095. /dicttype
  1096. { dup rcheck
  1097. { (<< ) .p1
  1098. { 2 index 3 -1 roll .print pop ( ) .p1
  1099. 1 index exch .print pop ( ) .p
  1100. }
  1101. forall (>>) .p
  1102. }
  1103. { .cvp
  1104. }
  1105. ifelse
  1106. } bind def
  1107. /stringtype
  1108. { 1 index exch 2 .writecvp
  1109. } bind def
  1110. {//.dict begin .print pop end}
  1111. bind
  1112. end
  1113. /write===only exch def
  1114. /write=== {1 index exch write===only (\n) writestring} bind def
  1115. /===only { (%stdout) (w) file exch write===only } bind def
  1116. /=== { ===only (\n) print } bind def
  1117. % Create the initialization queue.
  1118. /.delayed_init_queue 10 dict def
  1119. /.schedule_init % <priority> <proc> .schedule_init -
  1120. {
  1121. //.delayed_init_queue 2 index known {
  1122. (.delayed_init_queue priority conflict with ) print 1 index =
  1123. /.schedule_init cvx /configurationerror signalerror
  1124. } if
  1125. //.delayed_init_queue 3 1 roll .growput
  1126. } bind def
  1127. /.execute_scheduled_inits % - .execute_scheduled_inits -
  1128. {
  1129. { 0 //null //.delayed_init_queue { % maxp {} p {}
  1130. 3 index 2 index lt {
  1131. 4 2 roll
  1132. } if
  1133. pop pop
  1134. } forall
  1135. exch //.delayed_init_queue exch undef
  1136. dup //null eq {
  1137. pop exit
  1138. } if
  1139. exec
  1140. } loop
  1141. } bind def
  1142. (END PROCS) VMDEBUG
  1143. % Define the font directory.
  1144. /FontDirectory false .setglobal 100 dict true .setglobal
  1145. .forcedef % FontDirectory is local, systemdict is global
  1146. % Define the encoding dictionary.
  1147. /EncodingDirectory 16 dict def % enough for Level 2 + PDF standard encodings
  1148. % Define .findencoding. (This is redefined in Level 2.)
  1149. /.findencoding
  1150. { //EncodingDirectory exch get exec
  1151. } bind def
  1152. /.defineencoding
  1153. { //EncodingDirectory 3 1 roll put
  1154. } bind def
  1155. % If we've got the composite font extensions, define findencoding.
  1156. % To satisfy the Genoa FTS, findencoding must be a procedure, not an operator.
  1157. /rootfont where { pop /findencoding { .findencoding } def } if
  1158. % Define .registerencoding.
  1159. % NOTE: This procedure no longer does anything, but it must continue to
  1160. % exist for the sake of toolbin/encs2c.ps.
  1161. /.registerencoding { % <index> <array> .registerencoding -
  1162. pop pop
  1163. } bind odef
  1164. % Load StandardEncoding.
  1165. %% Replace 1 (gs_std_e.ps)
  1166. (gs_std_e.ps) dup runlibfile VMDEBUG
  1167. % Load ISOLatin1Encoding.
  1168. %% Replace 1 (gs_il1_e.ps)
  1169. (gs_il1_e.ps) dup runlibfile VMDEBUG
  1170. % Define stubs for the Symbol and Dingbats encodings.
  1171. % Note that the first element of the procedure must be the file name,
  1172. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  1173. /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  1174. %% Replace 3 (gs_sym_e.ps)
  1175. EncodingDirectory /SymbolEncoding
  1176. { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  1177. bind put
  1178. /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  1179. %% Replace 3 (gs_dbt_e.ps)
  1180. EncodingDirectory /DingbatsEncoding
  1181. { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  1182. bind put
  1183. (END FONTDIR/ENCS) VMDEBUG
  1184. % Construct a dictionary of all available devices.
  1185. % These are (read-only) device prototypes that can't be
  1186. % installed or have their parameters changed. For this reason,
  1187. % the value in the dictionary is actually a 2-element writable array,
  1188. % to allow us to create a default instance of the prototype on demand.
  1189. % Loop until the .getdevice gets a rangecheck.
  1190. errordict /rangecheck 2 copy get
  1191. errordict /rangecheck { pop stop } put % pop the command
  1192. 0 { {dup .getdevice exch 1 add} loop} .internalstopped pop
  1193. 1 add dict /devicedict 1 index def
  1194. begin % 2nd copy of count is on stack
  1195. { dup .devicename exch
  1196. dup wcheck { dup } { //null } ifelse 2 array astore def
  1197. } repeat
  1198. end
  1199. put % errordict /rangecheck
  1200. .clearerror
  1201. /devicenames devicedict { pop } forall devicedict length packedarray def
  1202. % Determine the default device.
  1203. /defaultdevice DISPLAYING
  1204. { systemdict /DEVICE .knownget
  1205. { devicedict 1 index known not
  1206. { (Unknown device: ) print =
  1207. flush /defaultdevice cvx 1 .quit
  1208. }
  1209. if
  1210. }
  1211. { .getdefaultdevice .devicename
  1212. }
  1213. ifelse
  1214. }
  1215. { /nullpage
  1216. }
  1217. ifelse
  1218. /.defaultdevicename 1 index def
  1219. finddevice % make a copy
  1220. def
  1221. devicedict /Default devicedict .defaultdevicename get put
  1222. (END DEVS) VMDEBUG
  1223. % Define statusdict, for the benefit of programs
  1224. % that think they are running on a LaserWriter or similar printer.
  1225. %% Replace 1 (gs_statd.ps)
  1226. (gs_statd.ps) runlibfile
  1227. (END STATD) VMDEBUG
  1228. % Load the standard font environment.
  1229. %% Replace 1 (gs_fonts.ps)
  1230. (gs_fonts.ps) runlibfile
  1231. (END GS_FONTS) VMDEBUG
  1232. % Define the default halftone screen and BG/UCR functions now, so that
  1233. % it will bind in the original definitions of set[color]screen.
  1234. % We make this a procedure so we can call it again when switching devices.
  1235. % Use an ordered dither for low-resolution devices.
  1236. /.setloreshalftone { % <dpi> .setloreshalftone -
  1237. % The following 'ordered dither' spot function was contributed by
  1238. % Gregg Townsend. Thanks, Gregg!
  1239. 16.001 div 0 % not 16: avoids rounding problems
  1240. { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1241. 0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1242. CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1243. 3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1244. FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1245. 01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1246. C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1247. 31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1248. F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1249. 0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1250. CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1251. 3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1252. FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1253. 02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1254. C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1255. 32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1256. F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1257. > exch get 256 div
  1258. }
  1259. bind
  1260. % Use correct, per-plane screens for CMYK devices only.
  1261. //systemdict /setcolorscreen known processcolors 4 eq and
  1262. { 3 copy 6 copy //setcolorscreen }
  1263. { //setscreen }
  1264. ifelse
  1265. } bind def
  1266. /.setloresscreen { % <dpi> .setloresscreen -
  1267. .setloreshalftone
  1268. 0 array cvx settransfer % Genoa CET won't accept a packed array!
  1269. /setstrokeadjust where { pop true setstrokeadjust } if
  1270. } bind def
  1271. % Use a 45-degree spot screen for high-resolution devices.
  1272. % The PS3 CET insists that the screen be an array and not a packedarray (!).
  1273. currentpacking false setpacking
  1274. /.linescreen
  1275. % The following screen algorithm is used by permission of the author.
  1276. { ((C) 1989 Berthold K.P. Horn) pop
  1277. 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos
  1278. 1 0.08 sub mul add 2 div
  1279. }
  1280. bind readonly def
  1281. setpacking
  1282. /.sethireshalftone { % <dpi> .sethireshalftone <doscreen>
  1283. % According to information published by Hewlett-Packard,
  1284. % they use a 60 line screen on 300 DPI printers and
  1285. % an 85 line screen on 600 DPI printers.
  1286. % However, we use a 106 line screen, which produces smoother-
  1287. % looking shades but fewer of them (32 vs. 50).
  1288. % 46 was suggested as a good frequency value for printers
  1289. % between 200 and 400 DPI, so we use it for lower resolutions.
  1290. % Imagesetters need even higher frequency screens.
  1291. //systemdict /DITHERPPI known
  1292. { DITHERPPI
  1293. }
  1294. { dup cvi 100 idiv 15 .min
  1295. {//null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
  1296. exch get
  1297. }
  1298. ifelse
  1299. 1 index 4.01 div .min % at least a 4x4 cell
  1300. 45
  1301. //.linescreen
  1302. % Determine whether we have lots of process colors.
  1303. % If so, don't bother with color screening or gamma correction.
  1304. % Also don't do gamma correction on very high-resolution devices.
  1305. % (This should depend on dot gain, not resolution, but we don't
  1306. % currently have a way to determine this.) Ignore missing components
  1307. % (*Values = 1).
  1308. currentdevice mark
  1309. /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1310. .dicttomark .getdeviceparams
  1311. counttomark 2 idiv 1 sub
  1312. { exch pop dup 1 le
  1313. { pop }
  1314. { exch dup 1 le
  1315. { pop }
  1316. { .min }
  1317. ifelse
  1318. }
  1319. ifelse
  1320. }
  1321. repeat
  1322. exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
  1323. % Stack: doscreen dpi freq angle proc
  1324. % Ghostscript currently doesn't use correct, per-plane halftones
  1325. % unless setcolorscreen has been executed. Since these are
  1326. % computationally much more expensive than binary halftones,
  1327. % we check to make sure they are really warranted, i.e., we have
  1328. % a high-resolution CMYK device (i.e., not a display) with
  1329. % fewer than 5 bits per plane (i.e., not a true-color device).
  1330. 4 -1 roll 150 ge
  1331. { /setcolorscreen where
  1332. { pop //systemdict /COLORSCREEN known
  1333. { COLORSCREEN }
  1334. { 3 index }
  1335. ifelse
  1336. dup false ne
  1337. { 4 1 roll 3 copy 6 copy 13 -1 roll
  1338. % For really high-quality screening on printers, we need to
  1339. % give each plane its own screen angle. Unfortunately,
  1340. % this currently has very large space and time costs.
  1341. true eq % true => different angles,
  1342. % 0 => same angles
  1343. { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1344. }
  1345. if //setcolorscreen
  1346. }
  1347. { pop //setscreen % false => single binary screen
  1348. }
  1349. ifelse
  1350. }
  1351. { //setscreen % setcolorscreen not known
  1352. }
  1353. ifelse
  1354. }
  1355. { //setscreen % not high resolution
  1356. }
  1357. ifelse
  1358. } bind def
  1359. /.sethiresscreen { % <dpi> .sethiresscreen
  1360. .sethireshalftone % pushes true if a screen halftone used
  1361. % Stack: doscree
  1362. {
  1363. % Set the transfer function to lighten up the grays.
  1364. % Parameter values closer to 1 are better for devices with
  1365. % less dot spreading; lower values are better with more spreading.
  1366. % The value 0.8 is a compromise that will probably please no one!
  1367. %
  1368. % Because of a bug in FrameMaker, we have to accept operands
  1369. % outside the valid range of [0..1].
  1370. {
  1371. dup dup 0.0 gt exch 1.0 lt and
  1372. {
  1373. 0.8 exp
  1374. }
  1375. if
  1376. }
  1377. }
  1378. {
  1379. % Set the transfer function to the identity.
  1380. 0 array cvx % Genoa CET won't accept a packed array!
  1381. }
  1382. ifelse
  1383. settransfer
  1384. /setstrokeadjust where
  1385. { pop false setstrokeadjust }
  1386. if
  1387. % Increase fill adjustment so that we effectively use Adobe's
  1388. % any-part-of-pixel rule.
  1389. 0.5 .setfilladjust
  1390. } bind def
  1391. % Set the default screen and BG/UCR.
  1392. /.setdefaultbgucr {
  1393. systemdict /setblackgeneration known {
  1394. { pop 0 } dup setblackgeneration setundercolorremoval
  1395. } if
  1396. } bind def
  1397. /.useloresscreen { % - .useloresscreen <bool>
  1398. % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1399. 72 72 matrix defaultmatrix dtransform abs exch abs .min
  1400. dup 150 lt //systemdict /DITHERPPI known not and
  1401. } bind def
  1402. % The following implementation uses LL2 extensions, but only in stopped
  1403. % contexts so that with LL1, the .set??reshalftone will be used.
  1404. %
  1405. % - .getdefaulthalftone <halftonedict> true if default found
  1406. % false
  1407. /.getdefaulthalftone {
  1408. % try the device to see if it has a default halftone
  1409. { currentdevice /HalftoneDefault gsgetdeviceprop } .internalstopped
  1410. { pop pop false } % no device property
  1411. { dup type /dicttype eq { true } { pop false } ifelse }
  1412. ifelse
  1413. % stack: <halftonedict> true if default found
  1414. % false not found
  1415. dup not
  1416. { % device did not provide a default, try Resource
  1417. pop { /Default /Halftone /findresource .systemvar exec } .internalstopped
  1418. { pop pop false } { true } ifelse
  1419. }
  1420. if
  1421. } bind def
  1422. /.setdefaulthalftone {
  1423. .getdefaulthalftone
  1424. { sethalftone }
  1425. { % default not found
  1426. .useloresscreen { .setloreshalftone } { .sethireshalftone pop } ifelse
  1427. }
  1428. ifelse
  1429. } bind def
  1430. /.setdefaultscreen {
  1431. .useloresscreen { .setloresscreen } { .sethiresscreen } ifelse
  1432. .setdefaultbgucr
  1433. } bind def
  1434. % Rendering intent mapping for setcolorrendering1 and PDF interpreter
  1435. /.renderingintentdict mark
  1436. /Perceptual 0
  1437. /RelativeColorimetric 1
  1438. /Saturation 2
  1439. /AbsoluteColorimetric 3
  1440. .dicttomark readonly def
  1441. % Load basic color support
  1442. %% Replace 1 (gs_cspace.ps)
  1443. (gs_cspace.ps) runlibfile
  1444. (END BASIC COLOR) VMDEBUG
  1445. % Load image support
  1446. %% Replace 1 (gs_img.ps)
  1447. (gs_img.ps) runlibfile
  1448. (END IMAGE) VMDEBUG
  1449. % Auxiliary procedures for generating file name templates.
  1450. % Convert a path name into a string suitable for filenameforall
  1451. % For example: (a\\b*?c) to (a\\\\b\\*\\?c)
  1452. /.makepathtemplate { % str1 -- str2
  1453. dup length dup add string 0 % result string up to twice the size
  1454. 0 1 4 index length 1 sub {
  1455. 3 index exch get
  1456. dup 92 eq { % \ -> \\
  1457. 2 index 2 index 92
  1458. put
  1459. exch 1 add exch
  1460. }
  1461. if
  1462. dup 42 eq { % * -> \*
  1463. 2 index 2 index 92
  1464. put
  1465. exch 1 add exch
  1466. }
  1467. if
  1468. dup 63 eq { % ? -> \?
  1469. 2 index 2 index 92
  1470. put
  1471. exch 1 add exch
  1472. }
  1473. if
  1474. 2 index 2 index 3 -1 roll put 1 add
  1475. } for
  1476. 0 exch getinterval exch pop
  1477. } bind def
  1478. % false <dir_list> <template> .generate_dir_list_templates_with_length <t1> ... <tN>
  1479. % true <dir_list> <template> .generate_dir_list_templates_with_length <t1> <l1> ... <tN> <ln>
  1480. %
  1481. % Generates various valid templates combining a directory list with a given template.
  1482. % With 'true' operand it also returns lengths of directory pathes.
  1483. %
  1484. % Example1 (DOS, Windows) :
  1485. % false [(/gs/lib) (/gs/Resource/) (\gs8.00\Resource)] (*/*) -->
  1486. % (/gs/lib/*/*) (/gs/Resource/*/*) (\\gs8.00\\Resource/*/*)
  1487. %
  1488. % Example2 (OpenVMS) :
  1489. % false [(gs:[lib]) (gs:[Resource]) (gs800:[Resource)] (*]*) -->
  1490. % ((gs:[lib.*]*) [gs:[Resource.*]*) ([gs800:[Resource.*]*)
  1491. %
  1492. /.generate_dir_list_templates_with_length
  1493. { % [dl] (templ)
  1494. % We need to convert paths into templates,
  1495. % because it can include '\' on DOS.
  1496. % In same time, the <template> must not convert,
  1497. % because it is already a template.
  1498. % Besides that, we cannot combine template using .file_name_combine,
  1499. % because template syntax breaks the platform path syntax.
  1500. % To resolve this, we first convert the <template> into
  1501. % a fake filename, and combine it with path,
  1502. % obtaining a correct separator. Then we replace
  1503. % the fake file name with the given template.
  1504. %
  1505. % Create the fake file name :
  1506. dup dup length string copy % b [dl] (templ) (ffn)
  1507. (*) 0 get (?) 0 get (\\) 0 get (x) 0 get 0 0 % b [dl] (templ) (ffn) * ? \ x i j
  1508. { 1 index 7 index length ge { exit } if
  1509. 6 index 2 index get % b [dl] (templ) (ffn) * ? \ x i j c
  1510. dup 7 index eq % b [dl] (templ) (ffn) * ? \ x i j c bool
  1511. 1 index 7 index eq or { % *?
  1512. pop 2 index
  1513. } if % b [dl] (templ) (ffn) * ? \ x i j C
  1514. dup 5 index eq { % \
  1515. 3 2 roll 1 add 3 1 roll % b [dl] (templ) (ffn) * ? \ x i' j C
  1516. 2 index 8 index length ge { pop exit } if
  1517. pop 6 index 2 index get % b [dl] (templ) (ffn) * ? \ x i' j C'
  1518. } if
  1519. 7 index 2 index 3 2 roll put % b [dl] (templ) (ffn) * ? \ x i' j
  1520. 1 add exch 1 add exch % b [dl] (templ) (ffn) * ? \ x i'' j'
  1521. } loop % b [dl] (templ) (ffn) * ? \ x i j
  1522. 6 1 roll pop % b [dl] (templ) (ffn) j * ? \ x
  1523. exch pop exch pop exch pop exch % b [dl] (templ) (ffn) x j
  1524. { dup 3 index length ge { exit } if
  1525. 3 copy exch put
  1526. 1 add
  1527. } loop
  1528. pop pop % b [dl] (templ) (ffn)
  1529. % An internal procedure :
  1530. { % {} b [dl] (templ) (ffn) (dffn)
  1531. dup length
  1532. 1 sub % drop 'x', which was added above.
  1533. exch % {} b [dl] (templ) (ffn) ldffn (dffn)
  1534. .makepathtemplate % {} b [dl] (templ) (ffn) ldffn (Dffn)
  1535. dup % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn)
  1536. 4 index length dup % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL templL
  1537. 2 index length % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL templL DffnL
  1538. exch sub % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL i
  1539. exch getinterval % {} b [dl] (templ) (ffn) ldffn (Dffn) (suffix)
  1540. 4 index exch copy pop % {} b [dl] (templ) (ffn) ldffn (dt)
  1541. 5 index {
  1542. exch % {} b [dl] (templ) (ffn) (dt) ldffn
  1543. 7 2 roll % (dt) ldffn {} b [dl] (templ) (ffn)
  1544. } {
  1545. exch pop % {} b [dl] (templ) (ffn) (dt)
  1546. 6 1 roll % (dt) {} b [dl] (templ) (ffn)
  1547. } ifelse
  1548. }
  1549. 5 1 roll % {} b [dl] (templ) (ffn)
  1550. % Generate templates :
  1551. dup .file_name_is_absolute {
  1552. dup % {} b [dl] (templ) (ffn) (ffn)
  1553. 5 index exec % (t1) {} b [dl] (templ) (ffn)
  1554. } {
  1555. 2 index { % ... {} b [dl] (templ) (ffn) (d)
  1556. 1 index % ... {} b [dl] (templ) (ffn) (d) (ffn)
  1557. false .file_name_combine { % ... {} b [dl] (templ) (ffn) (dffn)
  1558. 5 index exec % ... (t1) ?l1 {} b [dl] (templ) (ffn)
  1559. } { % ... {} b [dl] (templ) (ffn) (d) (ffn)
  1560. pop pop % ... {} b [dl] (templ) (ffn)
  1561. } ifelse
  1562. } forall
  1563. } ifelse % (t1) ?l1 (t2) ?l2 ... (tN) ?ln {} b [dl] (templ) (ffn)
  1564. pop pop pop pop pop % (t1) ?l1 (t2) ?l2 ... (tN) ?ln
  1565. } bind def
  1566. % <dir_list> <template> .generate_dir_list_templates <t1> ... <tN>
  1567. %
  1568. % Generates various valid templates combining a directory list with a given template.
  1569. % It's the 'false' case of the function above.
  1570. %
  1571. /.generate_dir_list_templates
  1572. { //false 3 1 roll //.generate_dir_list_templates_with_length exec
  1573. } bind def
  1574. % Load the initialization files for optional features.
  1575. %% Replace 4 INITFILES
  1576. systemdict /INITFILES known
  1577. { INITFILES { dup runlibfile VMDEBUG } forall
  1578. }
  1579. if
  1580. % If Level 2 (or higher) functionality is implemented, enable it now.
  1581. /.setlanguagelevel where {
  1582. pop 2 .setlanguagelevel
  1583. % If the resource machinery is loaded, fix up some things now.
  1584. /.fixresources where { pop .fixresources } if
  1585. } if
  1586. /ll3dict where {
  1587. pop 3 .setlanguagelevel
  1588. } if
  1589. (END INITFILES) VMDEBUG
  1590. % Create a null font. This is the initial font.
  1591. 8 dict dup begin
  1592. /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  1593. /FontType 3 def
  1594. /FontName () def
  1595. /Encoding StandardEncoding def
  1596. /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  1597. /BuildChar { pop pop 0 0 setcharwidth } bind def
  1598. /PaintType 0 def % shouldn't be needed!
  1599. end
  1600. /NullFont exch definefont setfont
  1601. % Define NullFont as the font.
  1602. /NullFont currentfont def
  1603. % Load initial fonts from FONTPATH directories, Fontmap file,
  1604. % and/or .getccfont as appropriate.
  1605. .loadinitialfonts
  1606. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  1607. /undefinefont where {
  1608. pop /NullFont undefinefont
  1609. } {
  1610. FontDirectory /NullFont .undef
  1611. } ifelse
  1612. (END FONTS) VMDEBUG
  1613. % Restore the real definition of runlibfile.
  1614. /runlibfile /.runlibfile load def
  1615. currentdict /.runlibfile .undef
  1616. % Bind all the operators defined as procedures.
  1617. /.bindoperators % binds operators in currentdict
  1618. { % Temporarily disable the typecheck error.
  1619. errordict /typecheck 2 copy get
  1620. errordict /typecheck { pop } put % pop the command
  1621. currentdict
  1622. { dup type /operatortype eq
  1623. { % This might be a real operator, so bind might cause a typecheck,
  1624. % but we've made the error a no-op temporarily.
  1625. .bind % do a real bind even if NOBIND is set
  1626. }
  1627. if pop pop
  1628. } forall
  1629. put
  1630. } def
  1631. NOBIND DELAYBIND or not { .bindoperators } if
  1632. % Establish a default environment.
  1633. defaultdevice
  1634. % The following line used to skip setting of page size and resolution if
  1635. % NODISPLAY was selected. We think this was only to save time and memory,
  1636. % and it is a bad idea because it prevents setting the resolution in this
  1637. % situation, which pstoedit (among other programs) relies on.
  1638. %DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1639. % If the paper size is not specifed and the device defaults to
  1640. % letter or A4 paper, select the DEFAULTPAPERSIZE.
  1641. systemdict /DEFAULTPAPERSIZE known not
  1642. {
  1643. % Use .defaultpapersize if it returns a known paper size
  1644. .defaultpapersize
  1645. {
  1646. false statusdict /.pagetypenames get
  1647. {
  1648. 2 index eq { pop true exit } if
  1649. }
  1650. forall
  1651. {systemdict exch /DEFAULTPAPERSIZE exch put}
  1652. {QUIET
  1653. { pop }
  1654. { (Unknown .defaultpapersize: ) print ==only (.) = }
  1655. ifelse
  1656. }
  1657. ifelse
  1658. }
  1659. if
  1660. }
  1661. if
  1662. systemdict /DEFAULTPAPERSIZE known
  1663. systemdict /PAPERSIZE known not and
  1664. systemdict /DEVICEWIDTH known not and
  1665. systemdict /DEVICEHEIGHT known not and
  1666. systemdict /DEVICEWIDTHPOINTS known not and
  1667. systemdict /DEVICEHEIGHTPOINTS known not and
  1668. {
  1669. defaultdevice mark /PageSize //null .dicttomark .getdeviceparams
  1670. .dicttomark /PageSize get
  1671. dup 0 get 0.5 add cvi 612 eq 1 index 1 get 0.5 add cvi 792 eq and
  1672. 1 index 0 get 0.5 add cvi 595 eq 2 index 1 get 0.5 add cvi 842 eq and
  1673. or exch pop
  1674. {
  1675. % the default paper size was letter, so replace it with DEFAULTPAPERSIZE
  1676. /PAPERSIZE DEFAULTPAPERSIZE def
  1677. } if
  1678. }
  1679. if
  1680. systemdict /DEVICEWIDTH known
  1681. systemdict /DEVICEHEIGHT known or
  1682. systemdict /DEVICEWIDTHPOINTS known or
  1683. systemdict /DEVICEHEIGHTPOINTS known or
  1684. systemdict /DEVICEXRESOLUTION known or
  1685. systemdict /DEVICEYRESOLUTION known or
  1686. systemdict /PAPERSIZE known or
  1687. not { (%END DEVICE) .skipeof } if
  1688. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1689. systemdict /PAPERSIZE known
  1690. systemdict /DEVICEWIDTH known not and
  1691. systemdict /DEVICEHEIGHT known not and
  1692. systemdict /DEVICEWIDTHPOINTS known not and
  1693. systemdict /DEVICEHEIGHTPOINTS known not and
  1694. { % Convert the paper size to device dimensions.
  1695. true statusdict /.pagetypenames get
  1696. { PAPERSIZE eq
  1697. { PAPERSIZE load
  1698. dup 0 get /DEVICEWIDTHPOINTS exch def
  1699. 1 get /DEVICEHEIGHTPOINTS exch def
  1700. pop false exit
  1701. }
  1702. if
  1703. }
  1704. forall
  1705. { (Unknown paper size: ) print PAPERSIZE ==only (.) =
  1706. }
  1707. if
  1708. }
  1709. if
  1710. % Adjust the device parameters per the command line.
  1711. % It is possible to specify resolution, pixel size, and page size;
  1712. % since any two of these determine the third, conflicts are possible.
  1713. % We simply pass them to .setdeviceparams and let it sort things out.
  1714. mark /HWResolution //null /HWSize //null /PageSize //null .dicttomark
  1715. .getdeviceparams .dicttomark begin
  1716. mark
  1717. % Check for resolution.
  1718. /DEVICEXRESOLUTION where dup
  1719. { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  1720. if
  1721. /DEVICEYRESOLUTION where dup
  1722. { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  1723. if
  1724. or { /HWResolution HWResolution } if
  1725. % Check for device sizes specified in pixels.
  1726. /DEVICEWIDTH where dup
  1727. { exch pop HWSize 0 DEVICEWIDTH put }
  1728. if
  1729. /DEVICEHEIGHT where dup
  1730. { exch pop HWSize 1 DEVICEHEIGHT put }
  1731. if
  1732. or { /HWSize HWSize } if
  1733. % Check for device sizes specified in points.
  1734. /DEVICEWIDTHPOINTS where dup
  1735. { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  1736. if
  1737. /DEVICEHEIGHTPOINTS where dup
  1738. { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  1739. if
  1740. or { /PageSize PageSize } if
  1741. % Check whether any parameters were set.
  1742. dup mark eq { pop defaultdevice } { defaultdevice putdeviceprops } ifelse
  1743. end
  1744. %END DEVICE
  1745. % Set any device properties defined on the command line.
  1746. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  1747. systemdict /BufferSpace known
  1748. systemdict /MaxBitmap known not and
  1749. { systemdict /MaxBitmap BufferSpace put
  1750. } if
  1751. dup getdeviceprops
  1752. counttomark 2 idiv
  1753. { systemdict 2 index known
  1754. { pop dup load counttomark 2 roll }
  1755. { pop pop }
  1756. ifelse
  1757. } repeat
  1758. counttomark dup 0 ne
  1759. { 2 add -1 roll putdeviceprops }
  1760. { pop pop }
  1761. ifelse
  1762. % If the initial device parameters are invalid, the setdevice may fail.
  1763. % Trap this and produce a reasonable error message.
  1764. { setdevice } % does an erasepage
  1765. INITDEBUG { exec false } { .internalstopped } ifelse {
  1766. (**** Unable to open the initial device, quitting.) = flush 1 .quit
  1767. } if
  1768. % If the media size is fixed, update the current page device dictionary.
  1769. FIXEDMEDIA
  1770. dup { pop systemdict /.currentpagedevice known } if
  1771. dup { pop .currentpagedevice exch pop } if
  1772. not { (%END MEDIA) .skipeof } if
  1773. currentpagedevice dup length dict .copydict
  1774. dup /Policies
  1775. % Stack: <pagedevice> <pagedevice> /Policies
  1776. 1 index /InputAttributes
  1777. 2 copy get dup length dict .copydict
  1778. % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1779. % /InputAttributes <inputattrs'>
  1780. dup 0 2 copy get dup length dict .copydict
  1781. % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1782. % /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
  1783. dup /PageSize 7 index /PageSize get
  1784. put % PageSize in 0
  1785. put % 0 in InputAttributes
  1786. put % InputAttributes in pagedevice
  1787. % Also change the page size policy so we don't get an error.
  1788. % Stack: <pagedevice> <pagedevice> /Policies
  1789. 2 copy get dup length dict .copydict
  1790. % Stack: <pagedevice> <pagedevice> /Policies <policies'>
  1791. dup /PageSize 7 put % PageSize in Policies
  1792. put % Policies in pagedevice
  1793. .setpagedevice
  1794. %END MEDIA
  1795. % Set up the interpreter context version of -dUSeCIEColor option
  1796. % so that .getuseciecolor has the correct value (see gs_setpd.ps)
  1797. /setpagedevice where {
  1798. pop systemdict /UseCIEColor known {
  1799. mark /UseCIEColor UseCIEColor .dicttomark setpagedevice
  1800. } if
  1801. } if
  1802. %END DISPLAYING
  1803. (END DEVICE) VMDEBUG
  1804. % Establish a default upper limit in the character cache,
  1805. % namely, enough room for a 18-point character at the resolution
  1806. % of the default device, or for a character consuming 1% of the
  1807. % maximum cache size, whichever is larger.
  1808. mark
  1809. % Compute limit based on character size.
  1810. 18 dup dtransform
  1811. exch abs cvi 31 add 32 idiv 4 mul % X raster
  1812. exch abs cvi mul % Y
  1813. % Compute limit based on allocated space.
  1814. cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  1815. .max dup 10 idiv exch
  1816. setcacheparams
  1817. % Conditionally disable the character cache.
  1818. NOCACHE { 0 setcachelimit } if
  1819. (END CONFIG) VMDEBUG
  1820. % Initialize graphics.
  1821. .setdefaultscreen
  1822. initgraphics
  1823. % The interpreter relies on there being at least 2 entries
  1824. % on the graphics stack. Establish the second one now.
  1825. gsave
  1826. % Define some control sequences as no-ops.
  1827. % This is a hack to get around problems
  1828. % in some common PostScript-generating applications.
  1829. <04> cvn JOBSERVER {
  1830. { { clear cleardictstack //false 0 .startnewjob } 2 .stop } bind
  1831. } {
  1832. { }
  1833. } ifelse def
  1834. <1b> cvn { % UEL is <esc>%-12345X and acts the same as ^D
  1835. currentfile (%-12345X) .peekstring pop (%-12345X) eq <04> cvn load if
  1836. } bind def
  1837. <1b45> cvn { } def % PJL reset prologue (ESC E)
  1838. <1b451b> cvn <1b> cvn load def % PJL reset epilogue (ESC E + UEL)
  1839. (\001M) cvn % TBCP initiator
  1840. { currentfile /TBCPDecode filter cvx exec
  1841. } bind def
  1842. /@PJL % H-P job control
  1843. {
  1844. % Windows 2000 driver includes PJL into %%BeginFeature block.
  1845. % Identify this from the pattern on the stack: countdictstack lucas mark
  1846. % and fail the feature request.
  1847. count 3 ge {
  1848. dup mark eq {
  1849. 2 index countdictstack eq {
  1850. 1 index /lucas where { /lucas get eq } { pop false } ifelse {
  1851. stop
  1852. } if
  1853. } if
  1854. } if
  1855. } if
  1856. currentfile //=string readline pop pop
  1857. } bind def
  1858. % Install the EPS handler if needed
  1859. systemdict /EPSBoundingBoxInit known { EPSBoundingBoxInit } if
  1860. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1861. .currentglobal true .setglobal
  1862. /SAFETY 2 dict
  1863. dup /safe false put
  1864. dup /tempfiles 10 dict readonly put
  1865. readonly def
  1866. .setglobal
  1867. /.locksafe {
  1868. SAFETY /safe get not {
  1869. <<
  1870. /PermitFileReading [
  1871. currentuserparams /PermitFileReading get aload pop
  1872. /FONTPATH .systemvar (*) .generate_dir_list_templates
  1873. % Library files :
  1874. /LIBPATH .systemvar (*) .generate_dir_list_templates
  1875. % Resource files on OpenVMS requires a separate template (gs:[dir.*]*)
  1876. % because the (gs:[dir]*) doesn't cover them.
  1877. /LIBPATH .systemvar (*) .file_name_separator (*)
  1878. concatstrings concatstrings .generate_dir_list_templates
  1879. .languagelevel 2 ge {
  1880. % Default resources :
  1881. [ currentsystemparams /GenericResourceDir get] (*) .generate_dir_list_templates
  1882. % Default resources (OpenVMS, see comment above.) :
  1883. [ currentsystemparams /GenericResourceDir get] (*) .file_name_separator (*)
  1884. concatstrings concatstrings .generate_dir_list_templates
  1885. } if
  1886. ]
  1887. /LockFilePermissions true
  1888. >> setuserparams
  1889. }
  1890. if
  1891. % setpagedevice has the side effect of clearing the page, but
  1892. % we will just document that. Using setpagedevice keeps the device
  1893. % properties and pagedevice .LockSafetyParams in agreement even
  1894. % after a restore that changes the value to false.
  1895. currentglobal currentpagedevice gcheck setglobal % use correct VM space
  1896. << /.LockSafetyParams true >> setpagedevice
  1897. setglobal
  1898. //SAFETY /safe //true .forceput % overrides readonly
  1899. } .bind executeonly odef
  1900. /.setsafe
  1901. {
  1902. SAFETY /safe get not {
  1903. <<
  1904. /PermitFileReading [ ]
  1905. /PermitFileWriting [ ]
  1906. /PermitFileControl [ ]
  1907. >> setuserparams
  1908. }
  1909. if
  1910. .locksafe
  1911. } .bind executeonly odef
  1912. /deletefile {
  1913. dup { deletefile } stopped {
  1914. pop //deletefile $error /errorname get signalerror
  1915. } {
  1916. % deletefile succeeded. Remove from tempfile list if present
  1917. //SAFETY /tempfiles get exch cvn 2 copy known {
  1918. .forceundef
  1919. } {
  1920. pop pop
  1921. }
  1922. ifelse
  1923. }
  1924. ifelse
  1925. } .bind executeonly odef
  1926. % If a file is opened with .tempfile with SAFER not (yet) set,
  1927. % the file can be deleted later, even if SAFER is set.
  1928. /.tempfile {
  1929. .tempfile % filename file
  1930. //SAFETY /tempfiles get 2 .argindex true .forceput
  1931. } .bind executeonly odef
  1932. % If we are running in SAFER mode, lock things down
  1933. SAFER { .setsafe } if
  1934. % If we delayed binding, make it possible to do it later.
  1935. /.bindnow {
  1936. currentuserparams /IdiomRecognition .knownget {
  1937. 1 dict dup /IdiomRecognition //false put setuserparams
  1938. } if
  1939. //systemdict begin .bindoperators end
  1940. % Temporarily disable the typecheck error.
  1941. errordict /typecheck 2 copy get
  1942. errordict /typecheck { pop } put % pop the command
  1943. 0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  1944. //systemdict /.delaybind {} .forceput % reclaim the space
  1945. //systemdict /.bindnow .forceundef % ditto
  1946. put
  1947. //systemdict /.forcecopynew .forceundef % remove temptation
  1948. //systemdict /.forcedef .forceundef % ditto
  1949. //systemdict /.forceput .forceundef % ditto
  1950. //systemdict /.forceundef .forceundef % ditto
  1951. currentuserparams /IdiomRecognition known {
  1952. 1 dict dup /IdiomRecognition 4 -1 roll put setuserparams
  1953. } if
  1954. } .bind odef
  1955. % Turn off array packing, since some PostScript code assumes that
  1956. % procedures are writable.
  1957. false setpacking
  1958. (END INIT) VMDEBUG
  1959. /.currentuserparams where {
  1960. pop
  1961. % Remove real user params from psuserparams.
  1962. mark .currentuserparams counttomark 2 idiv {
  1963. pop psuserparams exch undef
  1964. } repeat pop
  1965. % Update the copy of the user parameters.
  1966. mark .currentuserparams counttomark 2 idiv {
  1967. userparams 3 1 roll .forceput % userparams is read-only
  1968. } repeat pop
  1969. % Turn on idiom recognition, if available.
  1970. currentuserparams /IdiomRecognition known {
  1971. /IdiomRecognition true .definepsuserparam
  1972. } if
  1973. psuserparams readonly pop
  1974. systemdict /.definepsuserparam undef
  1975. % Save a copy of userparams for use with save/restore
  1976. % (and, if implemented, context switching).
  1977. .currentglobal false .setglobal
  1978. mark userparams { } forall .dicttomark readonly
  1979. /userparams exch .forcedef % systemdict is read-only
  1980. .setglobal
  1981. } if
  1982. /.currentsystemparams where {
  1983. pop
  1984. % Remove real system params from pssystemparams.
  1985. mark .currentsystemparams counttomark 2 idiv {
  1986. pop pssystemparams exch .forceundef
  1987. } repeat pop
  1988. } if
  1989. % Set up AlignToPixels :
  1990. /AlignToPixels where {
  1991. mark /AlignToPixels 2 index /AlignToPixels get .dicttomark setuserparams
  1992. /AlignToPixels undef
  1993. } if
  1994. % Set up GridFitTT :
  1995. /GridFitTT where {
  1996. mark /GridFitTT 2 index /GridFitTT get .dicttomark setuserparams
  1997. /GridFitTT undef
  1998. } if
  1999. % Establish local VM as the default.
  2000. false /setglobal where { pop setglobal } { .setglobal } ifelse
  2001. $error /.nosetlocal false put
  2002. (END GLOBAL) VMDEBUG
  2003. /.savelocalstate where {
  2004. % If we might create new contexts, save away copies of all dictionaries
  2005. % referenced from systemdict that are stored in local VM,
  2006. % and also save a copy of the initial gstate.
  2007. pop .savelocalstate
  2008. } {
  2009. % If we're *not* running in a multi-context system and FAKEFONTS is
  2010. % defined, add the fake fonts to LocalFontDirectory.
  2011. .definefakefonts % current VM is local
  2012. } ifelse
  2013. % Execute scheduled inits :
  2014. //.execute_scheduled_inits exec
  2015. currentdict /.execute_scheduled_inits undef
  2016. currentdict /.delayed_init_queue undef
  2017. % Make global and local FontDirectory read-only.
  2018. FontDirectory readonly pop
  2019. /GlobalFontDirectory where { pop GlobalFontDirectory readonly pop } if
  2020. % Remove systemdict entries for things that have been bound in where used
  2021. % and that shouldn't be accessible by name, and close up systemdict.
  2022. currentdict /filterdict .undef
  2023. currentdict /.cidfonttypes .undef
  2024. currentdict /.colorrenderingtypes .undef
  2025. currentdict /.formtypes .undef
  2026. currentdict /.halftonetypes .undef
  2027. currentdict /.imagetypes .undef
  2028. currentdict /.imagemasktypes .undef
  2029. currentdict /.patterntypes .undef
  2030. currentdict /.shadingtypes .undef
  2031. currentdict /.wheredict .undef
  2032. currentdict /.renderingintentdict .undef
  2033. end
  2034. % Clean up VM, and enable GC.
  2035. /vmreclaim where
  2036. { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  2037. } if
  2038. DELAYBIND not {
  2039. systemdict /.forcecopynew .undef % remove temptation
  2040. systemdict /.forcedef .undef % ditto
  2041. systemdict /.forceput .undef % ditto
  2042. systemdict /.forceundef .undef % ditto
  2043. } if
  2044. % Move superexec to internaldict if superexec is defined.
  2045. currentdict /superexec .knownget {
  2046. 1183615869 internaldict /superexec 3 -1 roll put
  2047. currentdict /superexec .undef
  2048. } if
  2049. WRITESYSTEMDICT not { systemdict readonly pop } if
  2050. (END GC) VMDEBUG
  2051. % The Adobe AGM_Core used by Illustrator 9 has some code that breaks
  2052. % if the 'product' is not (Adobe PostScript Parser). A bug has been
  2053. % submitted to Adobe since this also fails with Acrobat Distiller.
  2054. % As a temporary work around, the following HACK will work for
  2055. % devices without spot color support. Once Ghostscript can
  2056. % support DeviceN and spot color separations this will need to
  2057. % be 'true' in some cases.
  2058. userdict /AGM_preserve_spots false put
  2059. % The interpreter will run the initial procedure (start).