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