改变整个图形的字体?

我想知道我是否可以为整个图定义一种替代字体。

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

根据这篇 1旧文章,fontname 属性只能单独定义:

节点和边不继承图形的字体,您需要指定 把他们分开

有没有其他的方法,如何定义全局字体?

38950 次浏览

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"];
...
}

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

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