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.

335 lines
12 KiB

1 month ago
  1. % Copyright (C) 2001-2023 Artifex Software, Inc.
  2. % All Rights Reserved.
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  7. % This software is distributed under license and may not be copied,
  8. % modified or distributed except as expressly authorized under the terms
  9. % of the license contained in the file LICENSE in this distribution.
  10. %
  11. % Refer to licensing information at http://www.artifex.com or contact
  12. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  13. % CA 94129, USA, for further information.
  14. %
  15. % Initialization file for binary tokens.
  16. % When this is run, systemdict is still writable,
  17. % but everything defined here goes into level2dict.
  18. % Define whether or not to allow writing dictionaries.
  19. % This is a non-standard feature!
  20. /WRITEDICTS //false def
  21. languagelevel 1 .setlanguagelevel
  22. level2dict begin
  23. % Initialization for the system name table.
  24. mark
  25. % 0
  26. /abs /add /aload /anchorsearch /and
  27. /arc /arcn /arct /arcto /array
  28. /ashow /astore /awidthshow /begin /bind
  29. /bitshift /ceiling /charpath /clear /cleartomark
  30. % 20
  31. /clip /clippath /closepath /concat /concatmatrix
  32. /copy /count /counttomark /currentcmykcolor /currentdash
  33. /currentdict /currentfile /currentfont /currentgray /currentgstate
  34. /currenthsbcolor /currentlinecap /currentlinejoin /currentlinewidth /currentmatrix
  35. % 40
  36. /currentpoint /currentrgbcolor /currentshared /curveto /cvi
  37. /cvlit /cvn /cvr /cvrs /cvs
  38. /cvx /def /defineusername /dict /div
  39. /dtransform /dup /end /eoclip /eofill
  40. % 60
  41. /eoviewclip /eq /exch /exec /exit
  42. /file /fill /findfont /flattenpath /floor
  43. /flush /flushfile /for /forall /ge
  44. /get /getinterval /grestore /gsave /gstate
  45. % 80
  46. /gt /identmatrix /idiv /idtransform /if
  47. /ifelse /image /imagemask /index /ineofill
  48. /infill /initviewclip /inueofill /inufill /invertmatrix
  49. /itransform /known /le /length /lineto
  50. % 100
  51. /load /loop /lt /makefont /matrix
  52. /maxlength /mod /moveto /mul /ne
  53. /neg /newpath /not /null /or
  54. /pathbbox /pathforall /pop /print /printobject
  55. % 120
  56. /put /putinterval /rcurveto /read /readhexstring
  57. /readline /readstring /rectclip /rectfill /rectstroke
  58. /rectviewclip /repeat /restore /rlineto /rmoveto
  59. /roll /rotate /round /save /scale
  60. % 140
  61. /scalefont /search /selectfont /setbbox /setcachedevice
  62. /setcachedevice2 /setcharwidth /setcmykcolor /setdash /setfont
  63. /setgray /setgstate /sethsbcolor /setlinecap /setlinejoin
  64. /setlinewidth /setmatrix /setrgbcolor /setshared /shareddict
  65. % 160
  66. /show /showpage /stop /stopped /store
  67. /string /stringwidth /stroke /strokepath /sub
  68. /systemdict /token /transform /translate /truncate
  69. /type /uappend /ucache /ueofill /ufill
  70. % 180
  71. /undef /upath /userdict /ustroke /viewclip
  72. /viewclippath /where /widthshow /write /writehexstring
  73. /writeobject /writestring /wtranslation /xor /xshow
  74. /xyshow /yshow /FontDirectory /SharedFontDirectory /Courier
  75. % 200
  76. /Courier-Bold /Courier-BoldOblique /Courier-Oblique /Helvetica /Helvetica-Bold
  77. /Helvetica-BoldOblique /Helvetica-Oblique /Symbol /Times-Bold /Times-BoldItalic
  78. /Times-Italic /Times-Roman /execuserobject /currentcolor /currentcolorspace
  79. /currentglobal /execform /filter /findresource /globaldict
  80. % 220
  81. /makepattern /setcolor /setcolorspace /setglobal /setpagedevice
  82. /setpattern
  83. % pad to 256
  84. counttomark 256 exch sub { 0 } repeat
  85. % 256
  86. /= /== /ISOLatin1Encoding /StandardEncoding
  87. % 260
  88. ([) cvn (]) cvn /atan /banddevice /bytesavailable
  89. /cachestatus /closefile /colorimage /condition /copypage
  90. /cos /countdictstack /countexecstack /cshow /currentblackgeneration
  91. /currentcacheparams /currentcolorscreen /currentcolortransfer /currentcontext /currentflat
  92. % 280
  93. /currenthalftone /currenthalftonephase /currentmiterlimit /currentobjectformat /currentpacking
  94. /currentscreen /currentstrokeadjust /currenttransfer /currentundercolorremoval /defaultmatrix
  95. /definefont /deletefile /detach /deviceinfo /dictstack
  96. /echo /erasepage /errordict /execstack /executeonly
  97. % 300
  98. /exp /false /filenameforall /fileposition /fork
  99. /framedevice /grestoreall /handleerror /initclip /initgraphics
  100. /initmatrix /instroke /inustroke /join /kshow
  101. /ln /lock /log /mark /monitor
  102. % 320
  103. /noaccess /notify /nulldevice /packedarray /quit
  104. /rand /rcheck /readonly /realtime /renamefile
  105. /renderbands /resetfile /reversepath /rootfont /rrand
  106. /run /scheck /setblackgeneration /setcachelimit /setcacheparams
  107. % 340
  108. /setcolorscreen /setcolortransfer /setfileposition /setflat /sethalftone
  109. /sethalftonephase /setmiterlimit /setobjectformat /setpacking /setscreen
  110. /setstrokeadjust /settransfer /setucacheparams /setundercolorremoval /sin
  111. /sqrt /srand /stack /status /statusdict
  112. % 360
  113. /true /ucachestatus /undefinefont /usertime /ustrokepath
  114. /version /vmreclaim /vmstatus /wait /wcheck
  115. /xcheck /yield /defineuserobject /undefineuserobject /UserObjects
  116. /cleardictstack
  117. % 376
  118. /A /B /C /D /E /F /G /H /I /J /K /L /M
  119. /N /O /P /Q /R /S /T /U /V /W /X /Y /Z
  120. /a /b /c /d /e /f /g /h /i /j /k /l /m
  121. /n /o /p /q /r /s /t /u /v /w /x /y /z
  122. % 428
  123. /setvmthreshold (<<) cvn
  124. (>>) cvn /currentcolorrendering /currentdevparams /currentoverprint /currentpagedevice
  125. /currentsystemparams /currentuserparams /defineresource /findencoding /gcheck
  126. % 440
  127. /glyphshow /languagelevel /product /pstack /resourceforall
  128. /resourcestatus /revision /serialnumber /setcolorrendering /setdevparams
  129. /setoverprint /setsystemparams /setuserparams /startjob /undefineresource
  130. /GlobalFontDirectory /ASCII85Decode /ASCII85Encode /ASCIIHexDecode /ASCIIHexEncode
  131. % 460
  132. /CCITTFaxDecode /CCITTFaxEncode /DCTDecode /DCTEncode /LZWDecode
  133. /LZWEncode /NullEncode /RunLengthDecode /RunLengthEncode /SubFileDecode
  134. /CIEBasedA /CIEBasedABC /DeviceCMYK /DeviceGray /DeviceRGB
  135. /Indexed /Pattern /Separation /CIEBasedDEF /CIEBasedDEFG
  136. % 480
  137. /DeviceN
  138. % 481 -- end
  139. //.packtomark exec .installsystemnames
  140. % Define printobject and writeobject.
  141. % These are mostly implemented in PostScript, so that we don't have to
  142. % worry about interrupts or callbacks when writing to the output file.
  143. % Define procedures for accumulating the space required to represent
  144. % an object in binary form.
  145. % <#refs> <#chars> <obj> -proc- <#refs'> <#chars'>
  146. /cntdict mark
  147. /integertype /pop load
  148. /realtype 1 index
  149. /marktype 1 index
  150. /nulltype 1 index
  151. /booleantype 1 index
  152. /nametype { length add } .forcebind
  153. /stringtype 1 index
  154. /arraytype 0 % replaced below
  155. /dicttype 0 % replaced below
  156. .dicttomark def
  157. /.cntobj {
  158. dup type //cntdict exch get exec
  159. } .forcebind def
  160. cntdict /arraytype {
  161. dup length % #refs #chars array len
  162. 4 -1 roll add % #chars array #refs+len
  163. dup 65536 gt {
  164. /writeobject .systemvar /limitcheck signalerror
  165. } if
  166. 3 1 roll % #refs+len #chars array
  167. //.cntobj forall
  168. } .forcebind put % replace arraytype in cntdict
  169. cntdict /dicttype {
  170. /writeobject .systemvar /typecheck signalerror
  171. } .internalbind put
  172. /.bosheader { % <top_length> <total_length> <string8> .bosheader
  173. % <string4|8>
  174. dup 0 currentobjectformat 127 add put % object format => BOS tag
  175. 2 index 255 le 2 index 65531 le and {
  176. % Use the short header format: tag toplen(1) totlen(2)
  177. exch 4 add exch
  178. 0 4 getinterval
  179. dup 1 5 -1 roll put
  180. } {
  181. % Use the long header format: tag 0(1) toplen(2) totlen(4)
  182. exch 8 add exch
  183. 0 0 4 2 roll .bosobject exch pop exch pop % store with byte swapping
  184. } ifelse % Stack: shortlen str
  185. exch dup -8 bitshift exch 255 and % str hibyte lobyte
  186. currentobjectformat 1 and 0 eq { % lsb first
  187. exch
  188. } if
  189. 2 index 3 3 -1 roll put
  190. 1 index 2 3 -1 roll put
  191. } .forcebind def
  192. /.writeobjects { % <file> <tag> <array> .writeobjects -
  193. % Apply the tag early and forget about it.
  194. (12345678) dup 1 5 -1 roll % file array (...) (...) 1 tag
  195. put exch % file (.t.) array
  196. % Calculate the space required for refs and strings.
  197. % Reject excessively large graphs or graphs with loops.
  198. 0 0 % file (.t.) array #refs #chars
  199. 2 index //.cntobj exec % file (.t.) array #refs #chars
  200. % Write the header.
  201. 1 index 8 mul add % file (.t.) array #refs #refs*8+#chars
  202. 2 index length exch (12345678) % file (.t.) array #refs len(array) #refs*8+#chars (...)
  203. //.bosheader exec % file (.t.) array #refs (...)
  204. 4 index exch writestring % file (.t.) array #refs
  205. % Traverse an array tree in width-first order and place all the
  206. % arrays that are found on the operand stack. Acyclic graphs are
  207. % expanded to trees. The top parameter K indicates the number
  208. % of arrays on a given depth level. At the root level, K is equal to 1.
  209. mark 2 index 1 % file (.t.) array #refs -mark- array K
  210. { dup 0 le { pop exit } if
  211. dup {
  212. dup index {
  213. dup type /arraytype eq {
  214. exch 1 add
  215. } {
  216. pop
  217. } ifelse
  218. } forall
  219. 1 sub
  220. } repeat
  221. } loop % file (.t.) array #refs -mark- array1 ... arrayN
  222. counttomark 5 add -4 roll % -mark- array1 ... arrayN file (.t.) array #refs
  223. % Write the content of the root array
  224. 8 mul % -mark- array1 ... arrayN file (.t.) array #refs*8
  225. exch dup length 8 mul % -mark- array1 ... arrayN file (.t.) #refs*8 array len(array)*8
  226. 3 1 roll % -mark- array1 ... arrayN file (.t.) len(array)*8 #refs*8 array
  227. { 3 index % -mark- array1 ... arrayN file (.t.) len(array)*8 #refs*8 obj (.t.)
  228. .bosobject % -mark- array1 ... arrayN file (.t.) len(array)*8 #refs*8 (.t.)
  229. 4 index exch writestring % -mark- array1 ... arrayN file (.t.) len(array)*8 #refs*8
  230. } forall
  231. 3 -1 roll pop % -mark- array1 ... arrayN file len(array)*8 #refs*8
  232. % Write the remaining arrays
  233. counttomark 2 sub -1 3 {
  234. index { % ... file #refs #str obj
  235. (1\000345678) .bosobject % ... file #refs #str (...)
  236. 3 index exch writestring % ... file #refs #str
  237. } forall
  238. } for
  239. pop pop % -mark- array1 ... arrayN file
  240. % Write strings and names.
  241. counttomark 1 sub -1 1 {
  242. index {
  243. dup type /nametype eq {
  244. .namestring
  245. } if
  246. dup type /stringtype eq {
  247. 1 index exch writestring
  248. } {
  249. pop
  250. } ifelse
  251. } forall
  252. } for
  253. cleartomark % Clean up
  254. } .forcebind def
  255. /.writeobject {
  256. 3 copy exch
  257. % We must allocate the array in local VM
  258. % to avoid a possible invalidaccess.
  259. .currentglobal //false .setglobal exch 1 array astore exch .setglobal
  260. //.writeobjects exec pop pop pop
  261. } .forcebind def
  262. /printobject { % <obj> <tag> printobject -
  263. currentobjectformat 0 eq {
  264. /printobject .systemvar /undefined signalerror
  265. } if
  266. (%stdout) (w) file 2 index 2 index //.writeobject exec pop pop
  267. } odef
  268. /writeobject { % <file> <obj> <tag> writeobject -
  269. currentobjectformat 0 eq {
  270. /writeobject .systemvar /undefined signalerror
  271. } if
  272. 2 .argindex pop % check # of args
  273. //.writeobject exec
  274. } odef
  275. % Implement binary error message output.
  276. /.objectprinttest { % <obj> .objectprinttest -
  277. % This is a pseudo-operator so it will restore the stack
  278. % if it gets an error.
  279. mark 0 0 3 .argindex //.cntobj exec cleartomark pop
  280. } .internalbind def
  281. /.printerror {
  282. $error /binary get .languagelevel 2 ge and {
  283. currentobjectformat 0 ne {
  284. [ /Error $error /errorname get $error /command get
  285. % Convert the object with cvs if it isn't printable.
  286. dup { //.objectprinttest exec } //.internalstopped exec {
  287. pop 100 string cvs
  288. } if
  289. //false ] 250 printobject
  290. }
  291. //.printerror % known to be a procedure
  292. ifelse
  293. }
  294. //.printerror % known to be a procedure
  295. ifelse
  296. } .internalbind def
  297. currentdict /cntdict .undef
  298. % End of level2dict
  299. end
  300. .setlanguagelevel
  301. % undefine things defined in this file and not referenced elsewhere
  302. [
  303. /.objectprinttest
  304. /.bosheader
  305. /.cntobj
  306. /.writeobject
  307. /.writeobjects
  308. ] dup level2dict .undefinternalnames
  309. systemdict .undefinternalnames