aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2013-12-06 17:26:09 -0500
committerBehdad Esfahbod <behdad@behdad.org>2013-12-06 17:26:09 -0500
commitb8e1afa809d19202c1f1e405aa4c7312625947d1 (patch)
treeba1f9021ee691a81674e84c5138be3423a012597
parent5e36f854aafa3a4e75883dd4e4c943afff50e32d (diff)
downloadfonttools-b8e1afa809d19202c1f1e405aa4c7312625947d1.tar.gz
Use struct format 'Q' to read/write 64bit integers
-rw-r--r--Lib/fontTools/misc/sstruct.py2
-rw-r--r--Lib/fontTools/ttLib/tables/_h_e_a_d.py34
2 files changed, 3 insertions, 33 deletions
diff --git a/Lib/fontTools/misc/sstruct.py b/Lib/fontTools/misc/sstruct.py
index d4958f7a..e8e11cf0 100644
--- a/Lib/fontTools/misc/sstruct.py
+++ b/Lib/fontTools/misc/sstruct.py
@@ -113,7 +113,7 @@ _elementRE = re.compile(
"\s*" # whitespace
"([A-Za-z_][A-Za-z_0-9]*)" # name (python identifier)
"\s*:\s*" # whitespace : whitespace
- "([cbBhHiIlLfd]|[0-9]+[ps]|" # formatchar...
+ "([cbBhHiIlLqQfd]|[0-9]+[ps]|" # formatchar...
"([0-9]+)\.([0-9]+)(F))" # ...formatchar
"\s*" # whitespace
"(#.*)?$" # [comment] + end of string
diff --git a/Lib/fontTools/ttLib/tables/_h_e_a_d.py b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
index 4a3f0861..a24c3cdf 100644
--- a/Lib/fontTools/ttLib/tables/_h_e_a_d.py
+++ b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
@@ -14,8 +14,8 @@ headFormat = """
magicNumber: I
flags: H
unitsPerEm: H
- created: 8s
- modified: 8s
+ created: Q
+ modified: Q
xMin: h
yMin: h
xMax: h
@@ -36,23 +36,12 @@ class table__h_e_a_d(DefaultTable.DefaultTable):
if rest:
# this is quite illegal, but there seem to be fonts out there that do this
assert rest == "\0\0"
- self.strings2dates()
def compile(self, ttFont):
self.modified = int(time.time() - mac_epoch_diff)
- self.dates2strings()
data = sstruct.pack(headFormat, self)
- self.strings2dates()
return data
- def strings2dates(self):
- self.created = bin2long(self.created)
- self.modified = bin2long(self.modified)
-
- def dates2strings(self):
- self.created = long2bin(self.created)
- self.modified = long2bin(self.modified)
-
def toXML(self, writer, ttFont):
writer.comment("Most of this table will be recalculated by the compiler")
writer.newline()
@@ -114,22 +103,3 @@ def parse_date(datestring):
hour, minute, second = [int(item) for item in tim.split(":")]
t = (year, month, day, hour, minute, second, weekday, 0, 0)
return int(time.mktime(t) - time.timezone)
-
-
-def bin2long(data):
- # thanks </F>!
- v = 0
- for i in map(byteord, data):
- v = v<<8 | i
- return v
-
-def long2bin(v, bytes=8):
- mask = int("FF" * bytes, 16)
- data = b""
- while v:
- data = bytechr(v & 0xff) + data
- v = (v >> 8) & mask
- data = (bytes - len(data)) * b"\0" + data
- assert len(data) == 8, "long too long"
- return data
-