logo_90
Uni ZH | Informatikdienste | PostScript

The Dictionary

PostScript offers the usual elements of a higher programming language, as data types (simple variables, arrays, strings) and control facilities (conditions, loops, procedures). Furthermore, PostScript supports associative tables, named dictionaries, allowing clear and error-free programming.

A dictionary is a table whose elements are pairs of PostScript objects (number, string, name, operator, ...). We call the first element of a pair the 'key' and the second element the 'value'. The language includes operators inserting a key-value pair into a dictionary, operators looking up a key and fetching the associated value, and so on. For instance, put, get, load belong to these operators:

put
associate a key with a value in the dictionary
get
get a value associated with a key in the dictionary. Example: mydict /Max get
load
search dictionary stack for a key and return the associated value
length
number of key-value pairs in the dictionary
dict
create new dictionary
Usually, a key is the name of a variable or a procedure, for instance Max or rectangle, while the value consists of a number or a procedure body. However, a font dictionary associates the names of the characters with the procedures for drawing those character shapes.

When the interpreter seeks to execute a name object, it first searches the current dictionary for the key. If the key isn't there, the interpreter searches the next lower dictionary on the dictionary stack. This continues until either it finds the key or it exhausts the dictionary stack. In the last case the interpreter issues an undefined error message.

Special dictionaries are systemdict, userdict, statusdict, and errordict. The systemdict dictionary is always the bottommost dictionary on the dictionary stack; it associates the names of all PostScript operators with their values (implementations).

When for instance you call the quit operator in systemdict the printer is restarted without the need of manually powering it off and on again.

	%!File: Reset.ps
	systemdict begin quit
The begin operator pushes a dictionary onto the dictionary stack.

The statusdict dictionary is the repository for machine- and configuration-dependent operators and values in most implementations of the PostScript interpreter, for instance setdostartpage, setpapertray (Level 1).

PostScript experts characterize the understanding of the dictionary philosophy as 'the royal road to PostScript mastery'.

Using dictionaries

This allows redefinition of any PostScript operator by using the user dictionary or your own dictionary. Example:
 
% userdict:
/showpage { } def      % dummying
   ...
If no dictionary is specified the interpreter puts the definitions into userdict.
% your own dictionary:
/mydict 11 dict def
mydict begin
   /bd { bind def } bind def
   ...
end
mydict /Max get   
In order to build your own font you have to use a font dictionary:
 
% font dictionary:
/ExampleFont 12 dict def
ExampleFont begin
   /FontType 3 def     % your own font
   ...
   CharacterDefs ...   % definitions of types
   /BuildChar
    { ... } def        % mandatory
end
The error handling may also be redefined:
 
% errordict:
errordict begin
   /handleerror
    { ... } def
end
In the real world, not only is error handling redefined but also operators such as copypage and erasepage.

PostScript Level 2

PostScript Level 2 kennt besondere Dictionaries:

Adobe Systems bezeichnet diese Dictionaries manchmal als Ressourcen, die entweder direkt in einem PostScript-Programm enthalten oder aber in separaten Files abgelegt sind.

Ein Dictionary ist durch die neue Syntax "<< ... >>" oder durch die Operatoren begin--end gekennzeichnet. Die Konstruktion "<<...>>" ist praktisch die einzige Syntax, die exklusiv auf Level 2 unterstützt ist.


Uni ZH | Informatikdienste | PostScript
Optimized for Lynx Last update: Tuesday, 02-Apr-2002 09:38:31 CEST by vo