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