svg export issues

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: svg export issues

Post by yorik »

Looks like it's solved indeed. I'll pull the changes, and add the info to the wiki
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: svg export issues

Post by NormandC »

Thanks for your help guys,

But it's still not solved from my end. I changed my A template to have this:

Code: Select all

width="279.4mm"
height="215.9mm"
viewBox="0 0 279.4 215.9"
And removed these lines from the <sodipodi:namedview> tag:

Code: Select all

inkscape:zoom="2.8723143"
inkscape:cx="198.88572"
inkscape:cy="94.621281"
And my Print preview from FreeCAD still looks like the one I posted.

EDIT: just tried with the revised A4_Landscape.svg template, and the Print Preview is now fine. So I guess there's something wrong with my custom template. Would that be because un-rounded units are not allowed in viewBox?
2nd EDIT: nope, just tried it with viewBox="0 0 279 216", no change. I'm stomped. :(
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: svg export issues

Post by NormandC »

I don't understand. If I export my Drawing page to svg and open it in Inkscape, then it recognizes its page size as US letter, and printing is OK.

But in FreeCAD's Print preview, the template still won't scale correctly to the page, while the A_Landscape.svg template revised by shoogen does. :?:
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: svg export issues

Post by shoogen »

In src/Mod/Drawing/App/DrawingExport.cpp the angle of an arc is calculated by

Code: Select all

double a = v3.DotCross(v1,v2);
Lines 177 and
To determine the parameters of an arc I need to use 2D trigonometrics in order to get the quadrant/sign of the angle (like arctan2) right (in importSVG.py).
I thought seb_kuzminsky ran into this, but it turned out that i was wrong.
But I'm courius about this.

EDIT
I think that the documentation i found on dotCross is broken. A tripple scalar product doesn't make any sense.
If it does (0,0,1) * (v1 x v2). Than this would not return an angle, but -1,1 for the orientation. (as needed)
Last edited by shoogen on Sun Feb 12, 2012 6:23 pm, edited 1 time in total.
seb_kuzminsky
Posts: 11
Joined: Thu Feb 09, 2012 5:41 am

Re: svg export issues

Post by seb_kuzminsky »

Here's a sketch that produces incorrect arcs when exported to svg.

The raw exported svg is here (Sourceforge wouldn't let me attach the svg to this post): http://highlab.com/~seb/apogaea/longitu ... ported.svg

Here's the manually corrected svg: http://highlab.com/~seb/apogaea/longitude-fixed.svg

I think the problem is in Draft.py, line 1082. The exporter just blithely sets the arc flags to "0 1", without consulting the geometry it's exporting.
Attachments
longitude.fcstd
(5.93 KiB) Downloaded 56 times
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: svg export issues

Post by NormandC »

normandc wrote:I don't understand. If I export my Drawing page to svg and open it in Inkscape, then it recognizes its page size as US letter, and printing is OK.

But in FreeCAD's Print preview, the template still won't scale correctly to the page, while the A_Landscape.svg template revised by shoogen does. :?:
Nevermind that.

For a reason I can't understand, in the Print Preview dialog, if I click on the Page configuration button, I see in the new dialog that the page is correctly recognized as US letter; changing nothing and clicking OK closes the dialog, returns to the Preview window, and the content automatically resizes correctly to fit the page. Now I need to print it out to check that the scale is indeed correct.

Thank you shoogen for this fix in the template, it has the added bonus that now the svg shows a lot bigger when opened in Firefox or an image viewer.

@ seb_kuzminsky: in both your svg, most of the profile is outside the document dimensions. I can only view their content in Eye of GNOME, as in Inkscape or Firefox I only see white space.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: svg export issues

Post by yorik »

normandc wrote:@ seb_kuzminsky: in both your svg, most of the profile is outside the document dimensions. I can only view their content in Eye of GNOME, as in Inkscape or Firefox I only see white space.
Yes, that's the "white-on-white" problem I must fix one day...
For the arc flags problems we must also make a better code.
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: svg export issues

Post by shoogen »

yorikvanhavre wrote:For the arc flags problems we must also make a better code.

Code: Select all

edge=...
drawing_plane_normal=FreeCAD.Vector(0,0,1) #be careful when doing (other) projections!

flag_large_arc = ((edge.ParameterRange[1]-edge.ParameterRange[0]) / math.pi) % 2) > 1
flag_sweep = edge.Curve.Axis*drawing_plane_normal < 0
Note:
sweepflag <==> arc is travelled clockwise (negative) in FreeCAD coordinate system <==> arc is travelled counter-clockwise (positive) in SVG coordinate system
j-dowsett
Posts: 210
Joined: Wed Sep 07, 2011 9:37 am

Re: svg export issues

Post by j-dowsett »

Normandc - could you post your A sized template please? This change to the template width/height format has introduced a bug to ortho-gui and I'd like to check my fix. I can just rough up a random-sized template but be nice to check it with a real one too!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: svg export issues

Post by yorik »

Thanks for your code Seb Hoogen... I just implemented it, slightly modified (by empirical testing). http://free-cad.git.sourceforge.net/git ... 3b1439ed19
As far as I tested it works great!
Post Reply