Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many levels of recursion does SVG support?

Tags:

svg

I cannot get past 2 levels. (Tried on Iceweasel and Chromium.)

As a test, I tried a variant of the code presented in this earlier reply. This one consists of 3 separate files, where a.svg includes b.svg, and b.svg includes c.svg. (NB: This is not a cycle.)

<!-- a.svg -->
<svg width="100%" height="100%" viewBox="-100 -100 200 200" version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <circle cx="-50" cy="-50" r="30" style="fill:#b58900" />
  <image x="10" y="20" width="80" height="80" xlink:href="b.svg" />
</svg>
<!-- b.svg -->
<svg width="100%" height="100%" viewBox="-100 -100 200 200" version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <circle cx="-50" cy="-50" r="30" style="fill:#cb4b16" />
  <image x="10" y="20" width="80" height="80" xlink:href="c.svg" />
</svg>
<!-- c.svg -->
<svg width="100%" height="100%" viewBox="-100 -100 200 200" version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <circle cx="-50" cy="-50" r="30" style="fill:#dc322f" />
</svg>

I expected to see a large dark yellow dot, a medium-sized orange dot, and a small red dot, but I see only the first two. In fact, what I see is exactly the same as what I would see if b.svg did not include c.svg.

Why is c.svg not being included?

Is there a way to get SVG recursion to work for more than 2 levels?

like image 461
kjo Avatar asked Mar 09 '16 21:03

kjo


1 Answers

SVG when used as an image must be complete in a single file.

  • a.svg is not an image
  • b.svg is included as an image by a.svg and is therefore subject to the complete in a single file image rule so any images it contains must be included as data URIs.
  • c.svg is ignored as b.svg cannot refer to external files.

Convert c.svg to a data URI and include it inline in b.svg to get round this.

like image 83
Robert Longson Avatar answered Dec 31 '22 13:12

Robert Longson