xref: /aosp_15_r20/external/fonttools/Lib/fontTools/ttLib/tables/DefaultTable.py (revision e1fe3e4ad2793916b15cccdc4a7da52a7e1dd0e9)
1from fontTools.misc.textTools import Tag
2from fontTools.ttLib import getClassTag
3
4
5class DefaultTable(object):
6    dependencies = []
7
8    def __init__(self, tag=None):
9        if tag is None:
10            tag = getClassTag(self.__class__)
11        self.tableTag = Tag(tag)
12
13    def decompile(self, data, ttFont):
14        self.data = data
15
16    def compile(self, ttFont):
17        return self.data
18
19    def toXML(self, writer, ttFont, **kwargs):
20        if hasattr(self, "ERROR"):
21            writer.comment("An error occurred during the decompilation of this table")
22            writer.newline()
23            writer.comment(self.ERROR)
24            writer.newline()
25        writer.begintag("hexdata")
26        writer.newline()
27        writer.dumphex(self.compile(ttFont))
28        writer.endtag("hexdata")
29        writer.newline()
30
31    def fromXML(self, name, attrs, content, ttFont):
32        from fontTools.misc.textTools import readHex
33        from fontTools import ttLib
34
35        if name != "hexdata":
36            raise ttLib.TTLibError("can't handle '%s' element" % name)
37        self.decompile(readHex(content), ttFont)
38
39    def __repr__(self):
40        return "<'%s' table at %x>" % (self.tableTag, id(self))
41
42    def __eq__(self, other):
43        if type(self) != type(other):
44            return NotImplemented
45        return self.__dict__ == other.__dict__
46
47    def __ne__(self, other):
48        result = self.__eq__(other)
49        return result if result is NotImplemented else not result
50