1from fontTools.misc.py23 import Tag 2from fontTools.ttLib import getClassTag 3 4class DefaultTable(object): 5 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 if name != "hexdata": 35 raise ttLib.TTLibError("can't handle '%s' element" % name) 36 self.decompile(readHex(content), ttFont) 37 38 def __repr__(self): 39 return "<'%s' table at %x>" % (self.tableTag, id(self)) 40 41 def __eq__(self, other): 42 if type(self) != type(other): 43 return NotImplemented 44 return self.__dict__ == other.__dict__ 45 46 def __ne__(self, other): 47 result = self.__eq__(other) 48 return result if result is NotImplemented else not result 49