Reputation: 4750
I'm working with Graphviz on Mac but most of my apps run on servers with Ubuntu. I've noticed that dot-schemes with the same source code are drawn a bit differently when compiled on different operating systems.
It seems to me that the main reason is the difference between fonts on the systems. Even though I use the same generic fonts and same sizes — they appear too different which affects the layout a lot.
So the question is: is it possible to make fonts look identical in Graphviz schemes across the systems?
Below I attach the examples demonstrating the problem. Images are attached as links for convenience.
Source code:
digraph {
graph [label="Mac" labelloc=t]
dpi=100
pad=0.2
rankdir=LR
a [shape=rect label="width=1" width=1]
b [shape=rect label="width=1.5 Arial" width=1.5 fontname=Arial]
c [shape=rect label="width=2.7 Arial 20" width=2.7 fontname=Arial fontsize=20]
d [shape=rect label="width=4 Helvetica" width=4 fontname=Helvetica]
e [shape=rect label="width=5 Helvetica 25" width=5 fontname=Helvetica fontsize=25]
f [shape=rect label="width=6, blue 0.8, red 0.2" width=6 style=filled color="blue:red;0.2" fontcolor=white]
}
As you can see on the schemes — the font is not the only problem: filling with two colors looks a bit different on Mac\Ubuntu and Win10. But this specific issue may be because I have graphviz 2.38 on my Windows machine.
And now the same scheme but without node labels:
digraph {
graph [label=Mac labelloc=t]
dpi=100
pad=0.2
rankdir=LR
a [shape=rect label="" width=1]
b [shape=rect label="" width=1.5 fontname=Arial]
c [shape=rect label="" width=2.7 fontname=Arial fontsize=20]
d [shape=rect label="" width=4 fontname=Helvetica]
e [shape=rect label="" width=5 fontname=Helvetica fontsize=25]
f [shape=rect label="" width=6 style=filled color="blue:red;0.2" fontcolor=white]
}
Here the resuts are almost identical (except the damn colorlist)
Upvotes: 3
Views: 705
Reputation: 359
Ubuntu doesn't have the Times New Roman font by default. This is the default font used by Graphviz, so I was getting poor results when dot layout was done on Ubuntu as compared to Windows or Mac (which come natively with the correct fonts).
The most important thing is to do if you are generating Grapviz images on Ubuntu is:
sudo apt install ttf-mscorefonts-installer1
Beware that will pop up on your terminal an EULA from Microsoft, and you may not see the prompt to respond 'yes'.
However that may not be enough to get consistent results if you have built GraphViz completely by yourself. You may still get anomalous results results unless you have pre-installed certain libraries. So you should also do:
apt-get install --no-install-recommends -y build-essential clang-format cmake git pkg-config autoconf bison libtool dh-python flex d-shlibs debhelper fakeroot freeglut3-dev libgts-dev swig libgtkglext1-dev libglade2-dev libqt5gui5 qt5-qmake qtbase5-dev libann-dev libaa1-dev libdevil-dev libgd-dev libgtk-3-dev ghostscript libgs-dev liblasi-dev libpoppler-dev libpoppler-glib-dev librsvg2-dev libwebp-dev ruby golang-go guile-3.0 guile-3.0-dev lua5.3 liblua5.3-dev libperl-dev php-dev libsodium-dev libargon2-0-dev libpython3-dev ruby-dev tcl-dev python3-venv gcovr lcov shellcheck
The guidance to help me determine the packages needed came from the Gitlab page with the Dockerfile that is used to build Graphviz for testing: https://gitlab.com/graphviz/graphviz/-/blob/main/ci/ubuntu-22.04/Dockerfile )
Once I had done the above apt installs and rebuilt Graphviz, it generated the same layouts on Ubuntu as it does on Mac and Windows.
The above was tested with Graphviz 12.2.1. I am running on ARM architecture (which was why I needed to rebuild Graphviz from source as there was no up to date deb available).
Upvotes: 1
Reputation: 4750
The problem seemed to be with graphviz version which is bottled in Homebrew. Graphviz is very strange there, especially it doesn't include Cairo engine and really has some problems with fonts.
So I have removed Homebrew version and installed Graphviz from MacPorts. Now the font sizes when I build images on Mac are almost the same as on Ubuntu and Windows. The fonts are not perfectly the same but they are close enough for the development process.
Same image generated by Graphviz from MacPorts
Upvotes: 1