importSVG: ignore the viewBox if not absolute untis are
given for width and height and sort edges before trying to make a wire
This commit is contained in:
parent
734dd0a386
commit
d567ba1dfe
|
@ -40,6 +40,7 @@ currently unsupported: use, image
|
|||
|
||||
import xml.sax, string, FreeCAD, os, math, re, Draft
|
||||
from draftlibs import fcvec
|
||||
from draftlibs import fcgeo
|
||||
from FreeCAD import Vector
|
||||
|
||||
try: import FreeCADGui
|
||||
|
@ -217,7 +218,7 @@ def getcolor(color):
|
|||
b = float(v[2]/255.0)
|
||||
return (r,g,b,0.0)
|
||||
|
||||
def getsize(length,mode='discard',base=None):
|
||||
def getsize(length,mode='discard',base=1):
|
||||
"""parses length values containing number and unit
|
||||
with mode 'discard': extracts a number from the given string (removes unit suffixes)
|
||||
with mode 'tuple': return number and unit as a tuple
|
||||
|
@ -254,13 +255,15 @@ def getsize(length,mode='discard',base=None):
|
|||
return float(number)
|
||||
elif mode == 'tuple':
|
||||
return float(number),unit
|
||||
elif mode == 'isabsolute':
|
||||
return unit in ['mm','cm','in','px','pt']
|
||||
elif mode == 'mm':
|
||||
return float(number)*tomm[unit]
|
||||
elif mode == 'css':
|
||||
if unit != '%':
|
||||
return float(number)*topx[unit]
|
||||
else:
|
||||
return float(number)*(base or 1)
|
||||
return float(number)*base
|
||||
|
||||
def makewire(path,checkclosed=False,donttry=False):
|
||||
'''try to make a wire out of the list of edges. If the 'Wire' functions fails or the wire is not
|
||||
|
@ -268,7 +271,8 @@ def makewire(path,checkclosed=False,donttry=False):
|
|||
#ToDo Do not catch all exceptions
|
||||
if not donttry:
|
||||
try:
|
||||
sh = Part.Wire(path)
|
||||
sh = Part.Wire(fcgeo.sortEdges(path))
|
||||
#sh = Part.Wire(path)
|
||||
isok = (not checkclosed) or sh.isClosed()
|
||||
except:# BRep_API:command not done
|
||||
isok = False
|
||||
|
@ -429,7 +433,9 @@ class svgHandler(xml.sax.ContentHandler):
|
|||
if name == 'svg':
|
||||
m=FreeCAD.Matrix()
|
||||
if 'width' in data and 'height' in data and \
|
||||
'viewBox' in data:
|
||||
'viewBox' in data and\
|
||||
getsize(attrs.getValue('width'),'isabsolute') and\
|
||||
getsize(attrs.getValue('height'),'isabsolute'):
|
||||
x0,y0,x1,y1=[float(n) for n in data['viewBox']]
|
||||
vbw = x1-x0
|
||||
vbh = y1-y0
|
||||
|
@ -716,7 +722,7 @@ class svgHandler(xml.sax.ContentHandler):
|
|||
path.append(seg)
|
||||
if path: #the path should be closed by now
|
||||
#sh=makewire(path,True)
|
||||
sh=makewire(path,donttry=True)
|
||||
sh=makewire(path,donttry=False)
|
||||
if self.fill: sh = Part.Face(sh)
|
||||
sh = self.applyTrans(sh)
|
||||
obj = self.doc.addObject("Part::Feature",pathname)
|
||||
|
|
Loading…
Reference in New Issue
Block a user