Preparing to Draw: the PostScript Graphics State

5.3 Preparing to Draw: the PostScript Graphics State

Before you do any drawing with PostScript, you will want to set certain parameters that control how the appearance of the objects you draw, such as line thickness and ink color. Together, these parameters comprise the "graphics state".

PostScript uses the point, 1/72 of an inch, as its default unit. Since you are probably not accustomed to thinking in points, you will want to change this so that a single unit is an inch. (Actually, you probably shouldn't be thinking inches either, but for historical reasons we will let you get away with it.) You should do this with the "scale" command. For example, to change units to inches you would use:
72 72 scale
Remember, arguments before operation!

Lines in PostScript can be described by their thickness, how they look at corners, how they look at ends, and perhaps a dash pattern. The thickness is set by "setlinewidth", whose argument is a number in terms of the current units. A convienient argument is, in fact, 0, which sets the line width to the smallest width the device can draw. A good place to start for lines that have some thickness is:

.025 setlinewidth
2 setlinecap
2 setlinejoin
The "setlinecap" command affects how lines look at the ends, and the "setlinejoin" affects how lines look when they meet at angles. The meaning of these arguments, and some more choices, are listed in the command summary for this section. If you want, you can experiment to find a combination that looks pleasing to you.

You can control the colour of objects that you draw with the "setgray" command. This takes a number between 0 and 1 (1 being white and 0 being black) and uses this as the ink color. If you are working on a color screen or printer, you might also try "setrgbcolor", which takes red, green, and blue values as arguments, again between 0 and 1.


David Maxwell, who is still writing this, would like to hear your comments and suggestions. And remember, parts of this manual are based on P.J. Weingartner's work: A First Guide to PostScript.