diff --git a/Lib/fontTools/misc/xmlWriter.py b/Lib/fontTools/misc/xmlWriter.py index c846f4141..ddc2fdb3e 100644 --- a/Lib/fontTools/misc/xmlWriter.py +++ b/Lib/fontTools/misc/xmlWriter.py @@ -4,7 +4,6 @@ from fontTools.misc.py23 import byteord, strjoin, tobytes, tostr import sys import os import string -import warnings INDENT = " " @@ -38,12 +37,10 @@ class XMLWriter(object): self.file.write('') self.totype = tostr self.indentwhite = self.totype(indentwhite) - if newlinestr != "\n": - warnings.warn( - 'Setting "newlinestr" is deprecated and will be ignored.', - DeprecationWarning, - ) - self.newlinestr = self.totype("\n") + if newlinestr is None: + self.newlinestr = self.totype(os.linesep) + else: + self.newlinestr = self.totype(newlinestr) self.indentlevel = 0 self.stack = [] self.needindent = 1 diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index 51ea85105..e3bbddb9c 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -159,7 +159,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable): suffix=ext) existingGlyphFiles.add(glyphPath.lower()) glyphWriter = xmlWriter.XMLWriter( - glyphPath, idlefunc=writer.idlefunc) + glyphPath, idlefunc=writer.idlefunc, + newlinestr=writer.newlinestr) glyphWriter.begintag("ttFont", ttLibVersion=version) glyphWriter.newline() glyphWriter.begintag("glyf") diff --git a/Lib/fontTools/ttLib/ttFont.py b/Lib/fontTools/ttLib/ttFont.py index ba58e58d9..5ccd182cd 100644 --- a/Lib/fontTools/ttLib/ttFont.py +++ b/Lib/fontTools/ttLib/ttFont.py @@ -271,7 +271,8 @@ class TTFont(object): tag = tables[i] if splitTables: tablePath = fileNameTemplate % tagToIdentifier(tag) - tableWriter = xmlWriter.XMLWriter(tablePath) + tableWriter = xmlWriter.XMLWriter(tablePath, + newlinestr=writer.newlinestr) tableWriter.begintag("ttFont", ttLibVersion=version) tableWriter.newline() tableWriter.newline() diff --git a/Tests/misc/xmlWriter_test.py b/Tests/misc/xmlWriter_test.py index e1b92894a..7b9894c66 100644 --- a/Tests/misc/xmlWriter_test.py +++ b/Tests/misc/xmlWriter_test.py @@ -115,7 +115,7 @@ class TestXMLWriter(unittest.TestCase): writer.write("world") writer.newline() - linesep = tobytes('\n') + linesep = tobytes(os.linesep) if nls is None else tobytes(nls) self.assertEqual( header + linesep + b"hello" + linesep + b"world" + linesep, diff --git a/Tests/ttLib/tables/_n_a_m_e_test.py b/Tests/ttLib/tables/_n_a_m_e_test.py index 196904077..8e8297049 100644 --- a/Tests/ttLib/tables/_n_a_m_e_test.py +++ b/Tests/ttLib/tables/_n_a_m_e_test.py @@ -354,7 +354,7 @@ class NameRecordTest(unittest.TestCase): writer = XMLWriter(BytesIO()) name.toXML(writer, ttFont=None) xml = writer.file.getvalue().decode("utf_8").strip() - return xml.split("\n")[1:] + return xml.split(writer.newlinestr.decode("utf_8"))[1:] def test_toXML_utf16be(self): name = makeName("Foo Bold", 111, 0, 2, 7)