[Draft] [bug #6653] SVG import does not work with plain SVG

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

[Draft] [bug #6653] SVG import does not work with plain SVG

Post by uwestoehr »

As I wrote initially here: https://forum.freecadweb.org/viewtopic. ... 42#p582142
The SVG import has a bug:

- take this plain SVG of a box (created using Inkscape 1.1 and then saved as "Plain SVG"):
Box-plain-SVG.svg
(537 Bytes) Downloaded 51 times
and import it as SVG

result:
- you get an "error" about a missing DPI setting. However the settings are the SVG (as in the SVG specs it contains the mm settings).

Here is the issue: https://github.com/FreeCAD/FreeCAD/issues/6653
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [bug #6653] SVG import does not work with plain SVG

Post by Kunda1 »

1. Downloaded svg
2. opened SVG in inkscape and exported to plain SVG
3. opened FC
4. Imported as SVG
Result:
Screenshot_20220324_074912.png
Screenshot_20220324_074912.png (35.59 KiB) Viewed 1496 times
6. Chose 'No' to keep 90 dpi
Result: Import in to FC but outputs the following:

Code: Select all

07:49:35  This SVG file does not appear to have been produced by Inkscape. If it does not contain absolute units then a DPI setting will be used.
07:49:35  Do you wish to use 96 dpi? Choosing 'No' will use the older standard 90 dpi.
07:49:35  *** User specified 90.0 dpi ***
07:49:35  name: svg1061
07:49:35  done processing element 1
07:49:35  processing element 2: defs
07:49:35  existing group transform: [Matrix ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))]
07:49:35  name: defs1058
07:49:35  done processing element 2
07:49:35  processing element 3: g
07:49:35  existing group transform: [Matrix ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))]
07:49:35  name: layer1
07:49:35  done processing element 3
07:49:35  processing element 4: rect
07:49:35  existing group transform: [Matrix ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1)), Matrix ((1,0,0,-59.2622),(0,1,0,102.273),(0,0,1,0),(0,0,0,1))]
07:49:35  name: rect1144
07:49:35  applying group transform: Matrix ((1,0,0,-59.2622),(0,1,0,102.273),(0,0,1,0),(0,0,0,1))
07:49:35  applying group transform: Matrix ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))
07:49:35  Loading GUI of Part module... done
07:49:35  done processing element 4
07:49:35  closing group
07:49:35  closing group

Code: Select all

OS: Ubuntu Core 20 (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.20.28342 (Git)
Build type: Release
Branch: master
Hash: 05a8b67dce165745310b12de565c9dfb5f632292
Python 3.8.10, Qt 5.15.3, Coin 4.0.0, OCC 7.6.1
Locale: C/Default (C)
Installed mods: 
  * ToolbarStyle
  * Assembly4 0.11.10
  * stickframe
  * sheetmetal 0.2.49
  * Assembly3 0.11.0
  * Behave-Dark-Colors 0.0.1
  * Curves 0.3.0
  * Ship
  * BIM 2021.12.0
  * A2plus 0.4.55
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [bug #6653] SVG import does not work with plain SVG

Post by wandererfan »

This isn't a TD bug. "Insert SVG Symbol" accepts plain SVG. The error messages come when importing as geometry or importing to Drawing WB.

The messages are produced by Draft/importSVG.py.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [bug #6653] SVG import does not work with plain SVG

Post by uwestoehr »

wandererfan wrote: Thu Mar 24, 2022 1:18 pm The messages are produced by Draft/importSVG.py.
Thanks. I moved the topic to the Help forum and labeled it accordingly.

Inviting Roy since he knows Draft well.
Roy_043 wrote: .
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [Draft] [bug #6653] SVG import does not work with plain SVG

Post by Roy_043 »

I do not know the SVG format, nor the FreeCAD code involved. Maybe Yorik can assist.
yorik wrote: pinged by pinger macro
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: [Draft] [bug #6653] SVG import does not work with plain SVG

Post by yorik »

The "test" for inkscape DPI happens here: https://github.com/FreeCAD/FreeCAD/blob ... VG.py#L731
The way I see it, if no "inkscape:version" attribute is found in the <svg> element, the message is printed. Obviously if you saved it as plain SVG, that attribute is not there anymore, and the message is printed.

Now, in your file, only the svg box size is in mm. All the other values are unitless. That's a problem. The way I understand it, you can mix units in an SVG file. So can we assume that if the view box has units, all other values of the file are to be considered of the same unit?

Maybe instead of a yes/no dialog, we need to allow users to enter a custom value, so you could write "90 dots per inch" or "1 unit per mm" which would be applied to all unitless or px values
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [Draft] [bug #6653] SVG import does not work with plain SVG

Post by uwestoehr »

yorik wrote: Mon Mar 28, 2022 1:09 pm The "test" for inkscape DPI happens here: https://github.com/FreeCAD/FreeCAD/blob ... VG.py#L731
The way I see it, if no "inkscape:version" attribute is found in the <svg> element, the message is printed. Obviously if you saved it as plain SVG, that attribute is not there anymore, and the message is printed.
This is the issue. Inskscape is by definition just a SVG editor. Its specialties should not count. So no matter if there are Inkscape specifications or note, the SVG should be read according to the SVG specs.
yorik wrote: Mon Mar 28, 2022 1:09 pm Now, in your file, only the svg box size is in mm. All the other values are unitless. That's a problem. The way I understand it, you can mix units in an SVG file. So can we assume that if the view box has units, all other values of the file are to be considered of the same unit?
According to the SVG specs:
https://www.w3.org/TR/SVG2/coords.html# ... nateSystem
you declare the unit once. In the SVG specis they have this example

Code: Select all

<svg width="300px" height="100px" version="1.1"
all following numbers are unitless in the code but all take the unit "px".

in my SVG I have:

Code: Select all

<svg width="97.434448mm" height="99.698174mm" viewBox="0 0 97.434448 99.698174" version="1.1"...
therefore all further numbers take the unit mm
yorik wrote: Mon Mar 28, 2022 1:09 pm Maybe instead of a yes/no dialog, we need to allow users to enter a custom value, so you could write "90 dots per inch" or "1 unit per mm" which would be applied to all unitless or px values
There should not be a dialog at all, because the file defines the unit already according to the SVG specs.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: [Draft] [bug #6653] SVG import does not work with plain SVG

Post by Syres »

uwestoehr wrote: Mon Mar 28, 2022 3:20 pm There should not be a dialog at all, because the file defines the unit already according to the SVG specs.
What about those users who have old SVG files as per https://github.com/FreeCAD/FreeCAD/issues/5781 , surely there needs to be some consideration to not just the latest and greatest versions/specifications.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [Draft] [bug #6653] SVG import does not work with plain SVG

Post by uwestoehr »

Syres wrote: Mon Mar 28, 2022 4:13 pm What about those users who have old SVG files as per https://github.com/FreeCAD/FreeCAD/issues/5781 , surely there needs to be some consideration to not just the latest and greatest versions/specifications.
SVG 1.1 was released 10 years ago (sic!) ;)

My opinion is that we should be independent on certain 3rdparty programs like Inkscape. And since the Inkscape issue was fixed more than 4 years ago, I don't think we should care for it anymore. If you don't agree, then the dialog should only appear when users input an old Inkscape SVG.

As reference here are 3 versions of the same SVG:
Stegtest-plain-SVG.svg
(5.54 KiB) Downloaded 18 times
Stegtest-old-Inkscape.svg
(5.57 KiB) Downloaded 16 times
Stegtest-current-Inkscape.svg
(6.29 KiB) Downloaded 17 times
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: [Draft] [bug #6653] SVG import does not work with plain SVG

Post by adrianinsaval »

Syres wrote: Mon Mar 28, 2022 4:13 pm What about those users who have old SVG files as per https://github.com/FreeCAD/FreeCAD/issues/5781 , surely there needs to be some consideration to not just the latest and greatest versions/specifications.
I'm not sure I understand that issue, but Inkscape is free software, anyone can get it, if you have an old incorrect inkscape file, fix it in inkscape (I think by just oppening it already prompts you to fix the dpi) and then import in FreeCAD. IMO FreeCAD doesn't have the responsibility to support inkscape's old incorrect output. And regarding the example one user posted that specified a unit and no inkscape dpi, I think that's the kind of svg that uwe wants to add support.
Post Reply