DefaultTable.py 1.5 KB

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