From c63ac64007caf769f1e6a267403280264d4ae7bd Mon Sep 17 00:00:00 2001 From: jvr Date: Tue, 17 Jun 2008 20:41:15 +0000 Subject: [PATCH] fixed buglet that caused the last table in the font not to be padded to a 4-byte boundary (the spec is a little vague about this, but I believe it's needed, also, Suitcase may complain...) git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@562 4cde692c-a291-49d1-8350-778aa11640f8 --- Lib/fontTools/ttLib/sfnt.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/ttLib/sfnt.py b/Lib/fontTools/ttLib/sfnt.py index 3272f2c44..db90c7a4c 100644 --- a/Lib/fontTools/ttLib/sfnt.py +++ b/Lib/fontTools/ttLib/sfnt.py @@ -107,9 +107,12 @@ class SFNTWriter: self.nextTableOffset = self.nextTableOffset + ((len(data) + 3) & ~3) self.file.seek(entry.offset) self.file.write(data) - self.file.seek(self.nextTableOffset) - # make sure we're actually where we want to be. (XXX old cStringIO bug) + # Add NUL bytes to pad the table data to a 4-byte boundary. + # Don't depend on f.seek() as we need to add the padding even if no + # subsequent write follows (seek is lazy), ie. after the final table + # in the font. self.file.write('\0' * (self.nextTableOffset - self.file.tell())) + assert self.nextTableOffset == self.file.tell() if tag == 'head': entry.checkSum = calcChecksum(data[:8] + '\0\0\0\0' + data[12:])