Menu

 
 
 
 
 

Using TTX for Font Development

Background: See Building OpenType fonts.

From our research so far, TTX/FontTools appears to be the only tool able to both decompile and compile the entire contents of an OpenType font. We have therefore decided to use it, at least temporarily, to help us maintain and build fonts that require the high-end features not available with other font building systems.

TTX decompiles to and compiles from a nicely pretty-printed XML format, which means that the source files can readily be placed under source code control systems like CVS.

There are a couple of disadvantages to using this scheme:

  • the TTX XML DTD/schema does not seem to be documented. However, using other OpenType font tools, and the OpenType standard itself, it is possible to flush most of it out. Also, it is open source, so it may be possible to learn more from the Python code. TODO: We will attempt to build a DTD or schema that can be used to validate and guide entry.
  • The TTX XML very closely matches the OpenType standard, which means you are running fairly close to bare metal by using it in this way. You don't have to count bytes to compute table offsets, but there is a fair amount of detail, and a solid understanding of the OpenType standard is essential. There are at least two possible solutions. TODO: First, we want to write some "cookbook" recipes for doing basic maintenance. TODO: Second, in the long run we want to attempt to create an XML DTD and XSLT stylesheet that could be used for a more intuitive interface, then convert to the TTX format for compilation.

The Cookbook

This cookbook is terribly inadequate and incomplete. It is intended to be a starting place, a scratchpad for things learned.

Recipe 0: Basic Tasks and Definitions

The following tasks and definitions will be used in the recipes below:

  • dump an OTF to TTX: decompile the OTF file into XML, usually by dragging it to the TTX icon.
  • check in: commit the TTX file to the source repository (such as CVS). This is optional but recommended.
  • file conversions: We prefer to store all of our source files with Unix line endings, so we have added this step. If you have no such similar need, you can ignore this step when it is mentioned.
  • working TTX file: This term refers to the file you are ultimately editing for font production, as opposed to any temporary TTX files that are generated along the way
  • diff: Use a utility to find the differences between two text files. In Unix/Linux, one such utility is called diff.
  • diff output from other tools: Sometimes it is very useful to use another tool, such as FontLab or VOLT, for some aspect of the work. However, since these tools sometimes do not support all of the features of your font, they may "eat" those features when reading your base file. When this is true:
    • read the original file into the external tool, and, before making any changes to it, generate another OTF file from it, perhaps naming it Font1.otf. This step is important so that differences caused by the external tool's deficiencies will be eliminated.
    • open Font1.otf in the external tool, make your desired changes, then generate another OTF file, perhaps naming it Font2.otf.
    • dump both Font1.otf and Font2.otf to TTX
    • diff the resulting TTX files, then mimic these changes in your working TTX file

Recipe 1: Getting Started

  • Dump to TTX, perform file conversions, check in. This is the base, unaltered revision.
  • Remove the contents, if any, in the <DSIG> (digital signature) element, and check in. The Digital Signature will be worthless once the font is recompiled.
  • If necessary, rename the font, and check in. These names are in the <name> element, and there may be many of them.

Recipe 2: Add a Glyph

  • Use FontLab or other glyph editor to create the glyph, using the "diff output from other tools" technique. You may need to delete all other glyphs in the font to get a straightforward set of paths to drop into the TTX file.
  • In the TTX file, add a <GlyphID> element in the <GlyphOrder> element.
  • Add the glyph description itself (created above). For Type 1 fonts, this is a <CharString> element.
  • Create an entry for the new glyph in each table of the cmap section.
  • Add an mtx element for the metrics in the hmtx table.

Recipe 3: Creating a combining mark Glyph

  • In addition to the steps noted in the "Add a Glyph" Recipe, make sure the mtx element in the hmtx table has a width of zero

Recipe 4: Add Marks to a Base Glyph

  • Make sure the glyph is defined as a mark in the GDEF Glyph Class Definition Table