Every object in SVG has its own natural place on the canvas. For example, for a rectangle, this place is defined by the x
and y
attributes on the rect
element:
<rect id="rect2310" y="350" x="100" width="300" height="150" />
However, one of the most interesting features of SVG is that this position can be affected by the transform
attribute. Most often, this attribute contains a sequence of six numbers inside a matrix(...)
:
<rect transform="matrix(0.96333,0.26831,-0.26831,0.96333,203.200,-160.066)" id="rect2310" y="350" x="100" width="300" height="150" />
In this form, the attribute represents an affine transform matrix. A complete treatment of matrix algebra is way outside the scope of this book, but you should have an idea of what transformations are called affine:
Any moves, also called translations (Figure 6-1)
Any scalings, including both uniform and nonuniform; for example, scaling only width or only height (Figure 6-2)
Any rotations around any center (Figure 6-6)
Any skews, sometimes called shears (Figure 6-7)
Not coincidentally, these transformations are exactly those that the Selector tool can perform (Chapter 6). Note that, for example, perspective transformations are not affine: They cannot be expressed by a transform
attribute and cannot be performed by the Selector tool.
So, an element with a transform
attribute means: “Draw this element at its natural position and size, then move, scale, rotate, or skew it as specified in the transform.”
Moreover, the transform
value on the element’s parent (for example, on a g
element that contains this object) affects the object, too. All the transforms on the object and all its ancestors are combined. This is why, for example, when you move or scale a group, all objects belonging to the group are moved and scaled by the same amount, although it is only the parent g
element whose transform
attribute is modified.
On the Transforms tab of the Inkscape Preferences dialog (3.1 Preferences), there’s a Store transformation option with the values of Optimized and Preserved. This determines the strategy of Inkscape when transforming objects. If set to Preserved, it will always record all transformations of all objects as transform
attributes, leaving all other attributes intact. If set to Optimized (default), it will try, whenever possible, to record the transformation into the object’s other attributes and not transform
. For example, when you move a rectangle, in the optimized mode it will change the rectangle’s x
and y
attributes instead of adding or changing its transform
. Not all kinds of transformations and not all types of objects allow such optimization, however, so even in the optimized mode transform
attributes will still be created. The only object type that can optimize any kinds of transformations and make do without the transform
at all times is path
.