Number: 1864
Title: setting the dpi attribute results in bad svg transformation
Submitter: Daniel
Date: Fri Jan 22 13:12:30 2010
Subsys: Output generation
Version: 2.20.2
System: x86-Linux-Ubuntu 9.10 (Karmic)
Severity: minor
Problem:
When I apply the 'dpi' option of the graph with a value different from 72, the svg-output of any graphs is scaled out of view. This results in bad results when using rsvg for post processing and also can be a problem, when displaying the resulting svg in browsers, viewers or using desktop previews.

The problem is a bad transformation generated in the main svg group <g...> ... </g> in the svg output: the example provided by me results in a node with the text 'Hallo', when I display the the svg output in a browser (firefox) it only shows the upper left quarter of the node. Also inkscape shows me, that the page of the output is only half height and half width of the actual group of the graph.

The problem can be seen in the group enclosing the graph in the svg output: ..


<!-- Title: G Pages: 1 -->
<svg width="156pt" height="88pt"
 viewBox="0.00 0.00 78.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(2 2) rotate(0) translate(4 40)">
<title>G</title>
..

We can see a transform="scale(2 2)...."

This is unnecessary, as the SVG documentation states: http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute

Specifying the viewbox="..." in the line above and adjusting the width and height of the whole <svg..> </svg> is enough to get a bigger output with the 'dpi' attribute. The behaviour specified in the graphviz documentation can be achieved by manually editing the svg file to: ..


<!-- Title: G Pages: 1 -->
<svg width="156pt" height="88pt"
 viewBox="0.00 0.00 78.00 44.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 40)">
<title>G</title>
..

as it would be with dpi=72.

This problem affects anyone, who uses the same file for raster and vector output or wants to get a vector output comparable to raster output. Also affected are some automated build chains as a trac plugin.
Input:

digraph G {
graph [dpi=144]
Hallo
}
Fix:
Workarounds:

 - don't use the dpi attribute with svg output
 - manually edit the output file

Hints for a fix:


 - don't change the scale attribute of the transformation in the svg output away from (1 1)

Should be easy for someone with a knowledge of the code position - unfortunately not me.
Owner: *
Status: *