1 % Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
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.
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.
16 % $Id: gs_btokn.ps,v 1.9 2002/04/19 06:52:25 lpd Exp $
17 % Initialization file for binary tokens.
18 % When this is run, systemdict is still writable,
19 % but everything defined here goes into level2dict.
21 % Define whether or not to allow writing dictionaries.
22 % This is a non-standard feature!
25 languagelevel 1 .setlanguagelevel
28 % Initialization for the system name table.
32 /abs /add /aload /anchorsearch /and
33 /arc /arcn /arct /arcto /array
34 /ashow /astore /awidthshow /begin /bind
35 /bitshift /ceiling /charpath /clear /cleartomark
37 /clip /clippath /closepath /concat /concatmatrix
38 /copy /count /counttomark /currentcmykcolor /currentdash
39 /currentdict /currentfile /currentfont /currentgray /currentgstate
40 /currenthsbcolor /currentlinecap /currentlinejoin /currentlinewidth /currentmatrix
42 /currentpoint /currentrgbcolor /currentshared /curveto /cvi
43 /cvlit /cvn /cvr /cvrs /cvs
44 /cvx /def /defineusername /dict /div
45 /dtransform /dup /end /eoclip /eofill
47 /eoviewclip /eq /exch /exec /exit
48 /file /fill /findfont /flattenpath /floor
49 /flush /flushfile /for /forall /ge
50 /get /getinterval /grestore /gsave /gstate
52 /gt /identmatrix /idiv /idtransform /if
53 /ifelse /image /imagemask /index /ineofill
54 /infill /initviewclip /inueofill /inufill /invertmatrix
55 /itransform /known /le /length /lineto
57 /load /loop /lt /makefont /matrix
58 /maxlength /mod /moveto /mul /ne
59 /neg /newpath /not /null /or
60 /pathbbox /pathforall /pop /print /printobject
62 /put /putinterval /rcurveto /read /readhexstring
63 /readline /readstring /rectclip /rectfill /rectstroke
64 /rectviewclip /repeat /restore /rlineto /rmoveto
65 /roll /rotate /round /save /scale
67 /scalefont /search /selectfont /setbbox /setcachedevice
68 /setcachedevice2 /setcharwidth /setcmykcolor /setdash /setfont
69 /setgray /setgstate /sethsbcolor /setlinecap /setlinejoin
70 /setlinewidth /setmatrix /setrgbcolor /setshared /shareddict
72 /show /showpage /stop /stopped /store
73 /string /stringwidth /stroke /strokepath /sub
74 /systemdict /token /transform /translate /truncate
75 /type /uappend /ucache /ueofill /ufill
77 /undef /upath /userdict /ustroke /viewclip
78 /viewclippath /where /widthshow /write /writehexstring
79 /writeobject /writestring /wtranslation /xor /xshow
80 /xyshow /yshow /FontDirectory /SharedFontDirectory /Courier
82 /Courier-Bold /Courier-BoldOblique /Courier-Oblique /Helvetica /Helvetica-Bold
83 /Helvetica-BoldOblique /Helvetica-Oblique /Symbol /Times-Bold /Times-BoldItalic
84 /Times-Italic /Times-Roman /execuserobject /currentcolor /currentcolorspace
85 /currentglobal /execform /filter /findresource /globaldict
87 /makepattern /setcolor /setcolorspace /setglobal /setpagedevice
90 counttomark 256 exch sub { 0 } repeat
92 /= /== /ISOLatin1Encoding /StandardEncoding
94 ([) cvn (]) cvn /atan /banddevice /bytesavailable
95 /cachestatus /closefile /colorimage /condition /copypage
96 /cos /countdictstack /countexecstack /cshow /currentblackgeneration
97 /currentcacheparams /currentcolorscreen /currentcolortransfer /currentcontext /currentflat
99 /currenthalftone /currenthalftonephase /currentmiterlimit /currentobjectformat /currentpacking
100 /currentscreen /currentstrokeadjust /currenttransfer /currentundercolorremoval /defaultmatrix
101 /definefont /deletefile /detach /deviceinfo /dictstack
102 /echo /erasepage /errordict /execstack /executeonly
104 /exp /false /filenameforall /fileposition /fork
105 /framedevice /grestoreall /handleerror /initclip /initgraphics
106 /initmatrix /instroke /inustroke /join /kshow
107 /ln /lock /log /mark /monitor
109 /noaccess /notify /nulldevice /packedarray /quit
110 /rand /rcheck /readonly /realtime /renamefile
111 /renderbands /resetfile /reversepath /rootfont /rrand
112 /run /scheck /setblackgeneration /setcachelimit /setcacheparams
114 /setcolorscreen /setcolortransfer /setfileposition /setflat /sethalftone
115 /sethalftonephase /setmiterlimit /setobjectformat /setpacking /setscreen
116 /setstrokeadjust /settransfer /setucacheparams /setundercolorremoval /sin
117 /sqrt /srand /stack /status /statusdict
119 /true /ucachestatus /undefinefont /usertime /ustrokepath
120 /version /vmreclaim /vmstatus /wait /wcheck
121 /xcheck /yield /defineuserobject /undefineuserobject /UserObjects
124 /A /B /C /D /E /F /G /H /I /J /K /L /M
125 /N /O /P /Q /R /S /T /U /V /W /X /Y /Z
126 /a /b /c /d /e /f /g /h /i /j /k /l /m
127 /n /o /p /q /r /s /t /u /v /w /x /y /z
129 /setvmthreshold (<<) cvn
130 (>>) cvn /currentcolorrendering /currentdevparams /currentoverprint /currentpagedevice
131 /currentsystemparams /currentuserparams /defineresource /findencoding /gcheck
133 /glyphshow /languagelevel /product /pstack /resourceforall
134 /resourcestatus /revision /serialnumber /setcolorrendering /setdevparams
135 /setoverprint /setsystemparams /setuserparams /startjob /undefineresource
136 /GlobalFontDirectory /ASCII85Decode /ASCII85Encode /ASCIIHexDecode /ASCIIHexEncode
138 /CCITTFaxDecode /CCITTFaxEncode /DCTDecode /DCTEncode /LZWDecode
139 /LZWEncode /NullEncode /RunLengthDecode /RunLengthEncode /SubFileDecode
140 /CIEBasedA /CIEBasedABC /DeviceCMYK /DeviceGray /DeviceRGB
141 /Indexed /Pattern /Separation /CIEBasedDEF /CIEBasedDEFG
145 .packtomark .installsystemnames
147 % Define printobject and writeobject.
148 % These are mostly implemented in PostScript, so that we don't have to
149 % worry about interrupts or callbacks when writing to the output file.
151 % Define procedures for accumulating the space required to represent
152 % an object in binary form. The procedures for composite objects (arrays
153 % and dictionaries) leave different results on the stack:
154 % <#refs> <#chars> <simple_obj> -proc- <#refs> <#chars>
155 % <#refs> <#chars> <array|dict> -proc- <array|dict> <#refs> <#chars>
156 % This is required so that .writeobjects can also accumulate the actual
157 % list of composite objects to write in the binary object sequence.
159 /integertype /pop load
164 /nametype { length add } bind
169 /.cntobj { % <<arguments and results as for procedures in cntdict>>
170 dup type //cntdict exch get exec
173 dup dup length 5 -1 roll add 4 2 roll { .cntobj } forall
177 dup dup length 2 mul 5 -1 roll add 4 2 roll {
178 % We have to use .execn here, rather than simply rolling the
179 % value under the top elements, because key might involve arrays
181 cvlit {.cntobj} exch 2 .execn .cntobj
184 /writeobject load /typecheck signalerror
189 /nametype { 2 copy .writecvs pop } bind
193 /.bosheader { % <top_length> <total_length> <string8> .bosheader
195 dup 0 currentobjectformat 127 add put % object format => BOS tag
196 2 index 255 le 2 index 65531 le and {
197 % Use the short header format: tag toplen(1) totlen(2)
202 % Use the long header format: tag 0(1) toplen(2) totlen(4)
204 0 0 4 2 roll .bosobject exch pop exch pop % store with byte swapping
205 } ifelse % Stack: shortlen str
206 exch dup -8 bitshift exch 255 and % str hibyte lobyte
207 currentobjectformat 1 and 0 eq { % lsb first
210 2 index 3 3 -1 roll put
211 1 index 2 3 -1 roll put
214 /.writeobjects { % <file> <tag> <array> .writeobjects -
217 % Count the space required for refs and strings.
219 dup length 0 3 -1 roll
220 % Stack: file tag -mark- #refs #chars array
221 dup 4 1 roll { .cntobj } forall
225 % Stack: file tag -mark- array1 ... (array|dict)N #refs #chars
226 counttomark 3 add -2 roll 4 1 roll
227 % Stack: -mark- array1 ... (array|dict)N tag #refs #chars file
228 dup counttomark 1 sub index length
229 4 index 3 bitshift 4 index add
230 (xxxxxxxx) .bosheader writestring
232 % Write the objects per se.
235 counttomark 1 sub index length 3 bitshift exch
237 % Stack: -mark- array1 ... (array|dict)N tag file ref# char#
239 counttomark -1 roll dup 6 1 roll
240 % Stack: ... objN tag file ref# char# objN
241 dup type /dicttype eq { % can't be first object
242 { 5 1 roll (x\000xxxxxx) .bosobject
243 3 index exch writestring
244 4 -1 roll (x\000xxxxxx) .bosobject
245 3 index exch writestring
248 { (xxxxxxxx) .bosobject
250 3 index exch writestring
251 4 -1 roll pop 0 4 1 roll % clear tag
256 % Write the strings and names.
259 % Stack: -mark- array1 ... array|dictN file
261 counttomark -1 roll {
262 % The counting pass ensured that the keys and values
263 % of any dictionary must be writable objects.
264 % Hence, we are processing a dictionary iff
265 % the next-to-top stack element is not a file.
266 1 index type /filetype ne {
267 exch 2 index exch dup type //w2dict exch .knownget
268 { exec } { pop } ifelse pop
270 dup type //w2dict exch .knownget { exec } { pop } ifelse
281 /printobject { % <obj> <tag> printobject -
282 (%stdout) (w) file 2 index 2 index writeobject pop pop
284 /writeobject { % <file> <obj> <tag> writeobject -
286 % We must allocate the array in local VM
287 % to avoid a possible invalidaccess.
288 .currentglobal false .setglobal exch 1 array astore exch .setglobal
289 .writeobjects pop pop pop
292 % Implement binary error message output.
293 /.objectprinttest { % <obj> .objectprinttest -
294 % This is a pseudo-operator so it will restore the stack
295 % if it gets an error.
296 mark 0 0 3 index .cntobj cleartomark pop
299 $error /binary get .languagelevel 2 ge and {
300 currentobjectformat 0 ne {
301 [ /Error $error /errorname get $error /command get
302 % Convert the object with cvs if it isn't printable.
303 dup { .objectprinttest } .internalstopped {
306 false ] 250 printobject
308 //.printerror % known to be a procedure
311 //.printerror % known to be a procedure
315 currentdict /cntdict .undef
316 currentdict /w2dict .undef