Frames of Reference

5.6 Frames of Reference

All of the drawing commands in PostScript take place in a frame of reference. This frame of reference defines an affine transformation mapping a part of your drawing to the page. That is, you can scale, rotate and translate your frame of reference to make your life easier for your program. The basic sequence of commands are
  • save the graphics state.
  • manipulate the transformation matrix.
  • draw.
  • restore the graphics state.

    We have already seen how to use a scaling transformation with 72 72 scale. This command scales the x and y coordinates respectively by 72. Since PostScript starts with its units in points, and since there are 72 points in an inch, we have effectively converted from points to inches. In general the command is x-scale y-scale scale.

    Translation works similarly; the syntax is x-shift y-shift translate. This command shifts the origin to (x-shift,y-shift ). The origin starts at the lower left of the page, so if the page were 8 1/2 by 11, the command 72 72 scale 4.25 5.5 translate would shift the origin to the centre of the page. Notice here that we combined two transformations - the effect is cumulative. First we scaled so that a unit is an inch, and then we shifted to the centre of the page using the new units.

    The final transfomation is rotation. The rotate command takes a single argument: angle rotate. This rotates the frame of reference counter-clockwise by angle degrees.

    The current transformation is part of the graphics state, so you can save it and restore it using the gsave and grestore commands, just as you have seen with other graphics state variables (like the line width and greylevel).

    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.