Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/fontTools/ttLib/tables/DefaultTable.py: 34%

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

44 statements  

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING 

4 

5from fontTools.misc.textTools import Tag 

6from fontTools.ttLib import getClassTag 

7 

8if TYPE_CHECKING: 

9 from typing import Any 

10 

11 from fontTools.misc.xmlWriter import XMLWriter 

12 from fontTools.ttLib import TTFont 

13 

14 

15class DefaultTable: 

16 dependencies: list[str] = [] 

17 

18 def __init__(self, tag: str | bytes | None = None) -> None: 

19 if tag is None: 

20 tag = getClassTag(self.__class__) 

21 self.tableTag = Tag(tag) 

22 

23 def decompile(self, data: bytes, ttFont: TTFont) -> None: 

24 self.data = data 

25 

26 def compile(self, ttFont: TTFont) -> bytes: 

27 return self.data 

28 

29 def toXML( 

30 self, writer: XMLWriter, ttFont: TTFont, **kwargs: dict[str, Any] 

31 ) -> None: 

32 if hasattr(self, "ERROR"): 

33 writer.comment("An error occurred during the decompilation of this table") 

34 writer.newline() 

35 writer.comment(self.ERROR) 

36 writer.newline() 

37 writer.begintag("hexdata") 

38 writer.newline() 

39 writer.dumphex(self.compile(ttFont)) 

40 writer.endtag("hexdata") 

41 writer.newline() 

42 

43 def fromXML( 

44 self, name: str, attrs: dict[str, str], content: str, ttFont: TTFont 

45 ) -> None: 

46 from fontTools import ttLib 

47 from fontTools.misc.textTools import readHex 

48 

49 if name != "hexdata": 

50 raise ttLib.TTLibError("can't handle '%s' element" % name) 

51 self.decompile(readHex(content), ttFont) 

52 

53 def __repr__(self) -> str: 

54 return "<'%s' table at %x>" % (self.tableTag, id(self)) 

55 

56 def __eq__(self, other: Any) -> bool: 

57 if type(self) != type(other): 

58 return NotImplemented 

59 return self.__dict__ == other.__dict__ 

60 

61 def __ne__(self, other: Any) -> bool: 

62 result = self.__eq__(other) 

63 return result if result is NotImplemented else not result