diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index be96ac60a..853385fc8 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -1182,21 +1182,17 @@ def draftify(objectslist,makeblock=False): return newobjlist[0] return newobjlist -def getSVG(obj,modifier=100,textmodifier=100,fillstyle="shape color",direction=None): - '''getSVG(object,[modifier],[textmodifier],[fillstyle],[direction]): - returns a string containing a SVG representation of the given object. the modifier attribute - specifies a scale factor for linewidths in %, and textmodifier specifies - a scale factor for texts, in % (both default = 100). You can also supply - an arbitrary projection vector.''' +def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direction=None): + '''getSVG(object,[scale], [linewidth],[fontsize],[fillstyle],[direction]): + returns a string containing a SVG representation of the given object, + with the given linewidth and fontsize (used if the given object contains + 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 from draftlibs import fcgeo svg = "" - tmod = ((textmodifier-100)/2)+100 - if tmod == 0: tmod = 0.01 - modifier = 200-modifier - if modifier == 0: modifier = 0.01 - pmod = (200-textmodifier)/20 - if pmod == 0: pmod = 0.01 + linewidth = linewidth/scale + fontsize = (fontsize/scale)/2 plane = None if direction: if direction != Vector(0,0,0): @@ -1269,8 +1265,8 @@ def getSVG(obj,modifier=100,textmodifier=100,fillstyle="shape color",direction=N if fill != 'none': svg += 'Z' svg += '" ' svg += 'stroke="' + stroke + '" ' - svg += 'stroke-width="' + str(width) + ' px" ' - svg += 'style="stroke-width:'+ str(width) + svg += 'stroke-width="' + str(linewidth) + ' px" ' + svg += 'style="stroke-width:'+ str(linewidth) svg += ';stroke-miterlimit:4' svg += ';stroke-dasharray:' + lstyle svg += ';fill:' + fill + '"' @@ -1284,8 +1280,8 @@ def getSVG(obj,modifier=100,textmodifier=100,fillstyle="shape color",direction=N svg += '" cy="' + str(cen.y) svg += '" r="' + str(rad)+'" ' svg += 'stroke="' + stroke + '" ' - svg += 'stroke-width="' + str(width) + ' px" ' - svg += 'style="stroke-width:'+ str(width) + svg += 'stroke-width="' + str(linewidth) + ' px" ' + svg += 'style="stroke-width:'+ str(linewidth) svg += ';stroke-miterlimit:4' svg += ';stroke-dasharray:' + lstyle svg += ';fill:' + fill + '"' @@ -1329,35 +1325,36 @@ def getSVG(obj,modifier=100,textmodifier=100,fillstyle="shape color",direction=N svg += 'L '+str(p4.x)+' '+str(p4.y)+'" ' svg += 'fill="none" stroke="' svg += getrgb(obj.ViewObject.LineColor) + '" ' - svg += 'stroke-width="' + str(obj.ViewObject.LineWidth/modifier) + ' px" ' - svg += 'style="stroke-width:'+ str(obj.ViewObject.LineWidth/modifier) + svg += 'stroke-width="' + str(linewidth) + ' px" ' + svg += 'style="stroke-width:'+ str(linewidth) svg += ';stroke-miterlimit:4;stroke-dasharray:none" ' svg += 'freecad:basepoint1="'+str(p1.x)+' '+str(p1.y)+'" ' svg += 'freecad:basepoint2="'+str(p4.x)+' '+str(p4.y)+'" ' svg += 'freecad:dimpoint="'+str(p2.x)+' '+str(p2.y)+'"' svg += '/>\n' svg += '\n' + #svg +='scale('+str(tmod/2000)+','+str(-tmod/2000)+')' + svg += 'scale(1,-1) ' + svg += '">\n' for l in obj.LabelText: svg += ''+l+'\n' svg += '\n' @@ -1388,7 +1387,6 @@ def getSVG(obj,modifier=100,textmodifier=100,fillstyle="shape color",direction=N lorig = getLineStyle(obj) name = obj.Name stroke = getrgb(obj.ViewObject.LineColor) - width = obj.ViewObject.LineWidth/modifier fill = 'none' invpl = obj.Placement.inverse() n = 0 @@ -1432,7 +1430,6 @@ def getSVG(obj,modifier=100,textmodifier=100,fillstyle="shape color",direction=N stroke = "none" else: stroke = getrgb(obj.ViewObject.LineColor) - width = obj.ViewObject.LineWidth/modifier if len(obj.Shape.Vertexes) > 1: wiredEdges = [] @@ -2521,19 +2518,18 @@ class _Polygon: class _DrawingView: def __init__(self, obj): - obj.addProperty("App::PropertyVector","Direction","Shape view","Projection direction") - obj.addProperty("App::PropertyFloat","LinewidthModifier","Drawing view","Modifies the linewidth of the lines inside this object") - obj.addProperty("App::PropertyFloat","TextModifier","Drawing view","Modifies the size of the texts inside this object") + obj.addProperty("App::PropertyVector","Direction","Shape View","Projection direction") + obj.addProperty("App::PropertyFloat","LineWidth","Drawing View","The width of the lines inside this object") + obj.addProperty("App::PropertyFloat","FontSize","Drawing View","The size of the texts inside this object") obj.addProperty("App::PropertyLink","Source","Base","The linked object") - obj.addProperty("App::PropertyEnumeration","FillStyle","Drawing view","Shape Fill Style") + obj.addProperty("App::PropertyEnumeration","FillStyle","Drawing View","Shape Fill Style") fills = ['shape color'] for f in FreeCAD.svgpatterns.keys(): fills.append(f) obj.FillStyle = fills - obj.Proxy = self - obj.LinewidthModifier = 100 - obj.TextModifier = 100 + obj.LineWidth = 0.35 + obj.FontSize = 12 self.Type = "DrawingView" def execute(self, obj): @@ -2541,12 +2537,12 @@ class _DrawingView: obj.ViewResult = self.updateSVG(obj) def onChanged(self, obj, prop): - if prop in ["X","Y","Scale","LinewidthModifier","TextModifier","FillStyle","Direction"]: + if prop in ["X","Y","Scale","LineWidth","FontSize","FillStyle","Direction"]: obj.ViewResult = self.updateSVG(obj) def updateSVG(self, obj): "encapsulates a svg fragment into a transformation node" - svg = getSVG(obj.Source,obj.LinewidthModifier,obj.TextModifier,obj.FillStyle,obj.Direction) + svg = getSVG(obj.Source,obj.Scale,obj.LineWidth,obj.FontSize,obj.FillStyle,obj.Direction) result = '' result += '