tables: Access TrueType/OpenType tables
Overview
This folder is a subpackage of fontTools.ttLib
. Each module here is a
specialized TrueType/OpenType table converter: they can convert raw data
to Python objects and vice versa. Usually you do not need to
use these modules directly: they are imported and used
automatically when needed by fontTools.ttLib
.
In addition to the tables defined in the official TrueType/OpenType specification documents, several specialty tables are supported that are used by specific vendors (including the Graphite shaping engine and Apple’s AAT). Note that fontTools supports the tables that provide the core functionality of AAT, but does not guarantee everything.
Similarly, fontTools supports some third-party tables used by external applications (such as FontForge and Microsoft’s VTT), but may not support every private table employed by those applications.
Accessing tables
The Python modules representing the tables have pretty strange names: this is due to the
fact that we need to map TT/OT table tags (which are case sensitive)
to filenames (which on macOS and Windows are not case sensitive) as well
as to Python identifiers. The latter means that each table identifier
can only contain [A-Za-z0-9_]
and cannot start with a number.
The convention adopted is that capital letters in a table tag are
transformed into the letter followed by an underscore (e.g., A_
), while lowercase
letters and numbers are preceded by an underscore (e.g., _a
).
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>
>>
Helper modules
In addition to the core table-conversion implementations, a set of helper and utility modules is also found in this package. You should not normally need to access these modules directly, but consulting them might be valuable if you need to add fontTools support for a new table type.
In that case, a good place to start is with the documentation for the base table classes:
The modules that provide lower-level helper functionality include implementations of common OpenType data structures, support for OpenType font variations, and various classes needed for tables containing bitmap data or for tables used by the Graphite engine:
A module is also included for assembling and disassembling TrueType bytecode:
Tables currently supported
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 2 tablecidg
: 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 Program tablefvar
: 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 Data tableGMAP
: SING Glyphlet Summary tableGPKG
: SING Glyphlet Wrapper tableGPOS
: Glyph Positioning tableGSUB
: Glyph Substitution tablegvar
: Glyph Variations tablehdmx
: Horizontal Device Metrics tablehead
: Font Header tablehhea
: Horizontal Header tablehmtx
: Horizontal Metrics tableHVAR
: Horizontal Metrics Variations tableJSTF
: Justification tablekern
: Kerning tablelcar
: Ligature Caret Tableloca
: Index to Location tableltag
: Language Tag tableLTSH
: Linear Threshold tableMATH
: Mathematical Typesetting tablemaxp
: Maximum Profile tableMETA
: 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 Program tableprop
: 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 Metrics tablevhea
: Vertical Header tablevmtx
: Vertical Metrics tableVORG
: Vertical Origin tableVTT*
Visual TrueType private tablesVVAR
: Vertical Metrics Variations table