Skip to content

Commit

Permalink
Draft: temporary workaround for techdraw with no utf
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Nov 1, 2016
1 parent c0ca270 commit 253907d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Mod/Draft/Draft.py
Expand Up @@ -2015,14 +2015,25 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
if techdraw:
svg = ""
for i in range(len(text)):
t = text[i]
if not isinstance(t,unicode):
t = t.decode("utf8")
# temporary workaround for unsupported UTF8 in techdraw
try:
import unicodedata
except:
t = ""
print "Draft.getSVG: unicodedata not available"
else:
t = u"".join([c for c in unicodedata.normalize("NFKD",t) if not unicodedata.combining(c)]).encode("utf8")
svg += '<text fill="' + color +'" font-size="' + str(fontsize) + '" '
svg += 'style="text-anchor:'+anchor+';text-align:'+align.lower()+';'
svg += 'font-family:'+ fontname +'" '
svg += 'transform="rotate('+str(math.degrees(angle))
svg += ','+ str(base.x) + ',' + str(base.y+linespacing*i) + ') '
svg += 'translate(' + str(base.x) + ',' + str(base.y+linespacing*i) + ')" '
#svg += '" freecad:skip="1"'
svg += '>\n' + text[i] + '</text>\n'
svg += '>\n' + t + '</text>\n'
else:
svg = '<text fill="'
svg += color +'" font-size="'
Expand Down Expand Up @@ -2247,11 +2258,12 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
scale = obj.ViewObject.FirstLine.Value/obj.ViewObject.FontSize.Value
f1 = fontsize*scale
p2 = FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue())
p1 = p2.add(FreeCAD.Vector(obj.ViewObject.Proxy.header.translation.getValue().getValue()))
lspc = FreeCAD.Vector(obj.ViewObject.Proxy.header.translation.getValue().getValue())
p1 = p2.add(lspc)
j = obj.ViewObject.TextAlign
svg += getText(c,f1,n,a,getProj(p1),t1,linespacing,j,flip=True)
if t2:
svg += getText(c,fontsize,n,a,getProj(p2),t2,linespacing,j,flip=True)
svg += getText(c,fontsize,n,a,getProj(p1).add(FreeCAD.Vector(0,lspc.Length,0)),t2,linespacing,j,flip=True)

elif obj.isDerivedFrom('Part::Feature'):
if obj.Shape.isNull():
Expand Down

0 comments on commit 253907d

Please sign in to comment.