From ce609addd0bb32db634f5c19216bc79eb406aedf Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 20 Oct 2016 17:22:12 +0100 Subject: [PATCH] [ttx] add --newline option to explicitly control line endings --- Lib/fontTools/ttx.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/ttx.py b/Lib/fontTools/ttx.py index e53ef6232..3d9daba64 100644 --- a/Lib/fontTools/ttx.py +++ b/Lib/fontTools/ttx.py @@ -61,6 +61,9 @@ usage: ttx [options] inputfile1 [... inputfileN] starting from 0. --unicodedata Use custom database file to write character names in the comments of the cmap TTX output. + --newline 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 @@ -128,6 +131,7 @@ class Options(object): ignoreDecompileErrors = True bitmapGlyphDataFormat = 'raw' unicodedata = None + newlinestr = None recalcTimestamp = False flavor = None useZopfli = False @@ -189,6 +193,18 @@ class Options(object): self.ignoreDecompileErrors = False elif option == "--unicodedata": 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": self.recalcTimestamp = True elif option == "--flavor": @@ -252,7 +268,8 @@ def ttDump(input, output, options): skipTables=options.skipTables, splitTables=options.splitTables, disassembleInstructions=options.disassembleInstructions, - bitmapGlyphDataFormat=options.bitmapGlyphDataFormat) + bitmapGlyphDataFormat=options.bitmapGlyphDataFormat, + newlinestr=options.newlinestr) ttf.close() @@ -312,7 +329,7 @@ def guessFileType(fileName): def parseOptions(args): rawOptions, files = getopt.getopt(args, "ld:o:fvqht:x:sim:z:baey:", ['unicodedata=', "recalc-timestamp", 'flavor=', 'version', - 'with-zopfli']) + 'with-zopfli', 'newline=']) options = Options(rawOptions, len(files)) jobs = []