aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2014-05-14 00:08:15 -0400
committerBehdad Esfahbod <behdad@behdad.org>2014-05-14 00:08:15 -0400
commit2db5eca0df1ff21f4c6bb5dee44512bf02e3f203 (patch)
treebe958c9306e4871e676adcd5a589b09edc60862a
parent0d182bfb8078665313280db759b782c3144f65fa (diff)
downloadfonttools-2db5eca0df1ff21f4c6bb5dee44512bf02e3f203.tar.gz
Micro-optimize cmap subtable format 4 loading
-rw-r--r--Lib/fontTools/ttLib/tables/_c_m_a_p.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/fontTools/ttLib/tables/_c_m_a_p.py b/Lib/fontTools/ttLib/tables/_c_m_a_p.py
index cde727b3..3954d5ce 100644
--- a/Lib/fontTools/ttLib/tables/_c_m_a_p.py
+++ b/Lib/fontTools/ttLib/tables/_c_m_a_p.py
@@ -665,18 +665,22 @@ class cmap_format_4(CmapSubtable):
charCodes = []
gids = []
for i in range(len(startCode) - 1): # don't do 0xffff!
+ start = startCode[i]
+ delta = idDelta[i]
+ rangeOffset = idRangeOffset[i]
+ # *someone* needs to get killed.
+ partial = rangeOffset // 2 - start + i - len(idRangeOffset)
+
rangeCharCodes = list(range(startCode[i], endCode[i] + 1))
charCodes.extend(rangeCharCodes)
for charCode in rangeCharCodes:
- rangeOffset = idRangeOffset[i]
if rangeOffset == 0:
- glyphID = charCode + idDelta[i]
+ glyphID = charCode + delta
else:
- # *someone* needs to get killed.
- index = rangeOffset // 2 + (charCode - startCode[i]) + i - len(idRangeOffset)
+ index = charCode + partial
assert (index < lenGIArray), "In format 4 cmap, range (%d), the calculated index (%d) into the glyph index array is not less than the length of the array (%d) !" % (i, index, lenGIArray)
if glyphIndexArray[index] != 0: # if not missing glyph
- glyphID = glyphIndexArray[index] + idDelta[i]
+ glyphID = glyphIndexArray[index] + delta
else:
glyphID = 0 # missing glyph
gids.append(glyphID % 0x10000)