Just | 7842e56 | 1999-12-16 21:34:53 +0000 | [diff] [blame] | 1 | import sys |
| 2 | |
| 3 | class DefaultTable: |
| 4 | |
| 5 | dependencies = [] |
| 6 | |
| 7 | def __init__(self, tag): |
| 8 | self.tableTag = tag |
| 9 | |
| 10 | def decompile(self, data, ttFont): |
| 11 | self.data = data |
| 12 | |
| 13 | def compile(self, ttFont): |
| 14 | return self.data |
| 15 | |
| 16 | def toXML(self, writer, ttFont): |
Just | f8fd477 | 2000-01-03 23:00:10 +0000 | [diff] [blame] | 17 | if hasattr(self, "ERROR"): |
| 18 | writer.comment("An error occurred during the decompilation of this table") |
| 19 | writer.newline() |
| 20 | writer.comment(self.ERROR) |
| 21 | writer.newline() |
Just | 7842e56 | 1999-12-16 21:34:53 +0000 | [diff] [blame] | 22 | writer.begintag("hexdata") |
| 23 | writer.newline() |
| 24 | writer.dumphex(self.compile(ttFont)) |
| 25 | writer.endtag("hexdata") |
| 26 | writer.newline() |
| 27 | |
Behdad Esfahbod | 3a9fd30 | 2013-11-27 03:19:32 -0500 | [diff] [blame] | 28 | def fromXML(self, name, attrs, content, ttFont): |
Just | 7842e56 | 1999-12-16 21:34:53 +0000 | [diff] [blame] | 29 | from fontTools.misc.textTools import readHex |
| 30 | from fontTools import ttLib |
Behdad Esfahbod | 180ace6 | 2013-11-27 02:40:30 -0500 | [diff] [blame] | 31 | if name != "hexdata": |
Behdad Esfahbod | cd5aad9 | 2013-11-27 02:42:28 -0500 | [diff] [blame] | 32 | raise ttLib.TTLibError("can't handle '%s' element" % name) |
Just | 7842e56 | 1999-12-16 21:34:53 +0000 | [diff] [blame] | 33 | self.decompile(readHex(content), ttFont) |
| 34 | |
| 35 | def __repr__(self): |
| 36 | return "<'%s' table at %x>" % (self.tableTag, id(self)) |
| 37 | |
| 38 | def __cmp__(self, other): |
Behdad Esfahbod | ac1b435 | 2013-11-27 04:15:34 -0500 | [diff] [blame] | 39 | if not isinstance(self, type(other)): return cmp(type(self), type(other)) |
Behdad Esfahbod | 0ba7aa7 | 2013-10-28 12:07:15 +0100 | [diff] [blame] | 40 | if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__) |
Behdad Esfahbod | 96b321c | 2013-08-17 11:11:22 -0400 | [diff] [blame] | 41 | |
Just | 7842e56 | 1999-12-16 21:34:53 +0000 | [diff] [blame] | 42 | return cmp(self.__dict__, other.__dict__) |
| 43 | |