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