Use resvg or other rendered instead of Chromium to export SVGs
Consider using resvg instead of Chromium to render SVGs. Also solves #496.
There are two ways this can be done:
- FFI calls - harder to implement and harder development
- download binary - external dependency that must be downloaded separately on user's machine - same as current for Chromium afaik
resvg usage is blocked by https://github.com/RazrFalcon/resvg/issues/541 and uuh looks like these selectors are not supported:
-
:dir -
:last-child -
:not -
:nth-child -
:target
checked by
curl -s https://raw.githubusercontent.com/terrastruct/d2/master/docs/examples/twitter/in.d2 | d2 - - | ./resvg - out.png 2>&1 | grep "not supported"
would love to give chromium and playwright the boot. i suspect the easiest option is to actually roll out own PNG renderer using some low level graphics lib that writes rgba pixels. i don't know enough about how fonts work though
My 2c: @alixander have you considered using a Canvas/Cairo vector drawing library (like https://github.com/tdewolff/canvas) to generate an intermediate object that could be rendered into any supported target ? Probably would required a significant rewrite effort...