Fix #1947 non-ASCII in file path

- this also fixes file path part of #3139
- this needs work for Py3
This commit is contained in:
WandererFan
2017-12-06 19:49:33 -05:00
parent ccd04f3c9b
commit 06eeef4281
2 changed files with 14 additions and 8 deletions

View File

@@ -5973,7 +5973,11 @@ class _ShapeString(_DraftObject):
if obj.String and obj.FontFile:
if obj.Placement:
plm = obj.Placement
CharList = Part.makeWireString(obj.String,obj.FontFile,obj.Size,obj.Tracking)
ff8 = obj.FontFile.encode('utf8') # 1947 accents in filepath
# TODO: change for Py3?? bytes?
# Part.makeWireString uses FontFile as char* string
# CharList = Part.makeWireString(obj.String,obj.FontFile,obj.Size,obj.Tracking)
CharList = Part.makeWireString(obj.String,ff8,obj.Size,obj.Tracking)
if len(CharList) == 0:
msg(translate("draft","ShapeString: string has no wires\n"), 'warning')
return
@@ -5981,7 +5985,8 @@ class _ShapeString(_DraftObject):
# test a simple letter to know if we have a sticky font or not
sticky = False
testWire = Part.makeWireString("L",obj.FontFile,obj.Size,obj.Tracking)[0][0]
# testWire = Part.makeWireString("L",obj.FontFile,obj.Size,obj.Tracking)[0][0]
testWire = Part.makeWireString("L",ff8,obj.Size,obj.Tracking)[0][0]
if testWire.isClosed:
try:
testFace = Part.Face(testWire)

View File

@@ -1437,17 +1437,18 @@ class DraftToolBar:
dialogCaption,
dialogDir,
dialogFilter)
# print(fname)
#fname = str(fname.toUtf8()) # QString to PyString
fname = utf8_decode(fname[0])
# print("debug: D_G DraftToolBar.pickFile type(fname): " str(type(fname)))
# fname = utf8_decode(fname[0]) # 1947: utf8_decode fails ('ascii' codec can't encode character)
# when fname[0] contains accented chars
fname = fname[0].encode('utf8') #TODO: this needs changing for Py3??
# accented chars cause "UnicodeEncodeError" failure in DraftGui.todo without
# .encode('utf8')
except Exception as e:
FreeCAD.Console.PrintMessage("DraftGui.pickFile: unable to select a font file.")
print(type(e))
print(e.args)
else:
if fname:
if fname[0]:
self.FFileValue.setText(fname)
self.sourceCmd.validFFile(fname)
else: