LanguageLevel 2 added two binary encodings of the language: binary tokens, which can
be mixed with ordinary text, and binary object sequences. Both are introduced by a byte from 128 to 159,
which cannot start a text token. Ordinary .ps files rarely use them,
because they are not safe over 7-bit channels, but a reader must recognise them.
This page follows the PostScript Language Reference, section 3.14.
Binary token types
| Byte | Token | Bytes that follow |
|---|---|---|
| 128–131 | Binary object sequence | See below. 128: high-order byte first, IEEE reals; 129: low-order first, IEEE reals; 130: high-order first, native reals; 131: low-order first, native reals. |
| 132 | 32-bit integer | 4 bytes, high-order first. |
| 133 | 32-bit integer | 4 bytes, low-order first. |
| 134 | 16-bit integer | 2 bytes, high-order first, signed. |
| 135 | 16-bit integer | 2 bytes, low-order first, signed. |
| 136 | 8-bit integer | 1 byte, signed. |
| 137 | Fixed-point number | A representation byte r (see number representations), then the number. |
| 138 | IEEE real | 4 bytes, single precision, high-order first. |
| 139 | IEEE real | 4 bytes, low-order first. |
| 140 | Native real | 4 bytes in the machine’s own format. |
| 141 | Boolean | 1 byte: 0 false, 1 true. |
| 142 | String | 1 byte length n, then n bytes. |
| 143 | Long string | 2 bytes length, high-order first, then the bytes. |
| 144 | Long string | 2 bytes length, low-order first, then the bytes. |
| 145 | Literal system name | 1 byte index into the system name table. |
| 146 | Executable system name | 1 byte index. |
| 147–148 | Reserved | Display PostScript extension (user names); not part of the standard language. |
| 149 | Homogeneous number array | A representation byte, a 2-byte count, then the numbers: see below. |
| 150–159 | Unassigned | A syntaxerror if met. |
Number representations
Used by token 137 and homogeneous number arrays (tables 3.25 and 3.26). The representation byte r; values 48 and 49 (and 176, 177) apply only to homogeneous number arrays:
| r | Numbers are |
|---|---|
| 0–31 | 32-bit fixed point, high-order first, with r bits after the binary point (0: plain integers). |
| 32–47 | 16-bit fixed point, high-order first, with r − 32 fraction bits. |
| 48 | 32-bit IEEE reals, high-order first. |
| 49 | 32-bit native reals. |
| r + 128 | The same, low-order byte first. |
A fixed-point value whose fraction bits are 0 is an integer object; otherwise it becomes a real.
Homogeneous number arrays
Token 149, then the representation byte, then a 2-byte count of numbers (in the
byte order the representation names), then the numbers, all in that representation.
The interpreter reads it as a literal array of numbers. Operators that take long
lists of coordinates, such as ufill and xyshow, also accept
these arrays as strings, an encoded number string.
Binary object sequences
A complete set of objects, usually a whole procedure, in one block that the interpreter can take in without scanning text.
| Offset | Size | Field | Description |
|---|---|---|---|
0 | 1 | token type | 128 to 131: byte order and real format, as above. |
1 | 1 | top-level count | 1 to 255: the number of top-level objects. 0 means an extended header follows. |
2 | 2 | overall length | Normal header: the length of the whole sequence in bytes, header included. |
| Extended header (when byte 1 is 0): | |||
2 | 2 | top-level count | The number of top-level objects. |
4 | 4 | overall length | The length of the whole sequence. |
Then come the top-level objects, 8 bytes each, then the objects of any arrays they hold, then the string and name text they point to. The interpreter executes the top-level objects as if they were a procedure.
| Byte | Field | Description |
|---|---|---|
0 | type | Bits 0–6: the object type (below). Bit 7: executable. |
1 | tag | Must be 0 when a program is read, except that the top-level object of a sequence written by printobject or writeobject carries their one-byte tag here (§3.14.2, §3.14.6). |
2–3 | length | Depends on the type. |
4–7 | value | Depends on the type. |
| Type | Object | length | value |
|---|---|---|---|
| 0 | null | unused | unused |
| 1 | integer | unused | the integer |
| 2 | real | 0 for a real in the sequence’s format; otherwise a scale s, the value being a fixed-point number with s fraction bits | the number |
| 3 | name | A signed 16-bit number: 0, the value is a system name index; −1 (0xFFFF), reserved for Display PostScript; greater than 0, the length of the name text | the index, or the offset of the text from the start of the object list |
| 4 | boolean | unused | 0 false, 1 true |
| 5 | string | the length in bytes | the offset of the text from the start of the object list |
| 6 | immediately evaluated name | as name | as name |
| 9 | array | the number of elements | the offset of the first element’s 8-byte record |
| 10 | mark | unused | unused |
Types 7 and 8 are not used. Offsets are counted from the first byte after the
header. Bit 7 of the type byte makes names executable (moveto rather
than /moveto) and arrays procedures.
Name tables
The system name table is a fixed list in which each index stands
for a common name, so that a frequent name costs one byte (tokens 145 and 146 reach
indexes 0–255; binary object sequences reach all of them). An index with no name is
an undefined error, reported as systemn. The table,
from appendix F of the reference; each row starts at the index in the first column
and continues one by one:
| From | Names |
|---|---|
| 0 | abs add aload anchorsearch and arc arcn arct arcto array |
| 10 | ashow astore awidthshow begin bind bitshift ceiling charpath clear cleartomark |
| 20 | clip clippath closepath concat concatmatrix copy count counttomark currentcmykcolor currentdash |
| 30 | currentdict currentfile currentfont currentgray currentgstate currenthsbcolor currentlinecap currentlinejoin currentlinewidth currentmatrix |
| 40 | currentpoint currentrgbcolor currentshared curveto cvi cvlit cvn cvr cvrs cvs |
| 50 | cvx def defineusername dict div dtransform dup end eoclip eofill |
| 60 | eoviewclip eq exch exec exit file fill findfont flattenpath floor |
| 70 | flush flushfile for forall ge get getinterval grestore gsave gstate |
| 80 | gt identmatrix idiv idtransform if ifelse image imagemask index ineofill |
| 90 | infill initviewclip inueofill inufill invertmatrix itransform known le length lineto |
| 100 | load loop lt makefont matrix maxlength mod moveto mul ne |
| 110 | neg newpath not null or pathbbox pathforall pop print printobject |
| 120 | put putinterval rcurveto read readhexstring readline readstring rectclip rectfill rectstroke |
| 130 | rectviewclip repeat restore rlineto rmoveto roll rotate round save scale |
| 140 | scalefont search selectfont setbbox setcachedevice setcachedevice2 setcharwidth setcmykcolor setdash setfont |
| 150 | setgray setgstate sethsbcolor setlinecap setlinejoin setlinewidth setmatrix setrgbcolor setshared shareddict |
| 160 | show showpage stop stopped store string stringwidth stroke strokepath sub |
| 170 | systemdict token transform translate truncate type uappend ucache ueofill ufill |
| 180 | undef upath userdict ustroke viewclip viewclippath where widthshow write writehexstring |
| 190 | writeobject writestring wtranslation xor xshow xyshow yshow FontDirectory SharedFontDirectory Courier |
| 200 | Courier-Bold Courier-BoldOblique Courier-Oblique Helvetica Helvetica-Bold Helvetica-BoldOblique Helvetica-Oblique Symbol Times-Bold Times-BoldItalic |
| 210 | Times-Italic Times-Roman execuserobject currentcolor currentcolorspace currentglobal execform filter findresource globaldict |
| 220 | makepattern setcolor setcolorspace setglobal setpagedevice setpattern (226–255 unassigned) |
| 256 | = == ISOLatin1Encoding StandardEncoding [ ] atan banddevice bytesavailable cachestatus |
| 266 | closefile colorimage condition copypage cos countdictstack countexecstack cshow currentblackgeneration currentcacheparams |
| 276 | currentcolorscreen currentcolortransfer currentcontext currentflat currenthalftone currenthalftonephase currentmiterlimit currentobjectformat currentpacking currentscreen |
| 286 | currentstrokeadjust currenttransfer currentundercolorremoval defaultmatrix definefont deletefile detach deviceinfo dictstack echo |
| 296 | erasepage errordict execstack executeonly exp false filenameforall fileposition fork framedevice |
| 306 | grestoreall handleerror initclip initgraphics initmatrix instroke inustroke join kshow ln |
| 316 | lock log mark monitor noaccess notify nulldevice packedarray quit rand |
| 326 | rcheck readonly realtime renamefile renderbands resetfile reversepath rootfont rrand run |
| 336 | scheck setblackgeneration setcachelimit setcacheparams setcolorscreen setcolortransfer setfileposition setflat sethalftone sethalftonephase |
| 346 | setmiterlimit setobjectformat setpacking setscreen setstrokeadjust settransfer setucacheparams setundercolorremoval sin sqrt |
| 356 | srand stack status statusdict true ucachestatus undefinefont usertime ustrokepath version |
| 366 | vmreclaim vmstatus wait wcheck xcheck yield defineuserobject undefineuserobject UserObjects cleardictstack |
| 376 | A to Z (376–401), then a to z (402–427) |
| 428 | setvmthreshold << >> currentcolorrendering currentdevparams currentoverprint currentpagedevice currentsystemparams currentuserparams defineresource |
| 438 | findencoding gcheck glyphshow languagelevel product pstack resourceforall resourcestatus revision serialnumber |
| 448 | setcolorrendering setdevparams setoverprint setsystemparams setuserparams startjob undefineresource GlobalFontDirectory ASCII85Decode ASCII85Encode |
| 458 | ASCIIHexDecode ASCIIHexEncode CCITTFaxDecode CCITTFaxEncode DCTDecode DCTEncode LZWDecode LZWEncode NullEncode RunLengthDecode |
| 468 | RunLengthEncode SubFileDecode CIEBasedA CIEBasedABC DeviceCMYK DeviceGray DeviceRGB Indexed Pattern Separation |
| 478 | CIEBasedDEF CIEBasedDEFG DeviceN |
Some entries name Display PostScript operators (viewclip,
fork, yield and others) that ordinary interpreters lack.
Sources
- Adobe, PostScript Language Reference, third edition (1999) – §3.14 and tables 3.25, 3.26 and 3.27 (binary tokens, number representations, object sequences), appendix F (system name encodings)