Debian Codegraph @

Doc/source/ttLib/tables/table_api.rst

raw
1 ##########################
2 Base table classes and API
3 ##########################
4
5 .. contents:: On this page:
6 :local:
7
8 .. rubric:: Overview:
9 :heading-level: 2
10
11 The modules documented on this page are the base classes on which the
12 :mod:`fontTools.ttLib` table converters are built. The
13 :class:`.DefaultTable` is the most general; :class:`.asciiTable` is a
14 simpler option for storing text-based data. For OpenType and TrueType
15 fonts, the :class:`.otBase.BaseTTXConverter` leverages the model used
16 by the majority of existing OpenType/TrueType converters.
17
18
19 Contributing your own table convertors
20 --------------------------------------
21
22 To add support for a new font table that fontTools does not currently implement,
23 you must subclass from :py:mod:`fontTools.ttLib.tables.DefaultTable.DefaultTable`.
24 It provides some default behavior, as well as a constructor method (``__init__``)
25 that you don't need to override.
26
27 Your converter should minimally provide two methods::
28
29
30 class table_F_O_O_(DefaultTable.DefaultTable): # converter for table 'FOO '
31
32 def decompile(self, data, ttFont):
33 # 'data' is the raw table data. Unpack it into a
34 # Python data structure.
35 # 'ttFont' is a ttLib.TTfile instance, enabling you to
36 # refer to other tables. Do ***not*** keep a reference to
37 # it: it will cause a circular reference (ttFont saves
38 # a reference to us), and that means we'll be leaking
39 # memory. If you need to use it in other methods, just
40 # pass it around as a method argument.
41
42 def compile(self, ttFont):
43 # Return the raw data, as converted from the Python
44 # data structure.
45 # Again, 'ttFont' is there so you can access other tables.
46 # Same warning applies.
47
48
49 If you want to support TTX import/export as well, you need to provide two
50 additional methods::
51
52
53 def toXML(self, writer, ttFont):
54 # XXX
55
56 def fromXML(self, (name, attrs, content), ttFont):
57 # XXX
58
59
60
61 fontTools.ttLib.tables.DefaultTable
62 -----------------------------------
63
64 .. automodule:: fontTools.ttLib.tables.DefaultTable
65 :members:
66 :undoc-members:
67
68
69 fontTools.ttLib.tables.asciiTable
70 ---------------------------------
71
72 .. automodule:: fontTools.ttLib.tables.asciiTable
73 :members:
74 :undoc-members:
75
76
77 fontTools.ttLib.tables.otBase
78 -----------------------------
79
80 .. automodule:: fontTools.ttLib.tables.otBase
81 :members:
82 :undoc-members:
83