1############################### 2TrueType/OpenType Table Modules 3############################### 4 5This folder is a subpackage of :py:mod:`fontTools.ttLib`. Each module here is a 6specialized TT/OT table converter: they can convert raw data 7to Python objects and vice versa. Usually you don't need to 8use the modules directly: they are imported and used 9automatically when needed by :py:mod:`fontTools.ttLib`. The tables currently 10supported are: 11 12.. toctree:: 13 :maxdepth: 1 14 15 tables/_a_n_k_r 16 tables/_a_v_a_r 17 tables/B_A_S_E_ 18 tables/_b_s_l_n 19 tables/C_B_D_T_ 20 tables/C_B_L_C_ 21 tables/C_F_F_ 22 tables/C_F_F__2 23 tables/_c_i_d_g 24 tables/_c_m_a_p 25 tables/C_O_L_R_ 26 tables/C_P_A_L_ 27 tables/_c_v_a_r 28 tables/_c_v_t 29 tables/D_S_I_G_ 30 tables/E_B_D_T_ 31 tables/E_B_L_C_ 32 tables/F__e_a_t 33 tables/_f_e_a_t 34 tables/F_F_T_M_ 35 tables/_f_p_g_m 36 tables/_f_v_a_r 37 tables/_g_a_s_p 38 tables/_g_c_i_d 39 tables/G_D_E_F_ 40 tables/G__l_a_t 41 tables/G__l_o_c 42 tables/_g_l_y_f 43 tables/G_M_A_P_ 44 tables/G_P_K_G_ 45 tables/G_P_O_S_ 46 tables/G_S_U_B_ 47 tables/_g_v_a_r 48 tables/_h_d_m_x 49 tables/_h_e_a_d 50 tables/_h_h_e_a 51 tables/_h_m_t_x 52 tables/H_V_A_R_ 53 tables/J_S_T_F_ 54 tables/_k_e_r_n 55 tables/_l_c_a_r 56 tables/_l_o_c_a 57 tables/_l_t_a_g 58 tables/L_T_S_H_ 59 tables/M_A_T_H_ 60 tables/_m_a_x_p 61 tables/M_E_T_A_ 62 tables/_m_e_t_a 63 tables/_m_o_r_t 64 tables/_m_o_r_x 65 tables/M_V_A_R_ 66 tables/_n_a_m_e 67 tables/_o_p_b_d 68 tables/O_S_2f_2 69 tables/_p_o_s_t 70 tables/_p_r_e_p 71 tables/_p_r_o_p 72 tables/_s_b_i_x 73 tables/S__i_l_f 74 tables/S__i_l_l 75 tables/S_I_N_G_ 76 tables/S_T_A_T_ 77 tables/S_V_G_ 78 tables/_t_r_a_k 79 tables/T_T_F_A_ 80 tables/V_D_M_X_ 81 tables/_v_h_e_a 82 tables/_v_m_t_x 83 tables/V_O_R_G_ 84 tables/VTT_related 85 tables/V_V_A_R_ 86 87The Python modules representing the tables have pretty strange names: this is due to the 88fact that we need to map TT table tags (which are case sensitive) 89to filenames (which on Mac and Win aren't case sensitive) as well 90as to Python identifiers. The latter means it can only contain 91``[A-Za-z0-9_]`` and cannot start with a number. 92 93:py:mod:`fontTools.ttLib` provides functions to expand a tag into the format used here:: 94 95 >>> from fontTools import ttLib 96 >>> ttLib.tagToIdentifier("FOO ") 97 'F_O_O_' 98 >>> ttLib.tagToIdentifier("cvt ") 99 '_c_v_t' 100 >>> ttLib.tagToIdentifier("OS/2") 101 'O_S_2f_2' 102 >>> ttLib.tagToIdentifier("glyf") 103 '_g_l_y_f' 104 >>> 105 106And vice versa:: 107 108 >>> ttLib.identifierToTag("F_O_O_") 109 'FOO ' 110 >>> ttLib.identifierToTag("_c_v_t") 111 'cvt ' 112 >>> ttLib.identifierToTag("O_S_2f_2") 113 'OS/2' 114 >>> ttLib.identifierToTag("_g_l_y_f") 115 'glyf' 116 >>> 117 118Eg. the 'glyf' table converter lives in a Python file called:: 119 120 _g_l_y_f.py 121 122The converter itself is a class, named ``table_`` + expandedtag. Eg:: 123 124 125 class table__g_l_y_f: 126 etc. 127 128Note that if you _do_ need to use such modules or classes manually, 129there are two convenient API functions that let you find them by tag:: 130 131 >>> ttLib.getTableModule('glyf') 132 <module 'ttLib.tables._g_l_y_f'> 133 >>> ttLib.getTableClass('glyf') 134 <class ttLib.tables._g_l_y_f.table__g_l_y_f at 645f400> 135 >> 136 137ttProgram: TrueType bytecode assembler/disassembler 138--------------------------------------------------- 139 140.. automodule:: fontTools.ttLib.tables.ttProgram 141 :inherited-members: 142 :members: 143 :undoc-members: 144 145Contributing your own table convertors 146-------------------------------------- 147 148To add support for a new font table that fontTools does not currently implement, 149you must subclass from :py:mod:`fontTools.ttLib.tables.DefaultTable.DefaultTable`. 150It provides some default behavior, as well as a constructor method (``__init__``) 151that you don't need to override. 152 153Your converter should minimally provide two methods:: 154 155 156 class table_F_O_O_(DefaultTable.DefaultTable): # converter for table 'FOO ' 157 158 def decompile(self, data, ttFont): 159 # 'data' is the raw table data. Unpack it into a 160 # Python data structure. 161 # 'ttFont' is a ttLib.TTfile instance, enabling you to 162 # refer to other tables. Do ***not*** keep a reference to 163 # it: it will cause a circular reference (ttFont saves 164 # a reference to us), and that means we'll be leaking 165 # memory. If you need to use it in other methods, just 166 # pass it around as a method argument. 167 168 def compile(self, ttFont): 169 # Return the raw data, as converted from the Python 170 # data structure. 171 # Again, 'ttFont' is there so you can access other tables. 172 # Same warning applies. 173 174 175If you want to support TTX import/export as well, you need to provide two 176additional methods:: 177 178 179 def toXML(self, writer, ttFont): 180 # XXX 181 182 def fromXML(self, (name, attrs, content), ttFont): 183 # XXX 184 185.. automodule:: fontTools.ttLib.tables 186 :inherited-members: 187 :members: 188 :undoc-members: 189 190 191