Skip to content

Commit

Permalink
[ttx] add --no-recalc-timestamp option to keep original head.modified
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Jan 17, 2019
1 parent 158a7a3 commit 0e47ea1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Lib/fontTools/ttx.py
Expand Up @@ -77,6 +77,7 @@
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 <type> 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
Expand Down Expand Up @@ -123,7 +124,7 @@ class Options(object):
bitmapGlyphDataFormat = 'raw'
unicodedata = None
newlinestr = None
recalcTimestamp = False
recalcTimestamp = None
flavor = None
useZopfli = False

Expand Down Expand Up @@ -204,6 +205,8 @@ def __init__(self, rawOptions, numFiles):
% (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":
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions Tests/ttx/ttx_test.py
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0e47ea1

Please sign in to comment.