Allow disabling 'head' table modified-timestamp recalculation
Part of:
https://github.com/behdad/fonttools/issues/115
https://github.com/behdad/fonttools/issues/46
diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py
index 732aa52..9879a4e 100644
--- a/Lib/fontTools/ttLib/__init__.py
+++ b/Lib/fontTools/ttLib/__init__.py
@@ -72,7 +72,7 @@
def __init__(self, file=None, res_name_or_index=None,
sfntVersion="\000\001\000\000", flavor=None, checkChecksums=False,
verbose=False, recalcBBoxes=True, allowVID=False, ignoreDecompileErrors=False,
- fontNumber=-1, lazy=False, quiet=False):
+ recalcTimestamp=True, fontNumber=-1, lazy=False, quiet=False):
"""The constructor can be called with a few different arguments.
When reading a font from disk, 'file' should be either a pathname
@@ -106,6 +106,9 @@
greatly, and therefore should have some impact on the time needed
to parse/compile large fonts.
+ If the recalcTimestamp argument is false, the modified timestamp in the
+ 'head' table will *not* be recalculated upon save/compile.
+
If the allowVID argument is set to true, then virtual GID's are
supported. Asking for a glyph ID with a glyph name or GID that is not in
the font will return a virtual GID. This is valid for GSUB and cmap
@@ -130,6 +133,7 @@
self.quiet = quiet
self.lazy = lazy
self.recalcBBoxes = recalcBBoxes
+ self.recalcTimestamp = recalcTimestamp
self.tables = {}
self.reader = None
diff --git a/Lib/fontTools/ttLib/tables/_h_e_a_d.py b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
index 97dd1a7..bf4116d 100644
--- a/Lib/fontTools/ttLib/tables/_h_e_a_d.py
+++ b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
@@ -39,7 +39,8 @@
assert rest == "\0\0"
def compile(self, ttFont):
- self.modified = int(time.time() - mac_epoch_diff)
+ if ttFont.recalcTimestamp:
+ self.modified = int(time.time() - mac_epoch_diff)
data = sstruct.pack(headFormat, self)
return data