diff --git a/Lib/fontTools/ttx.py b/Lib/fontTools/ttx.py index a785325e4..44f76dff3 100644 --- a/Lib/fontTools/ttx.py +++ b/Lib/fontTools/ttx.py @@ -77,6 +77,7 @@ usage: ttx [options] inputfile1 [... inputfileN] file as-is. --recalc-timestamp Set font 'modified' timestamp to current time. By default, the modification time of the TTX file will be used. + --no-recalc-timestamp Keep the original font 'modified' timestamp. --flavor Specify flavor of output font file. May be 'woff' or 'woff2'. Note that WOFF2 requires the Brotli Python extension, available at https://github.com/google/brotli @@ -123,7 +124,7 @@ class Options(object): bitmapGlyphDataFormat = 'raw' unicodedata = None newlinestr = None - recalcTimestamp = False + recalcTimestamp = None flavor = None useZopfli = False @@ -204,6 +205,8 @@ class Options(object): % (value, ", ".join(map(repr, validOptions)))) elif option == "--recalc-timestamp": self.recalcTimestamp = True + elif option == "--no-recalc-timestamp": + self.recalcTimestamp = False elif option == "--flavor": self.flavor = value elif option == "--with-zopfli": @@ -282,7 +285,7 @@ def ttCompile(input, output, options): allowVID=options.allowVID) ttf.importXML(input) - if not options.recalcTimestamp and 'head' in ttf: + if options.recalcTimestamp is None and 'head' in ttf: # use TTX file modification time for head "modified" timestamp mtime = os.path.getmtime(input) ttf['head'].modified = timestampSinceEpoch(mtime) diff --git a/Tests/ttx/ttx_test.py b/Tests/ttx/ttx_test.py index ceb7abd38..eb5816ba8 100644 --- a/Tests/ttx/ttx_test.py +++ b/Tests/ttx/ttx_test.py @@ -476,6 +476,11 @@ def test_options_recalc_timestamp(): assert tto.recalcTimestamp is True +def test_options_recalc_timestamp(): + tto = ttx.Options([("--no-recalc-timestamp", "")], 1) + assert tto.recalcTimestamp is False + + def test_options_flavor(): tto = ttx.Options([("--flavor", "woff")], 1) assert tto.flavor == "woff" @@ -789,6 +794,14 @@ def test_ttcompile_timestamp_calcs(inpath, outpath1, outpath2, tmpdir): ttf = TTFont(str(outttf2)) assert ttf["head"].modified > epochtime + # --no-recalc-timestamp will keep original timestamp + options.recalcTimestamp = False + ttx.ttCompile(inttx, str(outttf2), options) + assert outttf2.check(file=True) + inttf = TTFont() + inttf.importXML(inttx) + assert inttf["head"].modified == TTFont(str(outttf2))["head"].modified + # ------------------------- # ttx.ttList function tests