After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 316590 - Inconsistent interpreation of SVG exported by Dia (text sizes)
Inconsistent interpreation of SVG exported by Dia (text sizes)
Status: RESOLVED FIXED
Product: dia
Classification: Other
Component: exports
0.94
Other Linux
: Normal normal
: 0.97
Assigned To: Hans Breuer
Dia maintainers
: 116098 543278 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2005-09-17 19:46 UTC by Roland Stigge
Modified: 2008-07-19 08:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Dia file (18.30 KB, application/x-dia-diagram)
2005-09-17 19:47 UTC, Roland Stigge
  Details
svg file (147.40 KB, image/svg+xml)
2005-09-17 19:48 UTC, Roland Stigge
  Details
dia file (1.33 KB, application/x-dia)
2006-04-26 13:40 UTC, Roland Stigge
  Details
svn file (3.11 KB, image/svg+xml)
2006-04-26 13:42 UTC, Roland Stigge
  Details
Perl script to fix scaling problem in svg produced by dia (2.28 KB, text/plain)
2006-06-14 06:53 UTC, Dov Grobgeld
  Details
Patch that solves the scaling problem in the dia svg output (5.82 KB, patch)
2006-06-22 19:43 UTC, Dov Grobgeld
needs-work Details | Review

Description Roland Stigge 2005-09-17 19:46:18 UTC
Distribution/Version: Debian

A Debian user reported the following:

===========================================================================
I attached 2 files. the dia file and the result of an SVG export.

As you can see, the size of the box in the SVG file is not correct.

If you try en EPS export the same sort of problem is present but less
pronounce.
===========================================================================

I could reproduce this with a current CVS snapshot. It may be related to #116098
but doesn't look exactly like it. It's even much more annoying.

I'm attaching the examples from the Debian bug report.
Comment 1 Roland Stigge 2005-09-17 19:47:17 UTC
Created attachment 52347 [details]
Dia file
Comment 2 Roland Stigge 2005-09-17 19:48:00 UTC
Created attachment 52348 [details]
svg file
Comment 3 Roland Stigge 2005-09-17 19:50:07 UTC
The original Debian bug report can be found at http://bugs.debian.org/328220
Comment 4 Hans Breuer 2005-10-08 15:34:16 UTC
Sorry, I fail to see what's broken in the SVG output. From the svg spec v1.0 :

"The value of the viewBox  attribute is a list of four numbers <min-x>, <min-y>,
<width>  and <height>, [...]". From my understanding the behaviour of Dia's c-svg
exporter - which seems to be used here - is correct. I'm even tempted to change
diasvg.py to behave the same.
Comment 5 Lars Clausen 2005-11-14 21:18:48 UTC
This is an awful example, as there's a large amount of stuff to show a simple
bug.  Trimming it down to the least amount of objects that display the bug would
make it a lot easier to work with.

I'm suspecting that this is a duplicate of the well-known text width problems --
if the fact that text overshoots the box is indeed the issue.  I'm thinking we
could use the textLength attribute to force the SVG renderer to use the correct
length.

If the bug is something else, please inform us.
Comment 6 Roland Stigge 2006-04-26 13:39:47 UTC
Interestingly, it seems to be a matter of font/size interpretation. Consider the attached example of the "Error" class of the above big example: Opening the svg file in inkscape shows an overflown box while opening in sodipodi does not.
Comment 7 Roland Stigge 2006-04-26 13:40:57 UTC
Created attachment 64321 [details]
dia file
Comment 8 Roland Stigge 2006-04-26 13:42:08 UTC
Created attachment 64322 [details]
svn file
Comment 9 Hans Breuer 2006-05-20 13:58:41 UTC
reflect comments in subject
Comment 10 Dov Grobgeld 2006-05-23 16:24:06 UTC
After getting inconsistent renderings of the SVG output produced by Dia, I had a look at its svg output today.

Here is part of the SVG output of a 3cm square produced by dia:

  :
  <svg width="3cm" height="2cm" viewBox="4 3 3 2">
    <rect style="fill: #ffffff" x="4.1" y="3.75" width="2.2" height="1.9"/>
  :

and here is a similar square output by inkscape:

  <svg ... width="30mm" height="30mm" ...>
  <rect ... width="105.20984" height="105.21541" x="63.081066" y="59.857193" />

There are two differences:

1. dia creates a viewport which according to the SVG specification is ok. It then gives the draw commands relative to the view port in user unit which is also ok. 

2. The magnitude of the numbers in the drawing commands.

And there lies the problem. The choice of the view port in cm units causes the distances to be small numbers. It turns out that various SVG reading software (rsvg and mozilla firefox, and even inkscape to a lesser degree) seem to round the distances to integer. This in turn causes huge quantization errors. It would be much better to multiply the viewport by a factor of 1000. Or to try to imitate inkscape, that doesn't set up a viewport at all, but uses default distance units. Though I must admit that I haven't been able to figure out what those mean...

Comment 11 Hans Breuer 2006-05-23 21:04:15 UTC
Thanks for the analysis. I've just re-read
http://www.w3.org/TR/SVG11/coords.html#Introduction
and think we should probably follow your suggestion to scale the viewBox 
and all coordinates. [Apparently the viewBox needs to be in integer.]
I also don't understand why the Inkscape way works, so to me leaving
out the viewBox does not look like an option ...
Comment 12 Dov Grobgeld 2006-06-14 06:53:46 UTC
Created attachment 67320 [details]
Perl script to fix scaling problem in svg produced by dia

Being too lazy to dig into the dia sources at the moment, I wrote a small perl script that transforms the svg output of dia, by multiplying all distances by a fixed factor. I'm attaching it here in lack of a better place to put it.
Comment 13 Hagen Fritsch 2006-06-19 22:03:00 UTC
Unfortunately the script does not adjust the stroke-width.

I open the file in inkscape set units to px save again and run the following perl-script to get an appropriate svg-image that can be displayed in most programs (i.e. firefox).

Was a quick hack, is ugly but works (at least for me).

--- fixsvg.pl ---
while(<>) {
        /(style=|viewBox=|points=|d=|[xy][12]?=)/ && s/([^xy#0-9\.])(\d+\.?\d*)/$1.($2*100)/eg;
        print;
}
Comment 14 Dov Grobgeld 2006-06-21 09:00:44 UTC
Yes, I realized that my script wasn't perfect. I fixed another few issues in it after I uploaded it, but I don't know if it is worth putting it on the site.

I had a look though at sources in cvs at home in order to fix it "for real", but was confused by the interaction between the svg related code in the plug-in directory and the svg related code in the lib directory. I got it to work by changing the sources in both places, but I was a bit confused about this split-up of svg output functionality. Could someone describe to me what the interaction of the code in these different directories are?

Comment 15 Hans Breuer 2006-06-21 21:56:33 UTC
The code in lib/ is the svg rendering base class shared by two exporters. The pure SVG exporter this bug is dealing with and the Shape exporter. The latter creates a combination of SVG and Shape specific information which is useable for Dias facility to define new objects without writing C code.
Comment 16 Dov Grobgeld 2006-06-22 05:12:08 UTC
I guess that means that if I change the svg code in lib, that will change the format output by the Shape exporter. Is it possible to make some changes to the Shape exporter codeto compensate for that? If not, do you have any suggestion what to do, Hans? Perhaps passing in a scaling parameter somehow into the svg rendering class? Is there any mechanism for that?
Comment 17 Dov Grobgeld 2006-06-22 19:43:14 UTC
Created attachment 67865 [details] [review]
Patch that solves the scaling problem in the dia svg output

Here is a patch that solves the problem of the svg output. It introduces a new class variable "scale" into the svg render that is set either to 100 in the svg plug-in and to 1 in the shape plug-in. This scale is then multiplied into all the svg distances through a somewhat ugly modification of the dia_svg_dtostr macro in diasvgrender.c .

The patch further modifies the text size output by a factor of 0.7 to match the size that is output by dia when writing postscript directly.
Comment 18 Dov Grobgeld 2006-10-09 07:10:36 UTC
Any progress with reviewing the patch?
Comment 19 Dov Grobgeld 2006-12-26 20:39:36 UTC
Hello? Is dia still being maintained?
Comment 20 Hans Breuer 2007-09-08 12:45:49 UTC
Sorry for the delay, but the thing turned out to be more time cosuming than original thought. Based on your patch I've finally something working which also fulfill the requirement to import again what was exported. See also
http://mail.gnome.org/archives/dia-list/2007-September/msg00023.html

Comment 21 Hans Breuer 2007-09-08 16:46:09 UTC
2007-09-08  Hans Breuer  <hans@breuer.org>

	* lib/diasvgrenderer.[ch] plug-ins/shape/shape-export.c
	  plug-ins/svg/render_svg.c : based on analysis and patch by
	Dov Grobgeld the values written to SVGs are now scaled up, because
	many SVG interpreters don't cope very well with small values.
	The overall size of the image is kept by writing with and height in cm 
	but the viewBox scaled like the values in the file.
	For the Shape export the scale value is kept at 1.0 to avoid breaking
	Dia's Shape/SVG consumption. Fixes bug #316590
	
	* lib/dia_svg.[ch](dia_svg_parse_style) : allow to pass in user_scale	
	* plug-ins/svg/svg-import.c : implment some unit awareness and use it 
	to scale the input to Dia's internal cm. Adapt the user_scale with the
	viewBox as explained above. This not only gives almost correct 
	round-trip with Dia's own SVG writing, but also works better for the
	general case.
	* objects/custom/shape_info.c : adapt to API change

Comment 22 Lars Clausen 2007-10-27 08:50:27 UTC
*** Bug 116098 has been marked as a duplicate of this bug. ***
Comment 23 Hans Breuer 2008-07-19 08:22:57 UTC
*** Bug 543278 has been marked as a duplicate of this bug. ***