Closed holeybit closed 2 years ago
Yeah, we don't handle foreignObject
. Which, frankly, is a bit complicated as well, since it basically is an island of HTML content in the middle of SVG. Writing an SVG renderer isn't easy already. Doing the same for HTML get even worse, sadly.
Perhaps we could try at least injecting the chosen font, since Comic Sans everywhere is a necessity, right?
I guess it shouldn't be too hard to just include the foreignObject in the resulting sketch (at least for SVG output), albeit not sketched then. This may be sufficient for text content and we could even try to inject Comic Sans FTW.
I've toyed around with it and noticed that mermaid seems to use viewBox scaling which is currently not really supported, so that the result is scaled differently. I've created a separate issue for this: #78
Once this is fixed, I'll give the foreignObject
a shot.
@holeybit I've pushed a simple implementation for the foreignObject
elements and updated https://fskpf.github.io/ Please try it there with more, common mermaid samples and post your feedback. I'd expect some artefacts, because the current implementation is still very superficial.
The implementation just copies the foreignObject
to the output SVG, thus it's only rendered for the SVG output. That said, this entire foreignObject
element is problematic, because it often relies on CSS rules that don't apply anymore after the sketching (due to the remodeling of the output DOM).
To better support the given mermaid sample, I've inlined font related CSS rules directly on the output element. To fix this more thoroughly, the CSS inlining should be done recursively on the entire foreignObject
and all (not just font related) properties.
About applying Comic Sans: The foreignObject
's overflow defaults to hidden
which clips the Comic Sans text most likely. Unconditionally setting overflow to visible
is not really an option IMO because the foreignObject
may contain anything...
@fskpf and @ygra -- thank you!! I was actually browsing the source tree about an hour ago (maybe less) and saw foreign-object.ts
in geom
and though 'hmm, there is something here...'
I tested a few other diagrams that I made from mermaid, they are all look good. Appreciate the added feature. As far as I can tell, svg2roughjs has the best looking implementation out of a handful of options that I was looking at. Thanks again!
Thank you for your feedback! I've released the fix as new version (https://github.com/fskpf/svg2roughjs/releases/tag/v2.3.0), so I'd consider this closed. If you find some odd artefacts please open a new issue then.
Was hoping to pass flowchart created by mermaidjs, but it seems the text is not getting thru. Maybe due to the use of
foreignObject
tag instead oftext
?https://mermaid-js.github.io/mermaid-live-editor/view#pako:eNo1jcEKwjAQRH8l7EmhePCYm1DBs_W4l7VZkkiTlHQjSOm_u1Kc08zwhllhLI7Bgq80B_PoMRvV5XDjaSpmePvzvTQfTq_liBk6SFwTRaeL9YciSODECFbtkxZ1mDfl2uxI-OqilApWauMOqEkZPnn8553pI-l52svtC02KMJs