Ghostscript and the PostScript language

Table of contents

For other information, see the Ghostscript overview.


Ghostscript's capabilities in relation to PostScript

The Ghostscript interpreter, except as noted below, is intended to execute properly any source program written in the (LanguageLevel 3) PostScript language as defined in the PostScript Language Reference, Third Edition (ISBN 0-201-37922-8) published by Addison-Wesley in mid-1999. However, the interpreter is configurable in ways that can restrict it to various subsets of this language. Specifically, the base interpreter accepts the Level 1 subset of the PostScript language, as defined in the first edition of the PostScript Language Reference Manual (ISBN 0-201-10174-2) Addison-Wesley 1985, plus the file system, version 25.0 language, and miscellaneous additions listed in sections A.1.6, A.1.7, and A.1.8 of the Second Edition respectively, including allowing a string operand for the "status" operator. The base interpreter may be configured (see the documentation on building Ghostscript for how to configure it) by adding any combination of the following:

Ghostscript currently does not implement the following PostScript LanguageLevel 3 facilities:

Ghostscript can also interpret files in the Portable Document Format (PDF) 1.3 format defined in the Portable Document Format Reference Manual Version 1.3 of March 11, 1999, distributed by Adobe Systems Incorporated, except as noted below. This facility is available only if the pdf feature was selected when Ghostscript was built.

Ghostscript currently does not implement the following PDF 1.3 facilities:

Ghostscript also includes a number of additional operators defined below that are not in the PostScript language defined by Adobe.


Implementation limits

The implementation limits show here correspond to those in Tables B.1 and B.2 of the Second and Third Editions, which describe the quantities fully. Where Ghostscript's limits are different from those of Adobe's implementations (as shown in the Third Edition), Adobe's limits are also shown.

Architectural limits


Architectural limits (corresponds to Adobe table B.1)
Quantity    Limit    Type    Adobe

integer   32-bit   twos complement integer    
real   single-precision   IEEE float    
array   65535   elements    
dictionary   65534   elements   65535
string   65535   characters    
name   16383   characters   127
filename   128*   characters    
save level   none   (capacity of memory)   15
gsave level   none   (capacity of memory)   13

* The limit on the length of a file name is 128 characters if the name starts with a %...% IODevice designation, or 124 characters if it does not.

Typical memory limits in LanguageLevel 1


Memory limits (corresponds to Adobe table B.2)
Quantity    Limit    Type    Adobe

userdict   200        
FontDirectory   100        
operand stack   800       500
dictionary stack   20    
execution stack   250    
interpreter level   none   (capacity of memory)   10
path   none   (capacity of memory)   1500
dash   11    
VM   none   (capacity of memory)   240000
file   none   (determined by operating system)   6
image   65535   values (samples × components)
for1-, 2-, 4-, or 8-bit samples
  3300
    32767   values for 12-bit samples   3300

Other differences in VM consumption

Packed array elements occupy either 2 bytes or 8 bytes. The average element size is probably about 5 bytes. Names occupy 12 bytes plus the space for the string.


Additional operators in Ghostscript

Graphics and text operators

Transparency

Ghostscript provides a set of operators for implementing the transparency and compositing facilities of PDF 1.4. These are defined only if the transpar option was selected when Ghostscript was built. We do not attempt to explain the underlying graphics model here: for details, see Adobe Technical Note #5407, "Transparency in PDF". Note, however, that Ghostscript's model generalizes that of PDF 1.4 in that Ghostscript maintains separate alpha and mask values for opacity and shape, rather than a single value with a Boolean that says whether it represents opacity or shape. EVERYTHING IN THIS SECTION IS SUBJECT TO CHANGE.

Graphics state operators
<modename> .setblendmode -
Sets the blending mode in the graphics state. If the mode name is not recognized, causes a rangecheck error. The initial value of the blending mode is /Compatible.
- .currentblendmode <modename>
Returns the current blending mode.
<0..1> .setopacityalpha -
Sets the opacity alpha value in the graphics state. The initial opacity alpha value is 1.
- .currentopacityalpha <0..1>
Returns the current opacity alpha value.
<0..1> .setshapealpha -
Sets the shape alpha value in the graphics state. The initial shape alpha value is 1.
- .currentshapealpha <0..1>
Returns the current shape alpha value.
<bool> .settextknockout -
Sets the text knockout flag in the graphics state. The initial value of the text knockout flag is true.
- .currenttextknockout <bool>
Returns the current text knockout flag.
Rendering stack operators

The interpreter state is extended to include a (per-context) rendering stack for handling transparency groups and masks (generically, "layers"). Groups accumulate a full value for each pixel (paint plus transparency); masks accumulate only a coverage value. Layers must be properly nested, i.e., the 'end' or 'discard' operator must match the corresponding 'begin' operator.

Beginning and ending layers must nest properly with respect to save and restore: save and restore do not save and restore the layer stack. Currently, layers are not required to nest with respect to gsave and grestore, except that the device that is current in the graphics state when ending a layer must be the same as the device that was current when beginning the layer. THIS AREA IS SUBJECT TO CHANGE.

<paramdict> <llx> <lly> <urx> <ury> .begintransparencygroup -
Begins a new transparency group. The ll/ur coordinates are the bounding box of the group in the current user coordinate system. paramdict has the following keys:
/Isolated
(optional) Boolean; default value = false.
/Knockout
(optional) Boolean; default value = false.
- .discardtransparencygroup -
Ends and discards the current transparency group.
- .endtransparencygroup -
Ends the current transparency group, compositing the group being ended onto the group that now becomes current.
<paramdict> <llx> <lly> <urx> <ury> .begintransparencymask -
Begins a new transparency mask. The ll/ur coordinates are the bounding box of the mask in the current user coordinate system. paramdict has the following keys:
/Subtype
(required) Name, either /Alpha or /Luminosity.
/Background
(optional) Array of number.
/TransferFunction
(optional) Function object (produced by applying .buildfunction to a Function dictionary).
- .discardtransparencymask -
Ends and discards the current transparency mask.
<masknum> .endtransparencymask -
Ends the current transparency mask, installing it as the current opacity (masknum = 0) or shape (masknum = 1) mask in the graphics state.
<masknum> .inittransparencymask -
Resets the current opacity (masknum = 0) or shape (masknum = 1) mask to an infinite mask with alpha = 1 everywhere.
New ImageType

The transparency extension defines a new ImageType 103, similar to ImageType 3 with the following differences:

Other graphics state operators

<bool> .setaccuratecurves -
Sets a graphics state flag that determines whether curves and arcs, when flattened, always start and end with a line that is a segment of the tangent; this also causes butt and square caps to be properly perpendicular to the tangent. initgraphics sets this flag to false, to match other PostScript implementations.
- .currentaccuratecurves <bool>
Returns the current value of the accurate curves flag.
<int> .setcurvejoin -
Sets a graphics state parameter that determines how to treat the joins between the line segments produced when a curve is flattened. The parameter value may be either -1 or a value acceptable to setlinejoin. If the parameter value is -1, the join used for flattened curve line segments is given by the current line join parameter in the graphics state (except that if the line join value is "none", a bevel join is used), which matches the Adobe Red Book, but not the Adobe implementations; if the curve join parameter value is a line join value, that type of join is used for flattened curve line segments, regardless of the value of the graphics state line join parameter. The initial (and default) value of the curve join parameter is 2, causing bevel joins to be used: this matches the Adobe implementations. initgraphics sets the parameter to its default value.
- .currentcurvejoin <int>
Returns the current value of the curve join parameter.
<bool> .setdashadapt -
Sets a graphics state flag that determines whether dash patterns do (true) or do not (false) automatically scale themselves so that each line segment consists of an integral number of pattern repetitions. initgraphics sets this flag to false.
- .currentdashadapt <bool>
Returns the current value of the dash adaptation flag.
<matrix> .setdefaultmatrix -
Sets the default matrix that is returned by defaultmatrix and installed by initmatrix. Ordinary programs should not use this operator.
<num> <bool> .setdotlength -
Sets a graphics state parameter that determines the handling of zero-length lines (dots). If the dot length is zero, dots are painted as circles if round line caps are in effect, otherwise they are not painted at all. If the dot length is non-zero, dots are treated exactly like lines of the given length: the length is specified in user coordinates (like line width) if bool is false, or in default user coordinates of points (units of 1/72in; see the notes on measurements in the documentation on devices) if bool is true. Dots occurring as part of dash patterns will be oriented correctly; isolated dots will be oriented as though they were part of a vertical line. initgraphics sets the dot length to zero.
- .currentdotlength <num> <bool>
Returns the current dot length and dot length mode.
<dx> <dy> .setfilladjust2 -
Sets graphics state parameters that cause all filled and stroked regions to be "fattened" by the given amount relative to an algorithm that only paints pixels whose centers fall within the region to be painted. dx and dy are numbers between 0 and 0.5, measured in device space. The only two values that are likely to be useful are 0, which gives a pure center-of-pixel rule, and 0.5, which gives Adobe's any-part-of-pixel rule. (0.5 is treated slightly specially in order to create half-open pixels per Adobe's specification.)
- .currentfilladjust2 <dx> <dy>
Returns the current fill adjustment values.
<bool> .setlimitclamp -
Sets a graphics state flag that determines whether attempts to set the current point outside the internally representable range should clamp the value to the largest representable value (true) or give a limitcheck error (false). initgraphics sets this flag to false, to match other PostScript implementations.
- .currentlimitclamp <bool>
Returns the current value of the limit clamp flag.
<int> .setoverprintmode -
Sets the overprint mode in the graphics state. Legal values are 0 or 1. Per the PDF 1.3 specification, if the overprint mode is 1, then when the current color space is DeviceCMYK, color components whose value is 0 do not write into the target, rather than writing a 0 value. THIS BEHAVIOR IS NOT IMPLEMENTED YET. The initial value of the overprint mode is 0.
- .currentoverprintmode <int>
Returns the current overprint mode.

Path operators

- .dashpath -
If there is no current dash pattern, does nothing. Otherwise, does the equivalent of flattenpath and then chops up the path as determined by the dash pattern.
<x> <y> <width> <height> .rectappend -
<numarray> .rectappend -
<numstring> .rectappend -
Appends a rectangle or rectangles to the current path, in the same manner as rectfill, rectclip, etc. Defined only if the dps or level2 option was selected when Ghostscript was built.

Painting operators

Ghostscript supports an experimental extension of the PostScript imaging model to include RasterOp and some related facilities. This extension is available only if the rasterop option was selected when building Ghostscript.

With the RasterOp extension, imaging operations compute a function D = f(D,S,T) in RGB space, where f is an arbitrary 3-input Boolean function, D is the destination (frame buffer or print buffer), S is the source (described below), and T is the texture (the current PostScript color, which may be a pattern). The source and texture depend on the PostScript imaging operation:

The rasterop option adds the following operators:

<int8> .setrasterop -
Sets the RasterOp function in the graphics state. The default function is 252, Source | Texture.
- .currentrasterop <int8>
Returns the current RasterOp function.
<bool> .setsourcetransparent -
Sets source transparency in the graphics state. When source transparency is true, white source pixels prevent storing into the destination, regardless of what the RasterOp function returns. The default source transparency is false.
- .currentsourcetransparent <bool> -
Returns the current source transparency.
<bool> .settexturetransparent -
Sets texture transparency in the graphics state. When texture transparency is true, white texture pixels prevent storing into the destination, regardless of what the RasterOp function returns. The default texture transparency is false.
- .currenttexturetransparent <bool> -
Returns the current texture transparency.

For more information on RasterOp and transparency, please consult chapter 5 of the "PCL 5 Color Technical Reference Manual", Hewlett-Packard Manual Part No. 5961-0635.

Character operators

<string> <bool> .charboxpath -
For each character C in the rendering of <string>, let the bounding box of C in device space be the four user-space points p1x/y, p2x/y, p3x/y, and p4x/y. For each character in order, .charboxpath appends the following to the current path:

This creates a path whose pathbbox is the bbox of the string.

If the CTM is well-behaved (consists only of reflection, scaling, and rotation by multiples of 90 degrees), this too creates a (simpler) path whose pathbbox is the bbox of the string.

<font> <charname|charcode> <charname> <charstring> .type1execchar -
Does all the work for rendering a Type 1 outline. This operator, like setcharwidth and setcachedevice, is valid only in the context of a show operator -- that is, it must only be called from within a BuildChar or BuildGlyph procedure.
<font> <charcode> %Type1BuildChar -
This is not a new operator: rather, it is a name known specially to the interpreter. Whenever the interpreter needs to render a character (during a ...show, stringwidth, or charpath), it looks up the name BuildChar in the font dictionary to find a procedure to run. If it does not find this name, and if the FontType is 1, the interpreter instead uses the value (looked up on the dictionary stack in the usual way) of the name %Type1BuildChar.

The standard definition of %Type1BuildChar is in the initialization file gs_type1.ps. Users should not need to redefine %Type1BuildChar, except perhaps for tracing or debugging.

<font> <charname> %Type1BuildGlyph -
Provides the Type 1 implementation of BuildGlyph.

Other operators

Mathematical operators

<number> arccos <number>
Computes the arc cosine of a number between -1 and 1.
<number> arcsin <number>
Computes the arc sine of a number between -1 and 1.

Dictionary operators

mark <key1> <value1> <key2> <value2> ... .dicttomark <dict>
Creates and returns a dictionary with the given keys and values. This is the same as the PostScript Level 2 >> operator, but is available even in Level 1 configurations.
<dict> <key> <value> .forceput -
Equivalent to put, but works even if dict is not writable, and (if dict is systemdict or the current save level is 0) even if dict is in global VM and key and/or value is in local VM. This operator should be used only initialization code, and only in executeonly procedures: it must not be accessible after initialization.
<dict> <key> .forceundef -
Equivalent to undef, but works even if dict is not writable. This operator should be used only initialization code, and only in executeonly procedures: it must not be accessible after initialization.
<dict> <key> .knownget <value> true
<dict> <key> .knownget false
Combines known and get in the obvious way.
<dict> <integer> .setmaxlength -
Sets the capacity (maxlength) of a dictionary. Causes a dictfull error if the dictionary has more occupied entries than the requested capacity.

String and name operators

<integer> .bytestring <bytestring>
Allocates and returns a bytestring, a special data type that can be larger than the maximum size of a string (64K-1 bytes) and can be used in place of a string with a very few operators.
<name> .namestring <string>
Returns the (read-only) string for a name.
<obj> <pattern> .stringmatch <bool>
Matches obj against a pattern in which '*' matches 0 or more characters and '?' matches any single character. If obj is a string or a name, matches its characters against the pattern; if obj is of any other type, the result is true if the pattern is the single character "*" and false otherwise.
<state> <fromString> <toString> .type1encrypt <newState> <toSubstring>
Encrypts fromString according to the algorithm for Adobe Type 1 fonts, writing the result into toString. toString must be at least as long as fromString, or a rangecheck error occurs. state is the initial state of the encryption algorithm (a 16-bit non-negative integer); newState is the new state of the algorithm.
<state> <fromString> <toString> .type1decrypt <newState> <toSubstring>
Decrypts fromString according to the algorithm for Adobe Type 1 fonts, writing the result into toString. Other specifications are as for type1encrypt.

Relational operators

<number|string> <number|string> max <number|string>
Returns the larger of two numbers or strings.
<number|string> <number|string> min <number|string>
Returns the smaller of two numbers or strings.

File operators

<file> .filename <string> true
<file> .filename false
If the file was opened by the file or .tempfile operator, returns the file name and true; if the file is a filter, returns false.
<file> .fileposition <integer> true
Returns the position of file. Unlike the standard fileposition operator, which causes an error if the file is not positionable, .fileposition works on all files, including filters: for non-positionable files, it returns the total number of bytes read or written since the file was opened.
<string> findlibfile <foundstring> <file> true
<string> findlibfile <string> false
Opens the file of the given name for reading, searching through directories as described in the usage documentation. If the search fails, findlibfile simply pushes false on the stack and returns, rather than causing an error.
<file> <string> .peekstring <substring> <filled_bool>
Reads bytes from a file like readstring, but also leaves the bytes in the file buffer so they will be read again by a subsequent read operation. Currently gives a rangecheck error if string is larger than the file's buffer.
<prefix_string|null> <access_string> .tempfile <string> <file>
Creates and opens a temporary file like the file operator, also returning the file name. There are three cases for the <prefix_string|null> operand:

It is intended that in some future version of Ghostscript, files opened with .tempfile will be closed and deleted automatically when Ghostscript exits; however, this is not currently the case (version 7.01).

<file> <integer> .unread -
Pushes back the last-read character onto the front of the file. If the file is open only for writing, or if the integer argument is not the same as the last character read from the file, causes an ioerror error. May also cause an ioerror if the last operation on the file was not a reading operation. This operator is now deprecated: use .peekstring in new code.

Ghostscript also supports the following IODevice in addition to a subset of those defined in the Adobe documentation: %pipe%command, which opens a pipe on the given command. This is supported only on operating systems that provide popen (primarily Unix systems, and not all of those).

Virtual memory operators

<save> .forgetsave -
Cancels the effect of a save, making it as though the save never happened.

Miscellaneous operators

<obj1> <obj2> ... <objn> <n> .execn ...
This executes obj1 through objn in that order, essentially equivalent to
<obj1> <obj2> ... <objn> <n> array astore {exec} forall

except that it doesn't actually create the array.

<string> getenv <string> true
<string> getenv false
Looks up a name in the shell environment. If the name is found, returns the corresponding value and true; if the name is not found, returns false.
<name> <array> .makeoperator <operator>
Constructs and returns a new operator that is actually the given procedure in disguise. The name is only used for printing. The operator has the executable attribute.

Operators defined in this way do one other thing besides running the procedure: if an error occurs during the execution of the procedure, and there has been no net reduction in operand or dictionary stack depth, the operand or dictionary stack pointer respectively is reset to its position at the beginning of the procedure.

<string> <boolean> .setdebug -
If the Ghostscript interpreter was built with the DEBUG flag set, sets or resets any subset of the debugging flags normally controlled by -Z in the command line. Has no effect otherwise.
- .oserrno <errno>
Returns the error code for the most recent operating system error.
- .oserrorstring <string>
Returns the error string for the most recent operating system error.

Device operators

<device> copydevice <device>
Copies a device. The copy is writable and installable. The copy is created in the current VM (local or global), usually local VM for executing ordinary PostScript files.
<devicename> finddevice <device>
Creates a default instance of a device specified by name. The instance is created in global VM. If finddevice is called more than once with the same device name, it creates the default instance the first time, and returns the same instance thereafter.
<devicename> findprotodevice <device>
Finds the prototype of a device specified by name. A prototype can be used with .getdeviceparams or other parameter-reading operators, but it is read-only and cannot be set with setdevice: it must be copied first.
<device> <x> <y> <width> <max_height> <alpha?> <std_depth|null> <string> .getbitsrect <height> <substring>
Reads a rectangle of rendered bits back from a device. This is only guaranteed to be implemented for image devices (see below). alpha? is 0 for no alpha, -1 for alpha first, 1 for alpha last. std_depth is null for native pixels, number of bits per component for a standard color space.
<index> .getdevice <device>
Returns a device from the set of devices known to the system. The first device, which is the default, is numbered 0. If the index is out of range, causes a rangecheck error. This device is actually a prototype, not a directly usable device, and is marked read-only; it cannot have its parameters changed or be installed as the current device.
<matrix> <width> <height> <palette> makeimagedevice <device>
Makes a new device that accumulates an image in memory. matrix is the initial transformation matrix: it must be orthogonal (that is, [a 0 0 b x y] or [0 a b 0 x y]). palette is a string of 2^N or 3 × 2^N elements, specifying how the 2^N possible pixel values will be interpreted. Each element is interpreted as a gray value, or as RGB values, multiplied by 255. For example, if you want a monochrome image for which 0=white and 1=black, the palette should be <ff 00>; if you want a 3-bit deep image with just the primary colors and their complements (ignoring the fact that 3-bit images are not supported), the palette might be <000000 0000ff 00ff00 00ffff ff0000 ff00ff ffff00 ffffff>. At present, the palette must contain exactly 2, 4, 16, or 256 entries, and must contain an entry for black and an entry for white; if it contains any entries that aren't black, white, or gray, it must contain at least the six primary colors (red, green, blue, and their complements cyan, magenta, and yellow); aside from this, its contents are arbitrary.

Alternatively, palette can be 16, 24, 32, or null (equivalent to 24). These are interpreted as:

Palette     Bits allocated per color

16   5 red, 6 green, 5 blue
24   8 red, 8 green, 8 blue
32   8C, 8M, 8Y, 8K

Note that one can also make an image device (with the same palette as an existing image device) by copying a device using the copydevice operator.

<matrix> <width> <height> <palette> <word?> makewordimagedevice <device>
Makes an image device as described above. word? is a Boolean value indicating whether the data should be stored in a word-oriented format internally. No ordinary PostScript programs should use this operator.
<device> <index> <string> copyscanlines <substring>
Copies one or more scan lines from an image device into a string, starting at a given scan line in the image. The data is in the same format as for the image operator. It is an error if the device is not an image device or if the string is too small to hold at least one complete scan line. Always copies an integral number of scan lines.
<device> setdevice -
Sets the current device to the specified device. Also resets the transformation and clipping path to the initial values for the device. Signals an invalidaccess error if the device is a prototype.
- currentdevice <device>
Gets the current device from the graphics state.
<device> getdeviceprops <mark> <name1> <value1> ... <namen> <valuen>
Gets the properties of a device. See the section on device parameters below for details.
<mark> <name1> <value1> ... <namen> <valuen> <device> putdeviceprops <device>
Sets properties of a device. May cause undefined, typecheck, rangecheck, or limitcheck errors.
- flushpage -
On displays, flushes any buffered output, so that it is guaranteed to show up on the screen; on printers, has no effect.

Filters

Standard filters

In its usual configuration, Ghostscript supports all the standard PostScript LanguageLevel 3 filters, both encoding and decoding, except that it does not currently support:

Ghostscript also supports additional keys in the optional dictionary operands for some filters. For the LZWDecode filter:

InitialCodeLength <integer> (default 8)
An integer between 2 and 11 specifying the initial number of data bits per code. Note that the actual initial code length is 1 greater than this, to allow for the reset and end-of-data code values.
FirstBitLowOrder <boolean> (default false)
If true, codes appear with their low-order bit first.
BlockData <boolean> (default false)
If true, the data is broken into blocks in the manner specified for the GIF file format.

For the CCITTFaxEncode and CCITTFaxDecode filters:

DecodedByteAlign <integer> (default 1)
An integer N with the value 1, 2, 4, 8, or 16, specifying that decoded data scan lines are always a multiple of N bytes. The encoding filter skips data in each scan line from Columns to the next multiple of N bytes; the decoding filter pads each scan line to a multiple of N bytes.

Non-standard filters

In addition to the standard PostScript LanguageLevel 3 filters, Ghostscript supports the following non-standard filters. Many of these filters are used internally to implement standard filters or facilities; they are almost certain to remain, in their present form or a backward-compatible one, in future Ghostscript releases.

<target> /BCPEncode filter <file>
<source> /BCPDecode filter <file>
Create filters that implement the Adobe Binary Communications Protocol. See Adobe documentation for details.
<target> <seed_integer> /eexecEncode filter <file>
Creates a filter for encrypting data into the encrypted format described in the Adobe Type 1 Font Format documentation. The seed_integer must be 55665 for the eexec section of a font, or 4330 for a CharString. Note that for the eexec section of a font, this filter produces binary output and does not include the initial 4 (or lenIV) garbage bytes.
<source> <seed_integer> /eexecDecode filter <file>
<source> <dict> /eexecDecode filter <file>
Creates a filter for decrypting data encrypted as described in the Adobe Type 1 Font Format documentation. The seed_integer must be 55665 or 4330 as described just above. Recognized dictionary keys are:
seed <16-bit integer> (required)
lenIV <non-negative integer> (default=4)
<target> /MD5Encode filter <file>
Creates a filter that produces the 16-byte MD5 digest of the input. Note that no output is produced until the filter is closed.
<source> <hex_boolean> /PFBDecode filter <file>
Creates a filter that decodes data in .PFB format, the usual semi-binary representation for Type 1 font files on IBM PC and compatible systems. If hex_boolean is true, binary packets are converted to hex; if false, binary packets are not converted.
<target> <dict> /PixelDifferenceEncode filter <file>
<source> <dict> /PixelDifferenceDecode filter <file>
Implements the Predictor=2 pixel-differencing option of the LZW filters. Recognized keys are:
Colors <integer> (1 to 4, default=1)
BitsPerComponent <integer> (1, 2, 4, or 8, default=8)
Columns <integer> (>= 0, required)

See the Adobe Portable Document Format Reference Manual for details.

<target> <dict> /PNGPredictorEncode filter <file>
<source> <dict> /PNGPredictorDecode filter <file>
Implements the "filter" algorithms of the Portable Network Graphics (PNG) graphics format. Recognized keys are:

Keys recognized in PNG filter algorithms
Key    Range    Default

Colors <integer>     1 to 16    16
BitsPerComponent <integer>   1, 2, 4, 8, or 16    8
Columns <integer>   >= 0    1
Predictor <integer>   10 to 15    15

The Predictor is the PNG algorithm number + 10 for the Encoding filter; the Decoding filter ignores Predictor. 15 means the encoder attempts to optimize the choice of algorithm. For more details see the PNG specification

http://www.w3.org/TR/WD-png-960128.html
<target> /TBCPEncode filter <file>
<source> /TBCPDecode filter <file>
Create filters that implement the Adobe Tagged Binary Communications Protocol. See Adobe documentation for details.
<target> /zlibEncode filter <file>
<source> /zlibDecode filter <file>
Creates filters that use the data compression method variously known as 'zlib' (the name of a popular library that implements it), 'Deflate' (as in RFC 1951, which is a detailed specification for the method), 'gzip' (the name of a popular compression application that uses it), or 'Flate' (Adobe's name). Note that the PostScript Flate filters are actually a combination of this filter with an optional predictor filter.

Unstable filters

Some versions of Ghostscript may also support other non-standard filters for experimental purposes. The current version includes the following such filters, which are not documented further. No code should assume that these filters will exist in compatible form, or at all, in future versions.

<target/source> <string> ByteTranslateEncode/Decode filter <file>
string must be a string of exactly 256 bytes. Creates a filter that converts each input byte b to string[b]. Note that the Encode and Decode filters operate identically: the client must provide a string for the Decode filter that is the inverse mapping of the string for the Encode filter.
<target/source> <dict> BoundedHuffmanEncode/Decode filter <file>
These filters encode and decode data using Huffman codes. Since these filters aren't used anywhere, we don't document them further, except to note the recognized dictionary keys, which must be set identically for encoding and decoding:
FirstBitLowOrder <bool> (default=false)
MaxCodeLength <int> (default=16)
EndOfData <bool> (default=true)
EncodeZeroRuns <int> (default=256)
Tables <int_array>
<target/source> <dict> BWBlockSortEncode/Decode filter <file>
This filter implements the Burroughs-Wheeler block sorting compression method, which we've heard is also used in the popular bzip2 compression application. See http://sources.redhat.com/bzip2/ for more information. The only recognized dictionary key is:
BlockSize <integer> (default=16384)
<target/source> MoveToFrontEncode/Decode filter <file>
The Encode filter starts by initializing an internal 256-byte array a to the values 0 .. 255. This array will always hold a permutation of these values. Then for each input byte b, the filter outputs the index i such that a[i] = b, and moves that element to the front (element 0) of a, moving elements 0 .. i-1 to positions 1 .. i. The Decode filter inverts this process.

Device parameters

Ghostscript supports the concept of device parameters for all devices, not just page devices. (For non-page devices, these are accessible through getdeviceprops and putdeviceprops, as indicated above.) Here are the currently defined parameters for all devices:
BitsPerPixel <integer> (usually read-only)
Number of bits per pixel.
.HWMargins [<four floats>]
Size of non-imageable regions around the edges of the page, in points (units of 1/72in; see the notes on measurements in the documentation on devices).
HWSize [<integer> <integer>]
X and Y size in pixels.
Name <string> (read-only)
The device name. Currently the same as OutputDevice.
Colors, GrayValues, RedValues, GreenValues, BlueValues, ColorValues (usually read-only)
As for the deviceinfo operator of Display PostScript. Red, Green, Blue, and ColorValues are only defined if Colors > 1.
TextAlphaBits, GraphicsAlphaBits (usually read-only)
The number of bits of anti-aliasing information for text or graphics respectively. Legal values are 1 (no anti-aliasing, the default for most devices), 2, or 4.

In addition, the following are defined per Adobe's documentation for the setpagedevice operator:

Duplex (if supported)
HWResolution
ImagingBBox
Margins
NumCopies (for printers only)
Orientation (if supported)
OutputDevice
PageOffset (write-only)
PageSize
ProcessColorModel (usually read-only)

Some devices may only allow certain values for HWResolution and PageSize. The null device ignores attempts to set PageSize; its size is always [0 0].

For printers these are also defined:

BufferSpace <integer>
Buffer space for band lists, if the bitmap is too big to fit in memory.
MaxBitmap <integer>
Maximum space for a full bitmap in memory.
OutputFile <string>
An empty string means "send to printer directly", otherwise specifies the file name for output; %d is replaced by the page number; on Unix systems %pipe%command writes to a pipe. (|command also writes to a pipe, but is now deprecated.)
OpenOutputFile <boolean>
If true, open the device's output file when the device is opened, rather than waiting until the first page is ready to print.
PageCount <integer> (read-only)
Counts the number of pages printed on the device.

The following parameters are for use only by very specialized applications that separate band construction from band rasterization. Improper use may cause unpredictable errors. In particular, if you only want to allocate more memory for banding, to increase band size and improve performance, use the BufferSpace parameter, not BandBufferSpace.

BandHeight <integer>
The height of bands when banding. 0 means use the largest band height that will fit within the BandBufferSpace (or BufferSpace, if BandBufferSpace is not specified).
BandWidth <integer>
The width of bands in the rasterizing pass, in pixels. 0 means use the actual page width.
BandBufferSpace <integer>
The size of the band buffer in the rasterizing pass, in bytes. 0 means use the same buffer size as for the interpretation pass.

In addition, Ghostscript supports the following parameter for setpagedevice and currentpagedevice that is not a device parameter per se:

ViewerPreProcess <procedure>
Specifies a procedure to be applied to the page device dictionary before any other processing is done. The procedure may not alter the dictionary, but it may return a modified copy. This "hook" is provided for use by viewing programs such as GSview.

User parameters

Ghostscript supports the following non-standard user parameters:
ProcessDSCComment <procedure|null>
If not null, this procedure is called whenever the scanner detects a DSC comment (comment beginning with %% or %!). There are two operands, the file and the comment (minus any terminating EOL), which the procedure must consume.
ProcessComment <procedure|null>
If not null, this procedure is called whenever the scanner detects a comment (or, if ProcessDSCComment is also not null, a comment other than a DSC comment). The operands are the same as for ProcessDSCComment.

Miscellaneous additions

run can take either a string or a file as its argument. In the latter case, it just runs the file, closing it at the end, and trapping errors just as for the string case.

Copyright © 1996, 2000 Aladdin Enterprises. All rights reserved.

This file is part of AFPL Ghostscript. See the Aladdin Free Public License (the "License") for full details of the terms of using, copying, modifying, and redistributing AFPL Ghostscript.

Ghostscript version 7.03, 20 October 2001