Home | History | Annotate | Download | only in tables
      1 from fontTools.misc.py23 import *
      2 from fontTools.misc import sstruct
      3 from fontTools.misc.textTools import safeEval
      4 from ._h_e_a_d import mac_epoch_diff
      5 from . import DefaultTable
      6 import time
      7 import calendar
      8 
      9 FFTMFormat = """
     10 		>	# big endian
     11 		version:        I
     12 		FFTimeStamp:    Q
     13 		sourceCreated:  Q
     14 		sourceModified: Q
     15 """
     16 
     17 class 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)