Graphviz: change font for the whole graph?

后端 未结 3 1994
独厮守ぢ
独厮守ぢ 2021-01-31 13:05

I am wondering if I can define an alternative font for the whole graph.

...
digraph script_concept {
graph [layout=\"dot\",fontname=\"helvetica\"];
...
<         


        
相关标签:
3条回答
  • 2021-01-31 13:47

    No, there is no other way.

    As in the forum post you linked, you have to define the default values separately (like the other attributes) at the beginning of your graphviz file:

    digraph g {
     graph [fontname = "helvetica"];
     node [fontname = "helvetica"];
     edge [fontname = "helvetica"];
     ...
    }
    
    0 讨论(0)
  • 2021-01-31 13:56

    Not sure if this is a recent update, but you can change these at the command-line level using the -G, -E and -N attribute flags. That is, the following works for me:

    $ dot -Tpng -Nfontname=Roboto -Nfontsize=10 \
        -Efontname=Roboto -Efontsize=10 \
        tree.dot > tree.png
    
    0 讨论(0)
  • 2021-01-31 13:59

    However, there's one easy trick, if you are exporting svgs:

    sed 's/Times,serif/Helvetica/g' thegraph.svg > thegraph_helvetica.svg

    combine this with Make and all the horror will be hidden :) here's an example Makefile:

    all: helvetica
    
    svg:
        cat thegraph.dot | dot -Tsvg > thegraph.svg
    helvetica: svg
        sed 's/Times,serif/Helvetica/g' thegraph.svg > thegraph_helvetica.svg
    
    0 讨论(0)
提交回复
热议问题