'fontnames' attribute docs aren't quite correct
Page URL
https://graphviz.org/docs/attrs/fontnames/
Problem description
What the docs claim:
If
fontnamesis undefined orsvg, the output will try to use known SVG fontnames.For example, the default font
Times-Romanwill be mapped to the basic SVG fontserif. This can be overridden by setting fontnames topsorhd. In the former case, known PostScript font names such asTimes-Romanwill be used in the output. In the latter case, the fontconfig font conventions are used. Thus,Times-Romanwould be treated asNimbus Roman No9 L. These last two options are useful with SVG viewers that support these richer fontname spaces.
What actually happens:
$ echo '
graph G {
n1 -- n2;
}
' | _dist/bin/dot -Tsvg
<?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 12.2.1~dev.20241107.1950 (20241107.1950)
-->
<!-- Title: G Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.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 112)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- n1 -->
<g id="node1" class="node">
<title>n1</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-85.33" font-family="Times,serif" font-size="14.00">n1</text>
</g>
<!-- n2 -->
<g id="node2" class="node">
<title>n2</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-13.32" font-family="Times,serif" font-size="14.00">n2</text>
</g>
<!-- n1--n2 -->
<g id="edge1" class="edge">
<title>n1--n2</title>
<path fill="none" stroke="black" d="M27,-71.7C27,-60.85 27,-46.92 27,-36.1"/>
</g>
</g>
</svg>
$ echo '
graph G {
fontnames="";
n1 -- n2;
}
' | _dist/bin/dot -Tsvg
<?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 12.2.1~dev.20241107.1950 (20241107.1950)
-->
<!-- Title: G Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.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 112)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- n1 -->
<g id="node1" class="node">
<title>n1</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-85.33" font-family="Times,serif" font-size="14.00">n1</text>
</g>
<!-- n2 -->
<g id="node2" class="node">
<title>n2</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-13.32" font-family="Times,serif" font-size="14.00">n2</text>
</g>
<!-- n1--n2 -->
<g id="edge1" class="edge">
<title>n1--n2</title>
<path fill="none" stroke="black" d="M27,-71.7C27,-60.85 27,-46.92 27,-36.1"/>
</g>
</g>
</svg>
$ echo '
graph G {
fontnames="svg";
n1 -- n2;
}
' | _dist/bin/dot -Tsvg
<?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 12.2.1~dev.20241107.1950 (20241107.1950)
-->
<!-- Title: G Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.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 112)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- n1 -->
<g id="node1" class="node">
<title>n1</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-85.33" font-family="serif,serif" font-size="14.00">n1</text>
</g>
<!-- n2 -->
<g id="node2" class="node">
<title>n2</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-13.32" font-family="serif,serif" font-size="14.00">n2</text>
</g>
<!-- n1--n2 -->
<g id="edge1" class="edge">
<title>n1--n2</title>
<path fill="none" stroke="black" d="M27,-71.7C27,-60.85 27,-46.92 27,-36.1"/>
</g>
</g>
</svg>
$ echo '
graph G {
fontnames="ps";
n1 -- n2;
}
' | _dist/bin/dot -Tsvg
<?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 12.2.1~dev.20241107.1950 (20241107.1950)
-->
<!-- Title: G Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.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 112)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- n1 -->
<g id="node1" class="node">
<title>n1</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-85.33" font-family="Times-Roman,serif" font-size="14.00">n1</text>
</g>
<!-- n2 -->
<g id="node2" class="node">
<title>n2</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-13.32" font-family="Times-Roman,serif" font-size="14.00">n2</text>
</g>
<!-- n1--n2 -->
<g id="edge1" class="edge">
<title>n1--n2</title>
<path fill="none" stroke="black" d="M27,-71.7C27,-60.85 27,-46.92 27,-36.1"/>
</g>
</g>
</svg>
$ echo '
graph G {
fontnames="hd";
n1 -- n2;
}
' | _dist/bin/dot -Tsvg
<?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 12.2.1~dev.20241107.1950 (20241107.1950)
-->
<!-- Title: G Pages: 1 -->
<svg width="62pt" height="116pt"
viewBox="0.00 0.00 62.00 116.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 112)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
<!-- n1 -->
<g id="node1" class="node">
<title>n1</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-85.33" font-family="Times,serif" font-size="14.00">n1</text>
</g>
<!-- n2 -->
<g id="node2" class="node">
<title>n2</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-13.32" font-family="Times,serif" font-size="14.00">n2</text>
</g>
<!-- n1--n2 -->
<g id="edge1" class="edge">
<title>n1--n2</title>
<path fill="none" stroke="black" d="M27,-71.7C27,-60.85 27,-46.92 27,-36.1"/>
</g>
</g>
</svg>
In other words, if fontnames is unset, set to "", or set to "hd", the default Times-Roman font will be mapped to Times,serif. If fontnames="svg", the SVG file uses serif,serif (which is kind of nonsensical), and if fontnames="ps", the SVG files uses Times-Roman,serif. Nimbus Roman No9 L is never used, at least on my system, and serif is always included as a fallback for whatever font is chosen.