Search code examples
svggraphviz

Graphviz -> svg (->pdf) text flows out of the box for some viewers


An svg file generated from graphviz looks fine in some viewers (Chrome, Gnome Image Viewer) but doesn't in others (Inkscape, when converting using ImageMagick to pdf).

Here's what my minimal example looks like, on the left is Chrome (correct rendering), on the right is Inkscape (wrong):

minimal example

The above was generated by this graphviz code:

digraph {
    node [shape=box];
    foo[label="long text long text long text"]
}

SVG produced by: dot g.txt -Tsvg -o g.svg

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
 -->
<!-- Title: %3 Pages: 1 -->
<svg width="177pt" height="44pt"
 viewBox="0.00 0.00 177.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<title>%3</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-40 173,-40 173,4 -4,4"/>
<!-- foo -->
<g id="node1" class="node"><title>foo</title>
<polygon fill="none" stroke="black" points="169,-36 0,-36 0,-0 169,-0 169,-36"/>
<text text-anchor="middle" x="84.5" y="-14.3" font-family="Times,serif" font-size="14.00">long text long text long text</text>
</g>
</g>
</svg>

What is causing this? Am I doing something wrong? How do I fix it? Thanks!

Program versions:

graphviz version 2.38.0 (20140413.2041)
Inkscape 0.92.2pre0 (973e216, 2017-07-25)
GNOME Image Viewer 3.26.2
Chrome Version 69.0.3497.92
ImageMagick 6.9.9-34 Q16 x86_64 2018012

Solution

  • Using Imagemagick 6.9.10.11 Q16 Mac OSX with inkscape @0.92.3_4, I get the following. Note I just convert to jpg to be able to post here. The pdf is the same.

    convert test.svg test.pdf
    convert test.pdf test.jpg
    


    enter image description here

    So I conclude it is either your Imagemagick version or more likely your version of Inkscape or a faulty install.