TrueType/OpenType Table Modules
This folder is a subpackage of fontTools.ttLib
. Each module here is a
specialized TT/OT table converter: they can convert raw data
to Python objects and vice versa. Usually you don’t need to
use the modules directly: they are imported and used
automatically when needed by fontTools.ttLib
. The tables currently
supported are:
ankr
: Anchor Point Tableavar
: Axis Variations TableBASE
: Baseline Tablebsln
: BaselineCBDT
: Color Bitmap Data TableCBLC
: Color Bitmap Location TableCFF
: Compact Font Format TableCFF2
: Compact Font Format (CFF) Version 2cidg
: CID to Glyph ID tablecmap
: Character to Glyph Index Mapping TableCOLR
: Color TableCPAL
: Color Palette Tablecvar
: CVT Variations Tablecvt
: Control Value TableDSIG
: Digital Signature TableEBDT
: Embedded Bitmap Data TableEBLC
: Embedded Bitmap Location TableFeat
: Graphite Feature Tablefeat
: Feature name tableFFTM
: FontForge Time Stamp Tablefpgm
: Font Programfvar
: Font Variations Tablegasp
: Grid-fitting and Scan-conversion Procedure Tablegcid
: Glyph ID to CID tableGDEF
: Glyph Definition TableGlat
: Graphite Glyph Attributes TableGloc
: Graphite index to glyph attributes tableglyf
: Glyph DataGMAP
: SING Glyphlet Summary TableGPKG
: SING Glyphlet Wrapper TableGPOS
: Glyph Positioning TableGSUB
: Glyph Substitution Tablegvar
: Glyph Variations Tablehdmx
: Horizontal Device Metricshead
: Font Header Tablehhea
: Horizontal Header Tablehmtx
: Horizontal Metrics TableHVAR
:Horizontal Metrics Variations TableJSTF
: Justification Tablekern
: Kerninglcar
: Ligature Caret Tableloca
: Index to Locationltag
: Language TagLTSH
: Linear ThresholdMATH
: Mathematical Typesetting Tablemaxp
: Maximum ProfileMETA
: SING Glyphlet Metadata Tablemeta
: Metadata Tablemort
: Glyph Metamorphosis Tablemorx
: Extended Glyph Metamorphosis TableMVAR
: Metrics Variations Tablename
: Naming Tableopbd
: Optical Bounds TableOS/2
: OS/2 and Windows Metrics Tablepost
: PostScript Tableprep
: Control Value Programprop
: Glyph Properties Tablesbix
: Standard Bitmap Graphics TableSilf
: Graphite Rules TableSill
: Graphite Languages TableSING
: SING Glyphlet Basic Information TableSTAT
: Style Attributes TableSVG
: SVG (Scalable Vector Graphics) Tabletrak
: Tracking tableTTFA
:ttfautohint
Parameter TableVDMX
: Vertical Device Metricsvhea
: Vertical Header Tablevmtx
: Vertical Metrics TableVORG
: Vertical Origin Table- Visual TrueType Private Tables
VVAR
: Vertical Metrics Variations Table
The Python modules representing the tables have pretty strange names: this is due to the
fact that we need to map TT table tags (which are case sensitive)
to filenames (which on Mac and Win aren’t case sensitive) as well
as to Python identifiers. The latter means it can only contain
[A-Za-z0-9_]
and cannot start with a number.
fontTools.ttLib
provides functions to expand a tag into the format used here:
>>> from fontTools import ttLib
>>> ttLib.tagToIdentifier("FOO ")
'F_O_O_'
>>> ttLib.tagToIdentifier("cvt ")
'_c_v_t'
>>> ttLib.tagToIdentifier("OS/2")
'O_S_2f_2'
>>> ttLib.tagToIdentifier("glyf")
'_g_l_y_f'
>>>
And vice versa:
>>> ttLib.identifierToTag("F_O_O_")
'FOO '
>>> ttLib.identifierToTag("_c_v_t")
'cvt '
>>> ttLib.identifierToTag("O_S_2f_2")
'OS/2'
>>> ttLib.identifierToTag("_g_l_y_f")
'glyf'
>>>
Eg. the ‘glyf’ table converter lives in a Python file called:
_g_l_y_f.py
The converter itself is a class, named table_
+ expandedtag. Eg:
class table__g_l_y_f:
etc.
Note that if you _do_ need to use such modules or classes manually, there are two convenient API functions that let you find them by tag:
>>> ttLib.getTableModule('glyf')
<module 'ttLib.tables._g_l_y_f'>
>>> ttLib.getTableClass('glyf')
<class ttLib.tables._g_l_y_f.table__g_l_y_f at 645f400>
>>
ttProgram: TrueType bytecode assembler/disassembler
ttLib.tables.ttProgram.py – Assembler/disassembler for TrueType bytecode programs.
Contributing your own table convertors
To add support for a new font table that fontTools does not currently implement,
you must subclass from fontTools.ttLib.tables.DefaultTable.DefaultTable
.
It provides some default behavior, as well as a constructor method (__init__
)
that you don’t need to override.
Your converter should minimally provide two methods:
class table_F_O_O_(DefaultTable.DefaultTable): # converter for table 'FOO '
def decompile(self, data, ttFont):
# 'data' is the raw table data. Unpack it into a
# Python data structure.
# 'ttFont' is a ttLib.TTfile instance, enabling you to
# refer to other tables. Do ***not*** keep a reference to
# it: it will cause a circular reference (ttFont saves
# a reference to us), and that means we'll be leaking
# memory. If you need to use it in other methods, just
# pass it around as a method argument.
def compile(self, ttFont):
# Return the raw data, as converted from the Python
# data structure.
# Again, 'ttFont' is there so you can access other tables.
# Same warning applies.
If you want to support TTX import/export as well, you need to provide two additional methods:
def toXML(self, writer, ttFont):
# XXX
def fromXML(self, (name, attrs, content), ttFont):
# XXX