gs_btokn.ps 11 KB

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