Differently sized svgs produced when building on different platforms - how to make the sizes consistent

0 votes
asked Mar 4, 2015 in To be sorted by martinjpaterson (140 points)
I get different svgs depending on where the PlantUML is built (Windows, RedHat 5 and RedHat 6). The difference is in the size of the diagram and the textLength attribute in the <text> elements. In the example the differences are small, but in a larger diagram with 5 or 6 actors, the differences are larger.
 
This happens whether or not I specify a font (I don't in the test example below, but in my real diagrams I use the same Liberation-Sans font in all places and still get different sized diagrams).
 
This causes a problem because we develop documentation with diagrams locally on Windows, but final production version is built on a Red Hat build sever (both 5 & 6 as we're gradually migrating from one to the other).
 
Do you have any idea what might be causing the differences and either what I can modify in the build environment to make them the same? These two environments are running the same version of Java (1.7.0_71). I am running plantuml version 8016.
 
Using a test file:
 
@startuml
Bob->Alice : hello
@enduml
 
here are some selections from the output svg using the test input file above, showing the differences:
 
Windows:
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink="http://www.w3.org/1999/xlink" height="129pt" style="width:114px;height:129px;" version="1.1" viewBox="0 0 114 129" width="114pt">
RedHat5:
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink="http://www.w3.org/1999/xlink" height="125pt" style="width:119px;height:125px;" version="1.1" viewBox="0 0 119 125" width="119pt">
 
Windows:
<line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 5.0,5.0;" x1="29" x2="29" y1="39.6094" y2="89.9609" />
RedHat5:
<line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 5.0,5.0;" x1="30" x2="30" y1="38.2969" y2="87.4297" />
 
Windows:
<text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="25" x="15" y="24.5332">Bob</text>
RedHat5:
<text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="27" x="15" y="22.9951">Bob</text>

1 Answer

0 votes
answered Mar 4, 2015 by plantuml (257,940 points)
We are facing here a severe issue with text and SVG.

When PlantUML is doing its drawing, it must know the exact dimension of texts, to be able to draw appropriate boxes (for example) around texts.

Under PNG, everything is fine.

Using SVG, it's another story, because the text drawing will be interpreted latter on the SVG client, and depending on fonts installed on each client, the text may be rendered differently. To force the SVG client to use a specific dimension for the text, we use the textLenght attribute, so that boxes fit the text.

Now, how to compute textLenght attribute? We use local fonts installed on the server (that is, the fonts that would be use if PNG export would be used). And since Windows and Red Hat did not have the same fonts, the lenght may differ (you can check this by using PNG export on both systems). Somehow, using server fonts is inaccurate, because those fonts will not be used at all when SVG will be rendered on the client. But it's better that no dimension at all.

I hope that my explanation are clear.

Did you try with other fonts, to see if differences between Windows and Red Hat are still there ?

If you want, you can send us your diagram so that we have a look on it : it may gives us ideas to fix the issue.

And if anyone has some better idea to cover this issue, please post!
...