XML technologies / SVG / Using text elements / Available SVG tags for text elements / Storing and using text modules
Storing and using text modules
Repeating the same text with different formatting in one file is laborious, especially for long texts. Changes require updating several places, and the file grows large. Instead, define reusable text modules by naming <text> tags and referencing them wherever needed.
Define the texts before their first reference, preferably at the file’s beginning with a normal <text> tag. To keep the text invisible there, enclose it in a <defs> tag. This defines elements that are available without being displayed.
<?xml version="1.0" standalone="no"?>
...
<svg width="500" height="500">
<defs>
<text id="cr">(c) 2001 by Helma Spona</text>
<text id="titel">Die Webseite zum Buch: SVG - Scalable Vector Graphic</text>
</defs>
</svg>
Wherever you want to use the defined <text> tags cr and titel, insert a <text> tag containing a <tref> tag. Set its attribute xlink:href to the text to display. The next instruction displays the text titel at 20/70.
Note:
Texts may also be defined in another SVG file. SVG Viewer currently supports no external references with the xlink:href attribute outside hyperlinks.
<text x="20" y="70" style="font-family:Arial;font-size:16"><tref xlink:href="#titel"/></text>Figure: Output of the tref tag.
The <tref> tag also has the attributes x, y, dx, dy and rotate. They have the same meanings as for the <tspan> tag (see Formatting individual characters in text). They act as if all text referenced with <tref> were enclosed in a <tspan> tag.
Copyright © verlag moderne industrie GmbH 2001
You may print the online version for your private use.
Otherwise, this chapter from “Das Einsteigerseminar SVG — Webgrafiken mit XML” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
verlag moderne industrie GmbH, Justus-von-Liebig-Straße 1, D-86899 Landsberg/Lech, fon ++49 (0) 81 91 / 125 – 0, leserservice(at)mi-verlag.de