View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0000591||FreeCAD||Bug||public||2012-02-07 14:59||2012-02-10 12:09|
|Fixed in Version||0.13|
|Summary||0000591: exported svg has incorrect units|
|Description||Sketches in FreeCAD are done in millimeters.|
Exporting a sketch as SVG produces an SVG that does not have units specified on its coordinates. By the SVG spec, this means the units default to "user units", aka "px".
This means the exported sketch has the wrong size.
The fix is to append "mm" to all the coordinates in the exported SVG.
To reproduce, open the attached circle-test.fcstd file in Freecad, select the 'circle' sketch (a single 10mm radius circle), and File->Export as SVG.
Open the SVG in inscape and hit Ctrl-A to select the circle. Find the "W" (width) and "H" (height) fields in the toolbar at the top and the Units selection next to them, and note that the selection is just over 20 px (it's a little bigger than 20 because of the thickness of the stroke).
Then change the units (in the toolbar at the top) from "px" to "mm", and note that the selection size is *not* 20x20 mm, as the sketch in FreeCAD specified. On my machine the selection is 5.680x5.680 mm.
This particular number is because FreeCAD incorrectly wrote an SVG with a 20x20 px circle, the default raster resolution is 90 dots per inch, so that 20x20 px is 0.222x0.222 inch, which is about 5.680x5.680 mm (modulo stroke thickness).
|Tags||No tags attached.|
There are elements like path and polyline which do not allow coordinates to have units. I can't see any explaination how to work with units and those elements in the same file (in the spec http://www.w3.org/TR/SVG/coords.html#Units )
"Note that use of px units or any other absolute unit identifiers can cause inconsistent visual results on different viewing environments since the size of "1px" may map to a different number of user units on different systems; thus, absolute units identifiers are only recommended for the ‘width’ and the ‘height’ on and situations where the content contains no transformations and it is desirable to specify values relative to the device pixel grid or to a particular real world unit size."
Therefore i suggest rather to multiply all the coordinates by 900/254 for export and 254/900 for import.
Yes, I see that you're right, the path element coordinates do not accept units. However, all the Basic Shapes do: <http://www.w3.org/TR/SVG/shapes.html>
"Mathematically, these shape elements are equivalent to a ‘path’ element that would construct the same shape."
Strange, that seems like a bug in the SVG spec.
Unfortunately there are things you can do (that we currently use) in a Path that you can't do with a Basic Shape. The one that sticks out is arcs that are just parts of (not complete) circles and ellipses. :-(
I've implemented your suggestion and tested it, and it works! Thanks!
Please review: http://git.highlab.com/?p=freecad.git;a=shortlog;h=refs/heads/scale-svg-export
Let me know if you want me to rework the patch in any way, or if you're happy with it, please pull:
git pull http://git.highlab.com/git/freecad.git scale-svg-export
Using a single <g transform="scale(3.5433070866141732)"> around all graphic elements might be better in case someone wants to read nice clean values in millimeter in the source code.
||I'll assign this to myself, and check ASAP. Seb Hoogen, I still need to pull your latest changes, maybe we can combine these 2?|
I've reworked my patches. Please consider pulling the svg-export-3 branch: http://git.highlab.com/?p=freecad.git;a=shortlog;h=refs/heads/svg-export-3
This latest version of the patchset:
* incorporates Yorik's Preference suggestion from the forum (http://forum.freecadweb.org/viewtopic.php?f=10&t=2226&p=16312#p16312). This means you can now select at run-time whether you want to export a picture (just like before), or an untranslated SVG, where all the coordinates are preserved from the sketch, which is more suitable for CAM work.
* incorporates Tag and Brian's viewBox suggestion from the svg-w3c list (http://lists.w3.org/Archives/Public/www-svg/2012Feb/0041.html). This means undimensioned path elements now have coordinates that correspond to millimeters.
Okay, the patch is included in master now. Thanks for your work!
Since all seems to work fine, I'll close this issue. Don't hesitate to reopen if needed.
|2012-02-07 14:59||seb_kuzminsky||New Issue|
|2012-02-07 14:59||seb_kuzminsky||File Added: circle-test.fcstd|
|2012-02-08 08:40||shoogen||Note Added: 0001618|
|2012-02-08 08:44||shoogen||Note Edited: 0001618|
|2012-02-08 11:06||shoogen||Note Edited: 0001618|
|2012-02-08 14:31||seb_kuzminsky||Note Added: 0001619|
|2012-02-08 15:01||seb_kuzminsky||Note Added: 0001620|
|2012-02-08 16:44||shoogen||Note Added: 0001621|
|2012-02-08 16:44||shoogen||Note Edited: 0001621|
|2012-02-08 16:47||shoogen||Note Edited: 0001621|
|2012-02-08 20:09||yorik||Status||new => assigned|
|2012-02-08 20:09||yorik||Assigned To||=> yorik|
|2012-02-08 20:11||yorik||Note Added: 0001622|
|2012-02-10 06:44||seb_kuzminsky||Note Added: 0001627|
|2012-02-10 12:09||yorik||Note Added: 0001630|
|2012-02-10 12:09||yorik||Status||assigned => closed|
|2012-02-10 12:09||yorik||Resolution||open => fixed|
|2012-02-10 12:09||yorik||Fixed in Version||=> 0.13|