DPI setting during SVG import results in small (or big) error

If you are having problems with QCAD, post here. Please report bugs through our Bug Tracker instead.

Always attach your original DXF or DWG file and mentions your QCAD version and the platform you are on.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
0xdeadbeef
Active Member
Posts: 31
Joined: Sun Aug 10, 2014 11:58 am

DPI setting during SVG import results in small (or big) error

Post by 0xdeadbeef » Wed Oct 07, 2020 2:19 pm

I have this SVG
mister_laser_case_forprint.svg
(20.63 KiB) Downloaded 336 times
which was obviously exported from Affinity designer (the AF document was included) and then post-processed with Inkscape. When I open this file in Inkscape, it's correctly scaled. I.e. the three rectangles above the "MiSTer FPGA" logo are exactly 10x4mm. Looking at the document properties, this document uses a resolution of 96dpi.
Now, when I import this document into QCAD (Pro 3.24.2.0, Win10) with 96 "pixels per inch", the three boxes are sized 10.000005x4.000001mm. Admittedly, it's not a large error, but still.

By chance, I also own Affinity Designer, so I tried to export an SVG directly from there with a 96dpi setting.
mister_laser_case_af.svg
(15.72 KiB) Downloaded 359 times
Again, when I open this in Inkscape, the three boxes are scaled correctly and Inkscape shows 96dpi under document properties.
Now, when importing this file with the 96dpi setting into QCAD, the 10mm lines become 1.259437mm which is a weird factor of about 7.94 (*). So I need to set the "pixels per inch" to roughly 12.0905952 to get the (somewhat) correct scale.

I guess the SVG import filter doesn't support all possible tags and I'd consider post-processing in Inkscape to be OKish but I'm concerned that even then the scale is slightly off.

(*) Don't know if this is by chance, but 300/96*2.54 = 7.9375. So the weird factor could result from a DPI mix-up combined with using millimeters instead of inches and some rounding errors. Or something like that.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: DPI setting during SVG import results in small (or big) error

Post by andrew » Mon Oct 12, 2020 5:10 pm

Let's have a look at one of those rectangles. After isolating and ungrouping it in Inkscape, it's stored in SVG as:

Code: Select all

<rect
     x="541.56116"
     y="518.22217"
     width="15.118115"
     height="37.795292"
     style="fill:#5a7cba;stroke-width:0.12288976"
     id="rect36" />
96 dpi means:

Code: Select all

96 units (pixels) equal 1 inch
or:

Code: Select all

96 pixels = 25.4 mm
Now, you can easily deduce that:

Code: Select all

15.118115 pixels -> 4.000001260416667 mm
37.795292 pixels -> 10.000004341666667 mm
SVG / Inkscape are not more accurate than that I'm afraid.

The second file uses a notation that is not recognised by QCAD (width in %).

0xdeadbeef
Active Member
Posts: 31
Joined: Sun Aug 10, 2014 11:58 am

Re: DPI setting during SVG import results in small (or big) error

Post by 0xdeadbeef » Mon Oct 12, 2020 5:48 pm

OK, thanks for having a look.

Post Reply

Return to “QCAD Troubleshooting and Problems”