[ttx] add --newline option to explicitly control line endings

This commit is contained in:
Cosimo Lupo 2016-10-20 17:22:12 +01:00
parent 2552d224a3
commit ce609addd0

View File

@ -61,6 +61,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
@ -128,6 +131,7 @@ class Options(object):
ignoreDecompileErrors = True ignoreDecompileErrors = True
bitmapGlyphDataFormat = 'raw' bitmapGlyphDataFormat = 'raw'
unicodedata = None unicodedata = None
newlinestr = None
recalcTimestamp = False recalcTimestamp = False
flavor = None flavor = None
useZopfli = False useZopfli = False
@ -189,6 +193,18 @@ class Options(object):
self.ignoreDecompileErrors = False self.ignoreDecompileErrors = False
elif option == "--unicodedata": elif option == "--unicodedata":
self.unicodedata = value self.unicodedata = value
elif option == "--newline":
validOptions = ('LF', 'CR', 'CRLF')
if value == "LF":
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)"
% (value, ", ".join(map(repr, validOptions))))
elif option == "--recalc-timestamp": elif option == "--recalc-timestamp":
self.recalcTimestamp = True self.recalcTimestamp = True
elif option == "--flavor": elif option == "--flavor":
@ -252,7 +268,8 @@ def ttDump(input, output, options):
skipTables=options.skipTables, skipTables=options.skipTables,
splitTables=options.splitTables, splitTables=options.splitTables,
disassembleInstructions=options.disassembleInstructions, disassembleInstructions=options.disassembleInstructions,
bitmapGlyphDataFormat=options.bitmapGlyphDataFormat) bitmapGlyphDataFormat=options.bitmapGlyphDataFormat,
newlinestr=options.newlinestr)
ttf.close() ttf.close()
@ -312,7 +329,7 @@ def guessFileType(fileName):
def parseOptions(args): def parseOptions(args):
rawOptions, files = getopt.getopt(args, "ld:o:fvqht:x:sim:z:baey:", rawOptions, files = getopt.getopt(args, "ld:o:fvqht:x:sim:z:baey:",
['unicodedata=', "recalc-timestamp", 'flavor=', 'version', ['unicodedata=', "recalc-timestamp", 'flavor=', 'version',
'with-zopfli']) 'with-zopfli', 'newline='])
options = Options(rawOptions, len(files)) options = Options(rawOptions, len(files))
jobs = [] jobs = []