XML technologies / SVG / The coordinate system of SVG graphics / Solutions

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

  1. Coordinate systems can be created by applying the transform attribute to the tag or a parent group.

  2. The SVG file containing the square should look as follows:

<?xml version="1.0" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN" "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
<svg>
  <rect width="7" height="7" x="10" y="10" />
</svg>

  1. To position the text beside the square, its y coordinate must match the square’s lower-left corner. This is the square’s y coordinate plus its height:

<text x="20" y="17" style="font-size:10px">Inhalt</text>
  1. To group the elements, enclose them in the <g> tag. Assign a name with the id attribute.

<g id="zeile1">
  <rect width="7" height="7" x="10" y="10" />
  <text x="20" y="17" style="font-size:10px">Inhalt</text>
</g>

  1. To position the group, add the transform attribute:

  2. <g id="zeile1" transform="translate(30,70)">
  3. To rotate by 30°, extend the transform attribute with the rotate instruction:

  4. <g id="zeile1" transform="translate(30,70) rotate(30)">

   

 

 

 

back to top