Labels are not exported in svg, dimensions are offsetted

Discussions about the development of the TechDraw workbench
reox
Posts: 882
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Labels are not exported in svg, dimensions are offsetted

Postby reox » Sat Feb 24, 2018 7:33 pm

I noticed that the Annotation labels are not exported in the SVG and also hidden when you click "Turn View frames on or off".
2018-02-24-203204_265x134_scrot.png
2018-02-24-203204_265x134_scrot.png (3.63 KiB) Viewed 1068 times
2018-02-24-203210_277x117_scrot.png
2018-02-24-203210_277x117_scrot.png (2.13 KiB) Viewed 1068 times
I think this is not the intended behaviour?

there is also something with the dimensions: In FreeCAD they look fine (I think they should be a little more above the line, because the comma is intersecting the line) but in the SVG the whole number intersects the line.
The second image was created with Inkscape:
2018-02-24-203503_405x190_scrot.png
2018-02-24-203503_405x190_scrot.png (5.8 KiB) Viewed 1063 times
2018-02-24-203512_738x330_scrot.png
2018-02-24-203512_738x330_scrot.png (11.09 KiB) Viewed 1063 times

Code: Select all

OS: Debian GNU/Linux testing (buster)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13312 (Git)
Build type: None
Branch: master
Hash: f445ace40c6e9126d9e3512ca73c6b294c84b24e
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: German/Austria (de_AT)
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Labels are not exported in svg, dimensions are offsetted

Postby wandererfan » Tue Feb 27, 2018 3:07 am

reox wrote:
Sat Feb 24, 2018 7:33 pm
I noticed that the Annotation labels are not exported in the SVG and also hidden when you click "Turn View frames on or off".
I think this is not the intended behaviour?
This is intentional. The View labels are not printed by default. This is a left over from when the View Name was displayed (ie View001) I think. You can use KeepLabel property to override.
KeepLabels.png
KeepLabels.png (11.56 KiB) Viewed 969 times
reox wrote:
Sat Feb 24, 2018 7:33 pm
there is also something with the dimensions: In FreeCAD they look fine (I think they should be a little more above the line, because the comma is intersecting the line) but in the SVG the whole number intersects the line.
Text exported to Svg isn't scaled properly. It hasn't worked quite right since the export to svg function was added. I'll take another look at it, but I seem to recall that a lot of hacks were tried, but none of them ever worked right for all cases.
reox
Posts: 882
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Labels are not exported in svg, dimensions are offsetted

Postby reox » Tue Feb 27, 2018 9:23 am

wandererfan wrote:
Tue Feb 27, 2018 3:07 am
This is intentional. The View labels are not printed by default. This is a left over from when the View Name was displayed (ie View001) I think. You can use KeepLabel property to override.
KeepLabels.png
Ohh now I understand - do'h :oops:
I saw this option but thought it did something else...
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Labels are not exported in svg, dimensions are offsetted

Postby wandererfan » Wed Feb 28, 2018 7:07 pm

reox wrote:
Sat Feb 24, 2018 7:33 pm
there is also something with the dimensions: In FreeCAD they look fine (I think they should be a little more above the line, because the comma is intersecting the line) but in the SVG the whole number intersects the line.
This is a note to some future programmer who looks into fixing this issue with Svg Page Export.

All/most text on a drawing pages is displaced and shrunken on export to Svg.

QSvgGenerator appears to use the system default font for all text. It tries to adjust the size and position of the text using svg transform matrix. This does not work very well when the default and the font specified in the FC document are dissimilar (ex Ubuntu vs osifont).

To fix this, we could hide all the text in the drawing and insert correct text clauses into the Template's Svg code. Text in Template survives export via QSvgGenerator. New code to hide dimension text and captions would be needed.
tpavlicek
Posts: 27
Joined: Sun Jan 07, 2018 2:15 am

Re: Labels are not exported in svg, dimensions are offsetted

Postby tpavlicek » Mon May 27, 2019 9:15 pm

Hello,

I will revive this thread . I have also noticed the dimension texts are shifted once the drawing is exported to SVG. After spending some time trying to figure out why, I have found the SVG export "magic" transformation does not work properly. As we are all rather technically oriented, I am proposing a standard engineering approach instead of magic ;)

First of all, we must be sure the font size on screen is correct and matches the size of other elements, namely part dimensions, line thickness, dimension arrows, etc. For this we need to properly convert the (user configured) font size in mm to font point size on the logical screen device. The correct formula goes like this:

fontPointSize = ((fontSizeInMM*MMtoPixels)/logicalDPI)*inchToPoints

logicalDPI is provided by the window we are using to paint on, inchToPoints is always 72, MMtoPixels is in FreeCAD source code currently set to 10.0. Once the font size is correct, it is enough to set SVG resolution to the same DPI the screen device reports, usually 96. No black magic involved, just simple as that.

I have created a pull request with the fix, hopefully You will find it useful and suitable for merge.

The downside of this fix is the default font sizes must be adjusted and the users will need to update their font size configuration, otherwise the (currently default) 3.5mm sized font becomes quite hard to read. Nevertheless this is correct, because the full height is reserved only for the tallest font glyphs like | (pipe character) or ▯ (non-existing glyph placeholder).

Kind regards,

Tomas
User avatar
Kunda1
Posts: 8410
Joined: Thu Jan 05, 2017 9:03 pm

Re: Labels are not exported in svg, dimensions are offsetted

Postby Kunda1 » Mon May 27, 2019 11:37 pm

Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Labels are not exported in svg, dimensions are offsetted

Postby wandererfan » Tue May 28, 2019 2:26 am

tpavlicek wrote:
Mon May 27, 2019 9:15 pm
I have created a pull request with the fix, hopefully You will find it useful and suitable for merge.
I am so happy to see this one fixed - git commit fad4db3300. :D

Thank you, Tomas.