d2 icon indicating copy to clipboard operation
d2 copied to clipboard

Use resvg or other rendered instead of Chromium to export SVGs

Open vfosnar opened this issue 2 years ago • 3 comments

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"

vfosnar avatar Aug 20 '23 20:08 vfosnar

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

alixander avatar Aug 20 '23 22:08 alixander

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...

abejenaru avatar Nov 29 '23 10:11 abejenaru