merge: Merge multiple fonts into one
Overview:
fontTools.merge provides both a library and a command line interface
(fonttools merge) for merging multiple fonts together.
Run fonttools merge --help (or pyftmerge --help) to list the command-line
options. -h is also supported. Help is written to standard output without
opening any font or input-list files.
If the merged BMP mapping exceeds the 16-bit limits of a cmap format 4
subtable, the merger uses format 12 instead. All nominal mappings and separate
Unicode variation mappings are retained. Such fonts require a reader that
supports format 12. BMP maps that fit in format 4 keep their representation.
- class fontTools.merge.Merger(options=None)[source]
Bases:
objectFont merger.
This class merges multiple fonts into a single OpenType font, taking into account complexities such as OpenType layout (
GSUB/GPOS) tables and cross-font metrics (for examplehhea.ascentis set to the maximum value across all the fonts).If multiple glyphs map to the same Unicode value, and the glyphs are considered sufficiently different (that is, they differ in any of paths, widths, or height), then subsequent glyphs are renamed and a lookup in the
loclfeature will be created to disambiguate them. For example, if the arguments are an Arabic font and a Latin font and both contain a set of parentheses, the Latin glyphs will be renamed toparenleft.1andparenright.1, and a lookup will be inserted into the toloclfeature (creating it if necessary) under thelatnscript to substituteparenleftwithparenleft.1etc.Restrictions:
All fonts must have the same units per em.
If duplicate glyph disambiguation takes place as described above then the fonts must have a
GSUBtable.
- options
Currently unused.
- merge(fontfiles)[source]
Merges fonts together.
- Parameters:
fontfiles -- A list of file names or
fontTools.ttLib.TTFontobjects to be merged. The two input types can be mixed.- Returns:
A
fontTools.ttLib.TTFontobject. Call thesavemethod on this to write it out to an OTF file.
Font objects are serialized in memory, including any unsaved changes. No temporary font files are created, and the input objects are not closed.
DMAP overrides are folded into the merged cmap table.