Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/fontTools/ttLib/tables/_l_o_c_a.py: 27%
49 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:33 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:33 +0000
1from . import DefaultTable
2import sys
3import array
4import logging
7log = logging.getLogger(__name__)
10class table__l_o_c_a(DefaultTable.DefaultTable):
12 dependencies = ["glyf"]
14 def decompile(self, data, ttFont):
15 longFormat = ttFont["head"].indexToLocFormat
16 if longFormat:
17 format = "I"
18 else:
19 format = "H"
20 locations = array.array(format)
21 locations.frombytes(data)
22 if sys.byteorder != "big":
23 locations.byteswap()
24 if not longFormat:
25 l = array.array("I")
26 for i in range(len(locations)):
27 l.append(locations[i] * 2)
28 locations = l
29 if len(locations) < (ttFont["maxp"].numGlyphs + 1):
30 log.warning(
31 "corrupt 'loca' table, or wrong numGlyphs in 'maxp': %d %d",
32 len(locations) - 1,
33 ttFont["maxp"].numGlyphs,
34 )
35 self.locations = locations
37 def compile(self, ttFont):
38 try:
39 max_location = max(self.locations)
40 except AttributeError:
41 self.set([])
42 max_location = 0
43 if max_location < 0x20000 and all(l % 2 == 0 for l in self.locations):
44 locations = array.array("H")
45 for i in range(len(self.locations)):
46 locations.append(self.locations[i] // 2)
47 ttFont["head"].indexToLocFormat = 0
48 else:
49 locations = array.array("I", self.locations)
50 ttFont["head"].indexToLocFormat = 1
51 if sys.byteorder != "big":
52 locations.byteswap()
53 return locations.tobytes()
55 def set(self, locations):
56 self.locations = array.array("I", locations)
58 def toXML(self, writer, ttFont):
59 writer.comment("The 'loca' table will be calculated by the compiler")
60 writer.newline()
62 def __getitem__(self, index):
63 return self.locations[index]
65 def __len__(self):
66 return len(self.locations)