• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from fontTools.misc.py23 import *
2from fontTools.misc import sstruct
3from fontTools.misc.textTools import safeEval
4from ._h_e_a_d import mac_epoch_diff
5from . import DefaultTable
6import time
7import calendar
8
9FFTMFormat = """
10		>	# big endian
11		version:        I
12		FFTimeStamp:    Q
13		sourceCreated:  Q
14		sourceModified: Q
15"""
16
17class table_F_F_T_M_(DefaultTable.DefaultTable):
18
19  def decompile(self, data, ttFont):
20    dummy, rest = sstruct.unpack2(FFTMFormat, data, self)
21
22  def compile(self, ttFont):
23    data = sstruct.pack(FFTMFormat, self)
24    return data
25
26  def toXML(self, writer, ttFont):
27    writer.comment("FontForge's timestamp, font source creation and modification dates")
28    writer.newline()
29    formatstring, names, fixes = sstruct.getformat(FFTMFormat)
30    for name in names:
31      value = getattr(self, name)
32      if name in ("FFTimeStamp", "sourceCreated", "sourceModified"):
33        try:
34          value = time.asctime(time.gmtime(max(0, value + mac_epoch_diff)))
35        except ValueError:
36          value = time.asctime(time.gmtime(0))
37      writer.simpletag(name, value=value)
38      writer.newline()
39
40  def fromXML(self, name, attrs, content, ttFont):
41    value = attrs["value"]
42    if name in ("FFTimeStamp", "sourceCreated", "sourceModified"):
43      value = calendar.timegm(time.strptime(value)) - mac_epoch_diff
44    else:
45      value = safeEval(value)
46    setattr(self, name, value)