Allow long-aligned glyph records (as is in fact recommended by the latest MS spec, but almost nobody seems to do it...)

git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@110 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
Just 2000-06-07 19:13:11 +00:00
parent 1b850986ef
commit 306d24ec79

View File

@ -235,9 +235,11 @@ class Glyph:
data = data + self.compileComponents(glyfTable) data = data + self.compileComponents(glyfTable)
else: else:
data = data + self.compileCoordinates() data = data + self.compileCoordinates()
# from the spec: "Note that the local offsets should be word-aligned" # From the spec: "Note that the local offsets should be word-aligned"
# From a later MS spec: "Note that the local offsets should be long-aligned"
# For now, I'll stick to word-alignment.
if len(data) % 2: if len(data) % 2:
# ...so if the length of the data is odd, append a null byte # if the length of the data is odd, append a null byte
data = data + "\0" data = data + "\0"
return data return data
@ -442,7 +444,7 @@ class Glyph:
# unpack raw coordinates, krrrrrr-tching! # unpack raw coordinates, krrrrrr-tching!
xDataLen = struct.calcsize(xFormat) xDataLen = struct.calcsize(xFormat)
yDataLen = struct.calcsize(yFormat) yDataLen = struct.calcsize(yFormat)
if (len(data) - (xDataLen + yDataLen)) not in (0, 1): if not (0 <= (len(data) - (xDataLen + yDataLen)) < 4):
raise ttLib.TTLibError, "bad glyph record" raise ttLib.TTLibError, "bad glyph record"
xCoordinates = struct.unpack(xFormat, data[:xDataLen]) xCoordinates = struct.unpack(xFormat, data[:xDataLen])
yCoordinates = struct.unpack(yFormat, data[xDataLen:xDataLen+yDataLen]) yCoordinates = struct.unpack(yFormat, data[xDataLen:xDataLen+yDataLen])