File: language.doc

package info (click to toggle)
gs 3.33-7
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 7,436 kB
  • ctags: 15,511
  • sloc: ansic: 92,150; asm: 684; sh: 486; makefile: 91
file content (460 lines) | stat: -rw-r--r-- 17,392 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
   Copyright (C) 1989, 1995 Aladdin Enterprises.  All rights reserved.
  
  This file is part of GNU Ghostscript.
  
  GNU Ghostscript is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility to
  anyone for the consequences of using it or for whether it serves any
  particular purpose or works at all, unless he says so in writing.  Refer
  to the GNU Ghostscript General Public License for full details.
  

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This file, language.doc, describes the relationship between the
Ghostscript interpreter and the PostScript language.  This file describes
version 3.33 of Ghostscript.

For an overview of Ghostscript and a list of the documentation files, see
README.

The Ghostscript interpreter, except as noted below, is intended to execute
properly any source program written in the (Level 2) PostScript language as
defined in the December 1990 printing of the PostScript Language Reference
Manual (Second Edition) published by Addison-Wesley (ISBN 0-201-18127-4).
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
by adding any combination of the following:

	- The ability to process PostScript Type 1 fonts.  This facility is
normally included in the interpreter.

	- The CMYK color extensions listed in section A.1.4 of the Second
Edition (including colorimage).  These facilities are only available if the
color, dps, or level2 feature was selected at the time that Ghostscript was
compiled and linked.

	- The Display PostScript extensions listed in section A.1.3
of the Second Edition, but excluding the operators listed in section
A.1.2.  These facilities are only available if the dps feature or the
level2 feature was selected at the time that Ghostscript was compiled
and linked.

	- The composite font extensions listed in section A.1.5 of the
Second Edition, and the ability to handle Type 0 fonts.  These facilities
are only available if the compfont feature or the level2 feature was
selected at the time that Ghostscript was compiled and linked.

	- The PostScript Level 2 "filter" facilities aside from DCTEncode
and DCTDecode filters.  These facilities are only available if the filter,
dps, or level2 feature was selected at the time that Ghostscript was
compiled and linked.

	- The PostScript Level 2 DCTEncode and DCTDecode filters.  These
facilities are only available if the dct or level2 feature was selected at
the time that Ghostscript was compiled and linked.

	- All the other PostScript Level 2 operators and facilities listed
in section A.1.1 of the Second Edition and not listed in any of the other
A.1.n sections.  These facilities are only available if the level2 feature
was selected at the time that Ghostscript was compiled and linked.

Adding all of these produces a full Level 2 PostScript language
interpreter.

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

Implementation limits
=====================

The following implementation limits correspond to those in Table B.1 and
B.2 of the Second Edition.  Those marked with * are different from the ones
in the Second Edition.

Architectural limits
--------------------

integer		32-bit two's complement integer
real		single-precision IEEE float
*array
	On 16-bit systems:	8191 elements
	On 32-bit systems:	65535 elements
*dictionary
	On 16-bit systems:	8190 elements
	On 32-bit systems:	65534 elements
*string		65535 characters
*name		16383 characters
filename	100 characters
*save level	none (capacity of memory)
*gsave level	none (capacity of memory)

Typical memory limits in Level 1
--------------------------------

userdict		200
FontDirectory		100
*operand stack		800
dictionary stack	20
execution stack		250
*interpreter level	none (capacity of memory)
*path			none (capacity of memory)
dash			11
*VM			capacity of memory
*file			determined by operating system
*image			65535 values (samples x components) for 1, 2, 4,
			  or 8-bit samples; 32767 values for 12-bit samples

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.

Ghostscript-specific additions
==============================

Miscellaneous
-------------

^D and ^Z are self-delimiting tokens, like [ and ].  They are initially
defined as empty procedures so that they will be ignored in the input
stream.

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.

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.

String operators
----------------

	<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
--------------

	<string> findlibfile <foundstring> <file> true
	<string> findlibfile <string> false
		Opens the file of the given name for reading, searching
		  through directories as described in use.doc.  If the
		  search fails, findlibfile simply pushes false on the
		  stack and returns, rather than causing an error.

	<file> <integer> unread -
	 	Pushes back the last-read character onto the front of the
		  file.  If the file is only open 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.

	<file> <device> writeppmfile -
		Writes the contents of the device, which must be an image
		  device, onto the file, in Portable PixMap (ppm) format.
		  Does not close the file.

Path operators
--------------

	<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.  Only
		  defined if the dps option is selected.

Filters
-------

Ghostscript supports all the standard PostScript Level 2 filters.  In
addition, Ghostscript supports the following non-standard filters:

	<target> <seed_integer> /eexecEncode filter <file>
		Creates a filter for encrypting data into the
		  eexec encrypted format described in the
		  Adobe Type 1 Font Format documentation.  The
		  seed_integer must be 55665 for proper operation.
		  This filter produces binary output and does not
		  include the initial 4 garbage bytes.

	<source> <seed_integer> /eexecDecode filter <file>
		Creates a filter for decrypting data that has been
		  encrypted using eexec encryption as described in the
		  Adobe Type 1 Font Format documentation.  The
		  seed_integer must be 55665 for proper operation.

	<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.

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

	<target/source> <string> ByteTranslateEncode/Decode
	<target> <int> BigStringEncode
	<target/source> BCPEncode/Decode
	<target/source> TBCPEncode/Decode
	<target/source> <dict> BoundedHuffmanEncode/Decode
		FirstBitLowOrder <bool> false
		MaxCodeLength <int> 16
		EndOfData <bool> true
		EncodeZeroRuns <int> 256
		Tables <int_array>
	<target/source> <dict> BWBlockSortEncode/Decode
		BlockSize <int> 16384
	<target/source> MoveToFrontEncode/Decode

Ghostscript also supports a non-standard optional dictionary operand for
the LZWDecode filter, with the following keys (all optional):

	InitialCodeLength <integer>
		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.
Default value: 8.

	FirstBitLowOrder <boolean>
		If true, codes appear with their low-order bit first.
Default value: false.

	BlockData <boolean>
		If true, the data is broken into blocks in the manner
specified for the GIF file format.  Default value: false.

	EarlyChange <integer>
		If 0, codes become one bit longer one code earlier than
they need to; if 1, codes become one bit longer as specified in the
PostScript Language Reference Manual.  Default value: 1.

Virtual memory operators
------------------------

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

Miscellaneous operators
-----------------------

	- currenttime <number>
		Returns the current value of a continuously-running timer,
		  in minutes.  The initial value of this timer is undefined.

	<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.

	<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 OS error.

	- .oserror <string>
		Returns the error string for the most recent OS error.

Device operators
----------------

	<device> copydevice <device>
		Copies a device.

	<index> .getdevice <device>
		Returns a device from the set of devices known to the
		  system.  The first device, which is default, is numbered
		  0.  If the index is out of range, causes a rangecheck
		  error.

	<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 (i.e., [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 null.  This is interpreted
		  as 24-bit-per-pixel color, where the four bytes of each
		  pixel are respectively R, G, and B.
		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.

	<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.  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.

	- currentdevice <device>
		Gets the current device from the graphics state.

	<device> getdeviceprops <mark> <name1> <value1> ... <namen> <valuen>
		Gets all the properties of a device.  Currently defined
		  names and values for all devices are:
			BitsPerPixel <integer>
				Usually read-only.  Number of bits per pixel.
			.HWMargins [<4 floats>]
				Size of non-imageable regions around edges
				  of page, in 1/72" units.
			HWSize [<integer> <integer>]
				X and Y size in pixels.
			Name <string>
				Read-only.  The device name.
				  Currently, same as OutputDevice.
			Colors, GrayValues, RedValues, GreenValues,
			  BlueValues, ColorValues
				As for the 'deviceinfo' operator of
				  Display PostScript.
		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
			PageSize
			ProcessColorModel
		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].
		Red/Green/Blue/ColorValues are only defined if Colors > 1.
		For printers, the following are also defined:
			BufferSpace <integer>
				Buffer space for band lists, if the bitmap
				  is too big to fit in RAM.
			MaxBitmap <integer>
				Maximum space for a full bitmap in RAM.
			OutputFile <string>
				() means send to printer directly,
				  otherwise specifies the file name for
				  output; a %d is replaced by the page #;
				  on Unix systems, (|command) writes to a pipe
			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.

	<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.

Character operators
-------------------

	<string> .type1addpath -
	<string> <lsbx> <lsby> .type1addpath -
		Adds the description of a character to the current
		  path.  The string argument is a scalable
		  description encoded in Adobe Type 1 format.  This
		  operator, like setcharwidth and setcachedevice, is
		  only valid in the context of a show operator.  It
		  uses information from the current font, in addition
		  to the argument(s).
		The optional lsbx and lsby arguments are left side
		  bearing values that override the ones in the
		  character outline.

	<font> <char> 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 gs_fonts.ps.
		  Users should not need to redefine Type1BuildChar, except
		  perhaps for tracing or debugging.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

PostScript is a trademark of Adobe Systems, Incorporated.