Delta 10 - Library inclusion
svgdxdocuments can include fragments from library files
Using libraries
Both the svgdx and svgdx-server command line programs support library inclusion through the --include flag.
This can be given multiple times to include more than one library.
$ svgdx --include library.xml -i input.xml -o output.svg
Note the example library has a name="common" attribute in the root SVG element. The library filename is irrelevant.
If multiple library files are included that share the same name, only the last one will be used.
When reference an element from a library the href attribute uses the target id prefixed by the library name and a colon,
for example href="#common:c1" in the input file above references the element with id c1 in the library named common.
Writing library files
A library file suitable for using in svgdx is a normal svgdx file with the following requirements:
-
The root
<svg>element must have anameattribute; this is used as the first part ofhrefattributes linking to the target element. -
Only
<defs>and<specs>are considered when referencing elements from the library:<defs>elements containing a referenced target are included as-is in the output document;<defs>elements that do not contain any referenced elements are not included in the output. This ensures that<use>elements in the rendered output have a target within the output.<specs>elements are excluded as elsewhere insvgdx- they are typically to contain<reuse>targets that are rendered into the output.
Elements other than <defs> and <specs> may still be useful so that library files can be
“self-documenting”, i.e. include examples of the fragments they include.
Example library document library.xml:
<svg name="lib">
<specs>
<circle id="c1" text="dx" r="2"
style="fill:black;" text-style="fill:white"/>
</specs>
<reuse href="#c1"/>
</svg>