Merge pull request #470 from anthrotype/namerecord-tostr

_n_a_m_e: add toStr method to NameRecord
This commit is contained in:
Cosimo Lupo 2016-01-19 13:30:54 +00:00
commit 6ea91c9e7a

View File

@ -139,10 +139,7 @@ class NameRecord(object):
return self.getEncoding(None) in ['utf_16_be', 'ucs2be', 'ascii', 'latin1']
def __str__(self):
try:
return self.toUnicode()
except UnicodeDecodeError:
return str(self.string)
return self.toStr(errors='backslashreplace')
def isUnicode(self):
return (self.platformID == 0 or
@ -212,6 +209,14 @@ class NameRecord(object):
"""
return tobytes(self.string, encoding=self.getEncoding(), errors=errors)
def toStr(self, errors='strict'):
if str == bytes:
# python 2
return self.toBytes(errors)
else:
# python 3
return self.toUnicode(errors)
def toXML(self, writer, ttFont):
try:
unistr = self.toUnicode()