Italic font not working for Graphviz (dot) diagrams

0 votes
asked Jun 14, 2022 in Bug by eduardomozart (320 points)


I'm trying to parse the following diagram:

digraph MyGraph {
  graph [fontname = "helvetica"];
  node [fontname = "helvetica" style=bold fontcolor="#595959" color="#595959"];
  edge [fontname = "helvetica" color="#595959"];
  b1, b2, c1, c2, d1, d2, e1, e2, e3, f1, f2, g1, g2, g3 [width=1 height=0.8 fixedsize=true];

  a [label="ClearPass\nServices" fontname="helvetica" fontcolor="#F5831F" color="#F5831F"]
  b [label="NAD" shape=Mrecord]
  c [label="Enf. Policy" shape=Mrecord]
  d [label="Role\nMapping" shape=Mrecord width=1.2]
  e [label="Enf. Profile" shape=Mrecord width=1.2]
  f [label="Authentication" shape=Mrecord]
  g [label="Authorization" shape=Mrecord]
  a -> b [arrowhead=none]
  a -> c [arrowhead=none]
  a -> d [arrowhead=none]
  a -> e [arrowhead=none]
  a -> f [arrowhead=none]
  a -> g [arrowhead=none]


It works just fine, but when I try to change the fontname to "helvetica italic", it renders the PNG normally, but it fails to parse Helvetica with italic style into SVG. It uses the Helvetica font correctly into SVG if it isn't using italic style.

commented Jun 14, 2022 by Martin (8,360 points)

I'm no expert on fonts, so I might be barking up the wrong tree - but try fontname="Helvetica-Oblique" instead.  This renders in SVG as:

<g id="node15" class="node"><title>a</title>
<ellipse fill="none" stroke="#f5831f" stroke-width="2" cx="1345" cy="-104" rx="85.2851" ry="18"/>
<text text-anchor="middle" x="1345" y="-100.3" font-family="Helvetica,sans-Serif" font-style="oblique" font-size="14.00" fill="#f5831f">ClearPassServices</text>

(I suspect png supports 'fake/faux' italics, but svg needs the actual font name, and some fonts seem to be oblique rather than italics...)

commented Jun 15, 2022 by eduardomozart (320 points)
Thank you @Martin! It worked!

Maybe PlantUML could identify when the "italic" keyword is being used and replace it with it's font equivalent into SVG if it's available?

commented Jun 15, 2022 by Martin (8,360 points)
To be fair, I believe that when you use Graphviz mode, Plantuml just passes everything you write through to Graphviz - so you should raise this with the Graphviz project.  I've not checked whether Plantuml's own diagram modes have similar strict font naming requirements.  

From the little I've read, handling fonts in a platform independent manner is a nightmare, so I doubt you'll find much appetite at Graphviz to fiddle with it.

One thing I can add is that with your example I found it useful to bypass Plantuml and run dot.exe directly from my (windows) command line using the "-v" switch - this provided information on whether any fonts used were found or not.

1 Answer

0 votes
answered Jun 15, 2022 by Martin (8,360 points)

As per my comment, a solution is to use fontname="Helvetica-Oblique"

It seems that some fonts come with an Italics version (hand-crafted slanty text), and some fonts come with an Oblique version (algorithmically generated slanty text).  

Graphviz seems to cope with the wrong one being specified for a given font for png (it possibly applies its own faux-italic algorithm), but not for svg - but I don't know all the technical details as to the how and why.