Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/fontTools/ttLib/tables/_l_o_c_a.py: 28%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

46 statements  

1from . import DefaultTable 

2import sys 

3import array 

4import logging 

5 

6 

7log = logging.getLogger(__name__) 

8 

9 

10class table__l_o_c_a(DefaultTable.DefaultTable): 

11 dependencies = ["glyf"] 

12 

13 def decompile(self, data, ttFont): 

14 longFormat = ttFont["head"].indexToLocFormat 

15 if longFormat: 

16 format = "I" 

17 else: 

18 format = "H" 

19 locations = array.array(format) 

20 locations.frombytes(data) 

21 if sys.byteorder != "big": 

22 locations.byteswap() 

23 if not longFormat: 

24 locations = array.array("I", (2 * l for l in locations)) 

25 if len(locations) < (ttFont["maxp"].numGlyphs + 1): 

26 log.warning( 

27 "corrupt 'loca' table, or wrong numGlyphs in 'maxp': %d %d", 

28 len(locations) - 1, 

29 ttFont["maxp"].numGlyphs, 

30 ) 

31 self.locations = locations 

32 

33 def compile(self, ttFont): 

34 try: 

35 max_location = max(self.locations) 

36 except AttributeError: 

37 self.set([]) 

38 max_location = 0 

39 if max_location < 0x20000 and all(l % 2 == 0 for l in self.locations): 

40 locations = array.array("H") 

41 for i in range(len(self.locations)): 

42 locations.append(self.locations[i] // 2) 

43 ttFont["head"].indexToLocFormat = 0 

44 else: 

45 locations = array.array("I", self.locations) 

46 ttFont["head"].indexToLocFormat = 1 

47 if sys.byteorder != "big": 

48 locations.byteswap() 

49 return locations.tobytes() 

50 

51 def set(self, locations): 

52 self.locations = array.array("I", locations) 

53 

54 def toXML(self, writer, ttFont): 

55 writer.comment("The 'loca' table will be calculated by the compiler") 

56 writer.newline() 

57 

58 def __getitem__(self, index): 

59 return self.locations[index] 

60 

61 def __len__(self): 

62 return len(self.locations)