XML technologies / SVG / Filters, transformations and gradients / Rotating and skewing elements / Skewing elements

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

Besides the rotate instruction, the transform attribute offers the instructions skewX and skewY to skew or mirror an element on the x or y axis. Both take an angle as parameter.

The result also depends on the elements’ positions, because the angle always refers to the origin. The next figure skews two texts with identical settings but different positions. Unskewed texts appear gray for comparison.

Skewing text 20° on the x axis

Figure: Skewing text 20° on the x axis.

The required code is:

<g transform="skewX(20)">
  <text x="150" y="130" style="font-family:'Arial Black';font-size:46;stroke:none;fill:rgb(0,0,255)">SVG</text>
  <text x="40" y="40" style="font-family:'Arial Black';font-size:46;stroke:none;fill:rgb(0,0,255)">SVG</text>
</g>

Note:
Skewing a group or its individual elements makes no difference, because the angle always refers to the group’s or graphic’s origin.

Any angle from 0 to 360° can be specified, but multiples of 90° produce no visible change.

Like the skewX instruction, use skewY to skew on the y axis. The result again depends on the position in the coordinate system.

Skewing text on the y axis

Figure: Skewing text on the y axis.

Note:
When skewing text on the y axis, remember its baseline is used. Unlike graphic elements, text has its origin at the baseline’s intersection with the x axis, not at its upper-left corner.

Both effects can be combined, as the next figure shows. It uses skewY at 20° and skewX at 45°.

Skewing text on the x and y axes

Figure: Skewing text on the x and y axes.

   

back to top