When using dot -Txlib my_graph.dot I got exactly the output I want (I’m not including the image because of the beginner limitation).
But when using dot -Tsvg my_graph.dot > my_graph.svg, there is extra spacing around the font labels (it’s especially visible before the parenthesis and the comma). Do you know how I could remove them?
I’m not including the image because of the beginner limitation
You don’t have to upload your SVG images. You can render them inline in this forum directly using only DOT source code as described in Render Graphviz graphs directly in your posts.
The inline rendering is very nice indeed. The output you got is the same than what I get with dot -Txlib as you can see in the second post. However, you can see in the image in the first post that there are extra spaces between main and the opening parenthesis, as well as between Fn() and the comma, and between usize and the closing parenthesis.
I can reproduce your problem with dot - graphviz version 2.44.2~dev.20201126.1914 (20201126.1914) when using -Tsvg, but not with -Tpng. I suggest you report it as an issue at https://gitlab.com/graphviz/graphviz/-/issues/new
We’ve talked about this kind of problem several times before. If results differ between -Tsvg and -Tpng, then the problem is usually that SVG generated by the Graphviz default SVG driver is underspecified. If fonts are not embedded in SVG, there’s really no way of knowing if graphviz and the downstream renderer are loading the same font for “Times-Roman”. So, use -Tsvg:cairo (or -Tsvg:quartz on a Mac) to get embedded fonts. The SVG is much more complicated but also much more likely to render the same everywhere. This problem is a little like noticing that web pages can sometimes look different in Microsoft Edge, Safari, Firefox or Chrome.
The sizing and layout of text in Graphviz doesn’t depend on the selection of output renderer. (Depending how graphviz was built, the preference is still to use cairopango at layout time to resolve fonts and to get the size of text, but if not available Graphviz could fall back to freetype/fontconfig/libgd. Run with -v to see what is happening.) An advantage of the simple SVG driver is that the output is more easily parsable by downstream tools, and we were able to implement features not in the cairopango API.