[cairo] Inline SVG images and the need to prefix identifiers

Christian von Schultz christian.cairo at vonschultz.se
Tue Oct 20 07:42:02 PDT 2015


Background: SVG can be used inline in XHTML. My use case involves
using MathML with SVG fallback using <annotation-xml>, to express
mathematics in an XHTML document. I generate my SVG images using
LaTeX, Poppler and Cairo.

The problem when inserting several SVG documents into the same XHTML
document is that some id's are clashing.  The first SVG image has
    <symbol overflow="visible" id="glyph0-0">
and so has the second SVG image, and the third, and so on.
Then the <use> element with xlink:href="#glyph0-0" doesn't know which
symbol it refers to, and things aren't rendered properly. This problem
arises with every id and every reference. Changing the identifiers and
references when patching it all together is possible, but I worry a
bit about missing something. There are several ways references can be

Would it make sense to have Cairo support inserting a prefix (or
appending a suffix) to the element identifiers as they are generated?
A "char *prefix" in the cairo_svg_document struct, for instance,
enabling code such as
_cairo_output_stream_printf (document->xml_node_glyphs,
	 "<symbol overflow=\"visible\" id=\"%sglyph%d-%d\">\n",
in _cairo_svg_document_emit_glyph(), and similarly in the other
emitters (alpha, image, pattern, clip, surface, linear, radial, mask)?

It would make life easier (and less error prone) for anyone trying to
combine SVG files on the XML level.

Comments are welcome.


More information about the cairo mailing list