From f9104bcc2cd61bf029ac6736ef0ee98968bde472 Mon Sep 17 00:00:00 2001 From: jvr Date: Thu, 17 Jan 2002 09:36:30 +0000 Subject: [PATCH] another buggy font workaround; sped up unpackPStrings somewhat git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@177 4cde692c-a291-49d1-8350-778aa11640f8 --- Lib/fontTools/ttLib/tables/_p_o_s_t.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/_p_o_s_t.py b/Lib/fontTools/ttLib/tables/_p_o_s_t.py index 609ec706e..203be8241 100644 --- a/Lib/fontTools/ttLib/tables/_p_o_s_t.py +++ b/Lib/fontTools/ttLib/tables/_p_o_s_t.py @@ -67,6 +67,12 @@ class table__p_o_s_t(DefaultTable.DefaultTable): def decode_format_2_0(self, data, ttFont): numGlyphs, = struct.unpack(">H", data[:2]) numGlyphs = int(numGlyphs) + if numGlyphs > ttFont['maxp'].numGlyphs: + # Assume the numGlyphs field is bogus, so sync with maxp. + # I've seen this in one font, and if the assumption is + # wrong elsewhere, well, so be it: it's hard enough to + # work around _one_ non-conforming post format... + numGlyphs = ttFont['maxp'].numGlyphs data = data[2:] indices = array.array("H") indices.fromstring(data[:2*numGlyphs]) @@ -200,12 +206,15 @@ class table__p_o_s_t(DefaultTable.DefaultTable): def unpackPStrings(data): strings = [] - while data: - length = ord(data[0]) - strings.append(data[1:1+length]) - data = data[1+length:] + index = 0 + dataLen = len(data) + while index < dataLen: + length = ord(data[index]) + strings.append(data[index+1:index+1+length]) + index = index + 1 + length return strings + def packPStrings(strings): data = "" for s in strings: