Revert "Deprecate and ignore ttx’s --newline option"

This reverts commit 3042f129fc6012bd96668831b18d0926c634f7df.
This commit is contained in:
Cosimo Lupo 2021-08-03 10:00:01 +02:00
parent 3042f129fc
commit 01b0180ce1
2 changed files with 26 additions and 4 deletions

View File

@ -65,6 +65,9 @@ usage: ttx [options] inputfile1 [... inputfileN]
starting from 0.
--unicodedata <UnicodeData.txt> Use custom database file to write
character names in the comments of the cmap TTX output.
--newline <value> Control how line endings are written in the XML
file. It can be 'LF', 'CR', or 'CRLF'. If not specified, the
default platform-specific line endings are used.
Compile options:
-m Merge with TrueType-input-file: specify a TrueType or OpenType
@ -119,6 +122,7 @@ class Options(object):
ignoreDecompileErrors = True
bitmapGlyphDataFormat = 'raw'
unicodedata = None
newlinestr = "\n"
recalcTimestamp = None
flavor = None
useZopfli = False
@ -189,9 +193,11 @@ class Options(object):
elif option == "--newline":
validOptions = ('LF', 'CR', 'CRLF')
if value == "LF":
pass
elif value in validOptions:
print('WARNING: The "--newline" option is deprecated and will be ignored')
self.newlinestr = "\n"
elif value == "CR":
self.newlinestr = "\r"
elif value == "CRLF":
self.newlinestr = "\r\n"
else:
raise getopt.GetoptError(
"Invalid choice for --newline: %r (choose from %s)"
@ -261,7 +267,8 @@ def ttDump(input, output, options):
splitTables=options.splitTables,
splitGlyphs=options.splitGlyphs,
disassembleInstructions=options.disassembleInstructions,
bitmapGlyphDataFormat=options.bitmapGlyphDataFormat)
bitmapGlyphDataFormat=options.bitmapGlyphDataFormat,
newlinestr=options.newlinestr)
ttf.close()

View File

@ -452,6 +452,21 @@ def test_options_unicodedata():
assert tto.unicodedata == "UnicodeData.txt"
def test_options_newline_lf():
tto = ttx.Options([("--newline", "LF")], 1)
assert tto.newlinestr == "\n"
def test_options_newline_cr():
tto = ttx.Options([("--newline", "CR")], 1)
assert tto.newlinestr == "\r"
def test_options_newline_crlf():
tto = ttx.Options([("--newline", "CRLF")], 1)
assert tto.newlinestr == "\r\n"
def test_options_newline_invalid():
with pytest.raises(getopt.GetoptError):
ttx.Options([("--newline", "BOGUS")], 1)