Text in Table in SVG output not completly centered

While trying different outputs, I realized that the Text in the SVG output is not completely centered.
This can be seen with the Vertical lines and the Black circles in the following examples:
SVG:
file3
PNG:

While testing, I moved the Text in the SVG manual, and it seems to be 1,7 units to the left of the center.

I am using Win10 with dot - graphviz version 10.0.1 (20240210.2158)

The examples are created throu:

graph {
// Graph generated by WireViz 0.3.2
// https://github.com/formatc1702/WireViz
	graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
	node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0]
	edge [fontname=arial style=bold label=" "]

	X2 [label=<
<table border="0" cellspacing="0" cellpadding="0">
 <tr><td>
  <table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>
   <td balign="left">X2</td>
  </tr></table>
 </td></tr>
 <tr><td>
  <table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>
   <td balign="left">P1</td>
   <td balign="left">9-pin</td>
  </tr></table>
 </td></tr>
 <tr><td>
  <table border="0" cellspacing="0" cellpadding="3" cellborder="1">
   <tr>
    <td port="p1l">1</td>
    <td>+28VDC</td>
    <td></td>
    <td  port="p1J"><FONT FACE="Sans Not-Rotated 14" POINT-SIZE="13.0" COLOR="#0066ff">&#11044;</FONT></td>
    <td></td>
   </tr>
   <tr>
    <td port="p2l">2</td>
    <td>+28VDC RTN</td>
    <td></td>
    <td></td>
    <td  port="p2J"><FONT FACE="Sans Not-Rotated 14" POINT-SIZE="13.0">&#11044;</FONT></td>
   </tr>
   <tr>
    <td port="p3l">3</td>
    <td>Token-In REF</td>
    <td  port="p3J"><FONT FACE="Sans" POINT-SIZE="13.0">&#11044;</FONT></td>
    <td></td>
    <td></td>
   </tr>
   <tr>
    <td port="p4l">4</td>
    <td>Token-In</td>
    <td  port="p4J"><FONT FACE="Sans" POINT-SIZE="13.0">&#11044;</FONT></td>
    <td></td>
    <td></td>
   </tr>
   <tr>
    <td port="p5l">5</td>
    <td>NC</td>
    <td></td>
    <td  port="p5J"><FONT FACE="Sans Not-Rotated 14" POINT-SIZE="13.0" COLOR="#0066ff">&#11044;</FONT></td>
    <td></td>
   </tr>
   <tr>
    <td port="p6l">6</td>
    <td>NC</td>
    <td></td>
    <td></td>
    <td  port="p6J"><FONT FACE="Sans Not-Rotated 14" POINT-SIZE="13.0">&#11044;</FONT></td>
   </tr>
   <tr>
    <td port="p7l">7</td>
    <td>RS-485+</td>
    <td></td>
    <td></td>
    <td></td>
   </tr>
   <tr>
    <td port="p8l">8</td>
    <td>RS-485-</td>
    <td></td>
    <td></td>
    <td></td>
   </tr>
   <tr>
    <td port="p9l">9</td>
    <td>RS-485 Shield</td>
    <td></td>
    <td  port="p9J"><FONT FACE="Sans Not-Rotated 14" POINT-SIZE="13.0" COLOR="#0066ff">&#11044;</FONT></td>
    <td></td>
   </tr>
  </table>
 </td></tr>
</table>
> fillcolor="#FFFFFF" shape=box style=filled]

	edge [color="#000000:#ff0000:#000000" label=" "]
	W1:w1:e -- X2:p1l:w
	edge [color="#000000:#000000:#000000" label=" "]
	W1:w2:e -- X2:p2l:w
	edge [color="#000000:#f5f0d0:#000000" label=" "]
	W1:w3:e -- X2:p7l:w
	edge [color="#000000:#0066ff:#000000" label=" "]
	W1:w4:e -- X2:p8l:w
	edge [color="#000000:#00ff00:#000000" label=" "]
	W1:w5:e -- X2:p9l:w

	edge [color="#000000" headclip=false, tailclip=false, style="dashed", constraint=false]
    X2:p3J:c -- X2:p4J:c[straight=true]

    edge [color="#0066ff" headclip=false, tailclip=false, style="dashed", constraint=false]
	X2:p1J:c -- X2:p5J:c[straight=true]
    X2:p5J:c -- X2:p9J:c[straight=true]

    edge [color="#000000" headclip=false, tailclip=false, style="dashed", constraint=false]
    X2:p2J:c -- X2:p6J:c[straight=true]

	W1 [label=<
<table border="0" cellspacing="0" cellpadding="0">
 <tr><td>
  <table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>
   <td balign="left">W1</td>
  </tr></table>
 </td></tr>
 <tr><td>
  <table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>
   <td balign="left">5x</td>
  </tr></table>
 </td></tr>
 <tr><td>
  <table border="0" cellspacing="0" cellborder="0">
   <tr><td>&nbsp;</td></tr>
   <tr>
    <td><!-- 1_in --></td>
    <td>
     1:RD
    </td>
    <td>X2:1:+28VDC</td>
   </tr>
   <tr>
    <td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w1" height="6">
     <table cellspacing="0" cellborder="0" border="0">
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#ff0000" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
     </table>
    </td>
   </tr>
   <tr>
    <td><!-- 2_in --></td>
    <td>
     2:BK
    </td>
    <td>X2:2:+28VDC RTN</td>
   </tr>
   <tr>
    <td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w2" height="6">
     <table cellspacing="0" cellborder="0" border="0">
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
     </table>
    </td>
   </tr>
   <tr>
    <td><!-- 3_in --></td>
    <td>
     3:IV
    </td>
    <td>X2:7:RS-485+</td>
   </tr>
   <tr>
    <td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w3" height="6">
     <table cellspacing="0" cellborder="0" border="0">
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#f5f0d0" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
     </table>
    </td>
   </tr>
   <tr>
    <td><!-- 4_in --></td>
    <td>
     4:BU
    </td>
    <td>X2:8:RS-485-</td>
   </tr>
   <tr>
    <td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w4" height="6">
     <table cellspacing="0" cellborder="0" border="0">
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#0066ff" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
     </table>
    </td>
   </tr>
   <tr>
    <td><!-- 5_in --></td>
    <td>
     5:GN
    </td>
    <td>X2:9:RS-485 Shield</td>
   </tr>
   <tr>
    <td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w5" height="6">
     <table cellspacing="0" cellborder="0" border="0">
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#00ff00" border="0"></td></tr>
      <tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0"></td></tr>
     </table>
    </td>
   </tr>
   <tr><td>&nbsp;</td></tr>
  </table>
 </td></tr>
</table>
> fillcolor="#FFFFFF" shape=box style=filled]
}

+(pin2pin.gvpr)

/*******************************************************************

  see https://forum.graphviz.org/t/straitening-one-line-throu-a-table/2196
  input must include pos values (must be output from one of the engines w/ -Tdot)
  
*******************************************************************/
BEG_G{
  string tok[int];
  int cnt;
}
/********************************************************
  the weakness is in the head==tail test
  it would be better to mark every target edge with a new attribute and test for that attribute
*********************************************************/
E[straight] {
  cnt=tokens($.pos,tok," ");
  $.oldpos=$.pos;
  pos=tok[0]+" " + tok[0]+" "+tok[cnt-1]+" "+tok[cnt-1];
}

and with these comands:
SVG: dot .\test2.gv | gvpr -cf pin2pin.gvpr | neato -n2 -Tsvg -o file3.svg
PNG: dot .\test2.gv | gvpr -cf pin2pin.gvpr | neato -n2 -Tpng -o file3.png

I do not know if this is a known Issue or not, did not find anything about this.

PDF, BMP and Tiff do not have the problem, or at least it is not as drastic as the SVG

That’s curious. The native SVG driver is capable of generating text using text-anchor="middle", but the HTML table rows use text-anchor="start". Because the downstream SVG renderer cannot be relied on to use the same fonts or to render them in the same way as when Graphviz computes text box sizes, this can happen. Maybe the problem would be solved by using dot -Tsvg:cairo because cairo embeds fonts in the output (which is more precise, but at the cost of larger SVG files that are more difficult to process downstream and for humans to read and understand.)

Someone could also look into whether lib/common/htmltable.c could be enhanced to call gvrender_textspan() with centered instead of left-justified text as needed. Offhand my hunch is this may not be as obviously easy as one might hope.

1 Like

Yes that seams to work, dot .\test2.gv | gvpr -cf pin2pin.gvpr | neato -n2 -Tsvg:cairo -o file3cairo.svg
Edit, ok when opend on my PC the Font is there :man_facepalming: but not here?
file3cairo

Here converted with Inkscape