Draft: Fix Unicode and UTF-8 encoding character behavior

This commit is contained in:
marioalexis
2021-09-10 17:41:19 -03:00
parent eb0b3f0b94
commit e2b3310277
4 changed files with 17 additions and 14 deletions

View File

@@ -1740,7 +1740,11 @@ class DraftToolBar:
"""this function sends the entered text to the active draft command
if enter has been pressed twice. Otherwise it blanks the line.
"""
self.sourceCmd.text = self.textValue.toPlainText().splitlines()
self.sourceCmd.text = self.textValue.toPlainText()\
.replace("\\","\\\\")\
.replace("\"","\\\"")\
.replace("\'","\\\'")\
.splitlines()
self.sourceCmd.createObject()
def displayPoint(self, point=None, last=None, plane=None, mask=None):

View File

@@ -86,19 +86,16 @@ class Text(gui_base_original.Creator):
def createObject(self):
"""Create the actual object in the current document."""
text_list = self.text
text_list = [text.replace("\"","\\\"") for text in text_list]
if not text_list:
self.finish()
return None
# If the last element is an empty string "" we remove it
if not text_list[-1]:
text_list.pop()
# For Python 2 we convert the string to unicode,
# Python 3 nothing needs to be done
if sys.version_info.major < 3:
u_list = [unicode(line) for line in text_list]
t_list = ['"' + str(line.encode("utf8")) + '"' for line in u_list]
else:
t_list = ['"' + line + '"' for line in text_list]
t_list = ['"' + line + '"' for line in text_list]
list_as_text = ", ".join(t_list)

View File

@@ -229,6 +229,7 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
self.text2d.string = self.text3d.string = "Label"
self.text2d.justification = coin.SoText2.RIGHT
self.text3d.justification = coin.SoAsciiText.RIGHT
self.font.name = utils.get_param("textfont")
switchnode = coin.SoSeparator()
switchnode.addChild(self.line)
@@ -310,10 +311,7 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
self.text2d.string.setValue("")
self.text3d.string.setValue("")
if sys.version_info.major >= 3:
_list = [l for l in obj.Text if l]
else:
_list = [l.encode("utf8") for l in obj.Text if l]
_list = [l for l in obj.Text if l]
self.text2d.string.setValues(_list)
self.text3d.string.setValues(_list)

View File

@@ -245,9 +245,13 @@ class ViewProviderText(ViewProviderDraftAnnotation):
def createObject(self):
import FreeCAD
import FreeCADGui
if hasattr(self,"Object"):
txt = [t.replace("\"","\\\"") for t in self.text]
txt = self.text
if not txt:
self.finish()
return None
# If the last element is an empty string "" we remove it
if not txt[-1]:
txt.pop()