Draft: small optimizations of Draft's SVG output and fixed wrong dash scale
This commit is contained in:
parent
217a67ddb2
commit
3dd586b5be
|
@ -1719,6 +1719,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
any text). You can also supply an arbitrary projection vector. the
|
||||
scale parameter allows to scale linewidths down, so they are resolution-independant.'''
|
||||
import Part, DraftGeomUtils
|
||||
pathdata = []
|
||||
svg = ""
|
||||
linewidth = float(linewidth)/scale
|
||||
fontsize = (float(fontsize)/scale)/2
|
||||
|
@ -1726,6 +1727,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
linespacing = float(linespacing)/scale
|
||||
else:
|
||||
linespacing = 0.5
|
||||
#print obj.Label," line spacing ",linespacing,"scale ",scale
|
||||
pointratio = .75 # the number of times the dots are smaller than the arrow size
|
||||
plane = None
|
||||
if direction:
|
||||
|
@ -1745,12 +1747,19 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
def getLineStyle():
|
||||
"returns a linestyle"
|
||||
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
l = None
|
||||
if linestyle == "Dashed":
|
||||
return p.GetString("svgDashedLine","0.09,0.05")
|
||||
l = p.GetString("svgDashedLine","0.09,0.05")
|
||||
elif linestyle == "Dashdot":
|
||||
return p.GetString("svgDashdotLine","0.09,0.05,0.02,0.05")
|
||||
l = p.GetString("svgDashdotLine","0.09,0.05,0.02,0.05")
|
||||
elif linestyle == "Dotted":
|
||||
return p.GetString("svgDottedLine","0.02,0.02")
|
||||
l = p.GetString("svgDottedLine","0.02,0.02")
|
||||
if l:
|
||||
l = l.split(",")
|
||||
# scale dashes
|
||||
l = ",".join([str(float(d)/scale) for d in l])
|
||||
#print "lstyle ",l
|
||||
return l
|
||||
return "none"
|
||||
|
||||
def getProj(vec):
|
||||
|
@ -1785,6 +1794,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
w1.fixWire()
|
||||
egroups.append(Part.__sortEdges__(w1.Edges))
|
||||
for egroupindex, edges in enumerate(egroups):
|
||||
edata = ""
|
||||
vs=() #skipped for the first edge
|
||||
for edgeindex,e in enumerate(edges):
|
||||
previousvs = vs
|
||||
|
@ -1795,7 +1805,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
vs.reverse()
|
||||
if edgeindex == 0:
|
||||
v = getProj(vs[0].Point)
|
||||
svg += 'M '+ str(v.x) +' '+ str(v.y) + ' '
|
||||
edata += 'M '+ str(v.x) +' '+ str(v.y) + ' '
|
||||
else:
|
||||
if (vs[0].Point-previousvs[-1].Point).Length > 1e-6:
|
||||
raise ValueError('edges not ordered')
|
||||
|
@ -1841,13 +1851,13 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
== (e.LastParameter > e.FirstParameter)
|
||||
# == (e.Orientation == "Forward")
|
||||
for v in endpoints:
|
||||
svg += 'A %s %s %s %s %s %s %s ' % \
|
||||
edata += 'A %s %s %s %s %s %s %s ' % \
|
||||
(str(rx),str(ry),str(rot),\
|
||||
str(int(flag_large_arc)),\
|
||||
str(int(flag_sweep)),str(v.x),str(v.y))
|
||||
elif DraftGeomUtils.geomType(e) == "Line":
|
||||
v = getProj(vs[-1].Point)
|
||||
svg += 'L '+ str(v.x) +' '+ str(v.y) + ' '
|
||||
edata += 'L '+ str(v.x) +' '+ str(v.y) + ' '
|
||||
else:
|
||||
bspline=e.Curve.toBSpline(e.FirstParameter,e.LastParameter)
|
||||
if bspline.Degree > 3 or bspline.isRational():
|
||||
|
@ -1860,21 +1870,28 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
|||
if bezierseg.Degree>3: #should not happen
|
||||
raise AssertionError
|
||||
elif bezierseg.Degree==1:
|
||||
svg +='L '
|
||||
edata +='L '
|
||||
elif bezierseg.Degree==2:
|
||||
svg +='Q '
|
||||
edata +='Q '
|
||||
elif bezierseg.Degree==3:
|
||||
svg +='C '
|
||||
edata +='C '
|
||||
for pole in bezierseg.getPoles()[1:]:
|
||||
v = getProj(pole)
|
||||
svg += str(v.x) +' '+ str(v.y) + ' '
|
||||
edata += str(v.x) +' '+ str(v.y) + ' '
|
||||
else:
|
||||
print("Debug: one edge (hash ",e.hashCode(),\
|
||||
") has been discretized with parameter 0.1")
|
||||
for linepoint in bspline.discretize(0.1)[1:]:
|
||||
v = getProj(linepoint)
|
||||
svg += 'L '+ str(v.x) +' '+ str(v.y) + ' '
|
||||
if fill != 'none': svg += 'Z '
|
||||
edata += 'L '+ str(v.x) +' '+ str(v.y) + ' '
|
||||
if fill != 'none':
|
||||
edata += 'Z '
|
||||
if edata in pathdata:
|
||||
# do not draw a path on another identical path
|
||||
return ""
|
||||
else:
|
||||
svg += edata
|
||||
pathdata.append(edata)
|
||||
svg += '" '
|
||||
svg += 'stroke="' + stroke + '" '
|
||||
svg += 'stroke-width="' + str(linewidth) + ' px" '
|
||||
|
|
Loading…
Reference in New Issue
Block a user