Graphviz can't find any fonts
Asked Answered
D

2

8

I'm getting "Could not find/open font" errors when doing anything with graphviz. I've been narrowing it down to an as simple graph as possible, in the file simplest.dot:

digraph G {
  node1
}

When running $ dot simplest.dot -Tpng -O the graph is rendered to simplest.dot.png, but I always get this error: Error: Could not find/open font, and the font used in the output isn't very pretty.

According to the graphviz faq, when this error occurs, you can tell graphviz where to look for fonts. I've been looking around for fonts on the system I'm using, and there seem to be some TrueType fonts in /usr/share/fonts, among others, the Bitstream Vera fonts, which seem to live in /usr/share/fonts/bitstream-vera.

So I've tried setting fontpath and fontname in the dot graph, to help graphviz figure things out:

digraph G {
  fontpath="/usr/share/fonts/bitstream-vera"
  fontname="Bitstream Vera Sans"
  node1
}

But I'm still getting the exact same error. I've tried several variations of the path and font name, but I can't seem to get it right. What am I doing wrong?

Declan answered 24/1, 2011 at 21:18 Comment(0)
C
5

This might be a shot into the dark, but in http://www.graphviz.org/doc/info/attrs.html#d:fontname it says If you specify fontname=schlbk, the tool will look for a file named schlbk.ttf or schlbk.pfa or schlbk.pfb in one of the directories specified by the fontpath attribute.

So, I'd probably try

digraph G {
  fontpath="/usr/share/fonts/bitstream-vera"
  fontname="nameOfttfWITHOUTsuffix.ttf"
  node1
}
Catechetical answered 25/1, 2011 at 14:28 Comment(3)
It actually seems like this works! I kinda feel stupid for not trying this myself. Thanks!Declan
Having to add a font configuration in each project is okay but it'd be nicer to fix the tool itself.Override
These settings don't work everywhere. Please read gitlab.com/graphviz/graphviz/blob/master/doc/fontfaq.txt for more details.Moan
F
0

On my macOS, the following works:

digraph G {
    node [shape=plaintext, fontname="SourceCodePro"];
Fallingout answered 24/10, 2023 at 22:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.