1from __future__ import print_function, division, absolute_import 2from fontTools.misc.py23 import * 3from fontTools.ttLib import getClassTag 4 5class DefaultTable(object): 6 7 dependencies = [] 8 9 def __init__(self, tag=None): 10 if tag is None: 11 tag = getClassTag(self.__class__) 12 self.tableTag = Tag(tag) 13 14 def decompile(self, data, ttFont): 15 self.data = data 16 17 def compile(self, ttFont): 18 return self.data 19 20 def toXML(self, writer, ttFont, **kwargs): 21 if hasattr(self, "ERROR"): 22 writer.comment("An error occurred during the decompilation of this table") 23 writer.newline() 24 writer.comment(self.ERROR) 25 writer.newline() 26 writer.begintag("hexdata") 27 writer.newline() 28 writer.dumphex(self.compile(ttFont)) 29 writer.endtag("hexdata") 30 writer.newline() 31 32 def fromXML(self, name, attrs, content, ttFont): 33 from fontTools.misc.textTools import readHex 34 from fontTools import ttLib 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