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