Graphics Programs Reference
In-Depth Information
Figure 5-8. Using q and Q operators to isolate color attributes
One of the most frequent uses of
q/Q
pairs is to isolate the effects of
coordinate trans-
forms
. We can use the
cm
operator to change the transformation from
user space
coordinates
to
device space coordinates
. This is known as the
Current Transformation
Matrix
(CTM). It's important that this change to the graphics state is isolated by a
q/
Q
pair, because it's complicated to undo.
The
cm
operator takes six arguments, representing a matrix to be composed with the
CTM. Here are the basic transforms:
• Translation by
(dx, dy)
is specified by
1, 0, 0, 1, dx, dy
• Scaling by
(sx, sy)
about
(0, 0)
is specified by
sx, 0, 0, sy, 0, 0
• Rotating counterclockwise by
x
radians about
(0, 0)
is specified by
cos x, sin x, -sin
x, cos x, 0, 0
The
cm
operator appends the given transform to the CTM, rather than replacing it. To
rotate or scale around an arbitrary point (rather than the origin), translate to the origin,
rotate or scale, and translate back.
Any graphics text will have a full discussion of the mathematics of such transforms. See
“PDF and Graphics Documentation” on page 119
.