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

View File

@ -452,6 +452,21 @@ def test_options_unicodedata():
assert tto.unicodedata == "UnicodeData.txt" 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(): def test_options_newline_invalid():
with pytest.raises(getopt.GetoptError): with pytest.raises(getopt.GetoptError):
ttx.Options([("--newline", "BOGUS")], 1) ttx.Options([("--newline", "BOGUS")], 1)