BigBadaboom / androidsvg

SVG rendering library for Android
http://bigbadaboom.github.io/androidsvg/
Apache License 2.0
1.19k stars 226 forks source link

Is <foreignObject> supported for HTML rendering? #233

Closed RiotGoesWoof closed 3 years ago

RiotGoesWoof commented 3 years ago

I don't see it mentioned anywhere on the implementation page, and haven't been able to find anyone discussing or having an issue with it in the issues on GitHub. However, when I try to render an SVG with <foreignObject> tags, none of the HTML inside will render.

Here is an example svg:

<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  <style>
    div {
      color: white;
      font: 18px serif;
      height: 100%;
      overflow: auto;
    }
  </style>

  <polygon points="5,5 195,10 185,185 10,195" />

  <!-- Common use case: embed HTML text into SVG -->
  <foreignObject x="20" y="20" width="160" height="160">
    <!--
      In the context of SVG embedded in an HTML document, the XHTML
      namespace could be omitted, but it is mandatory in the
      context of an SVG document
    -->
    <div xmlns="http://www.w3.org/1999/xhtml">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit.
      Sed mollis mollis mi ut ultricies. Nullam magna ipsum,
      porta vel dui convallis, rutrum imperdiet eros. Aliquam
      erat volutpat.
    </div>
  </foreignObject>
</svg>

SVG taken from here, for viewing the expected result.

BigBadaboom commented 3 years ago

Hi

Supporting HTML in a foreignObject would require some sort of HTML rendering engine. That would add a lot of bloat to AndroidSVG. One of my goals is to try to remain small as possible, so people can feel comfortable about including the library in their apps. So I think it is not very likely that support for foreignObject will ever ever be added.

But you're right, that should be noted somewhere. So I've just added it to the "Not supported" section on the home page.

However, often people use foreignObject in order to get automatic text wrapping. The potentially good news on that front is that the not-yet-adopted SVG 2 spec includes the property inline-size, which enables text wrapping. There's a good chance that I will end up supporting that as part of the text system rewrite that I am working on at the moment.

Thanks Paul