diff --git a/fpdf/ttfonts.py b/fpdf/ttfonts.py index 3550727d1..68ede5c20 100644 --- a/fpdf/ttfonts.py +++ b/fpdf/ttfonts.py @@ -943,13 +943,15 @@ def getLOCA(self, indexToLocFormat, numGlyphs): if (indexToLocFormat == 0): data = self.get_chunk(start,(numGlyphs*2)+2) arr = unpack(">%dH" % (len(data)//2), data) - for n in range(numGlyphs): - self.glyphPos.append((arr[n] * 2)) # n+1 !? + for n in range(len(arr)): + # NOTE: len(arr) == numGlyphs + 1, otherwise + # the length of the last glyph would be unknown. + self.glyphPos.append((arr[n] * 2)) elif (indexToLocFormat == 1): data = self.get_chunk(start,(numGlyphs*4)+4) arr = unpack(">%dL" % (len(data)//4), data) - for n in range(numGlyphs): - self.glyphPos.append((arr[n])) # n+1 !? + for n in range(len(arr)): + self.glyphPos.append((arr[n])) else: die('Unknown location table format ' + indexToLocFormat)