1
0

gs_init.ps 71 KB

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