Attaching instructions to fonts

Now that you have an idea of what you can put in a .tti file, you may want to know how to link your programs to a font. The first things required for this are a source file location and a destination file location:

#input "../Garogier.ttf"
#output "Garogier_instructed.ttf"

TTIComp will look in the current directory, without doing advanced things with search paths and such. After the file is found, a function is sought for every glyph, according to their postscript name. When the glyph is displayed for the first time, the function is called to grid-fit the outline according to your program.

void A() {
  <Code for capital A goes here>
}

void Zsmall() {
  <Code for small capital Z goes here>
}

Note: the postscript name Z.small will be linked to the function Zsmall(): the period has to be left out in the .tti file because it can't be used in identifiers in C.
Note 2: it is possible to call function A from within another function. Asmall() may do this, for example.
Note 3: the functions should not have any parameters, or they will not be linked to the glyph.

There is one additional function that is automatically linked. It has to be called prep() because it is put in the TrueType prep table. This function is executed every time the font size is changed. It may be used to set global variables, but it is mainly used to set CVT values.

The CVT Table

One of the most interesting aspects of TrueType instructions is the Control Value Table. It contains lots of common distances used in your font. For example, you may want to regularise all stems in a sans-serif font, by setting it to one below a certain threshold and rounding it to whole pixels otherwise. The stem then gets a value in the CVT table (say 100 font units) which is rounded every time the font size is changed by the prep() function.

#cvt stem: 100
// const uint stem = 0u;

void prep() {
  setCVT(stem, floor(getCVT(stem)+.5));
}

The first line of this piece of code defines the CVT table. Normally, this is a list of integers that may contain label definitions like stem:. Label definitions like stem: may come in handy when referencing the CVT value later. Internally, stem is defined as a constant with a value of 0u.

The CVT value is given in font units. However, when getCVT() is called, it returns a fixed number, that is, a number in pixel units. This provides an extremely simple way of converting distances in the font to actual distances in the current pixel size. After the stem size is rounded, the CVT value is set to the new value.

Predefined Functions

The aim of the TrueType instructions is to move points. For this, a large number of instructions are available. These instructions are represented as built-in functions in the TrueType Instruction Compiler. A call like moveDistance(1u,2u, 1u,3u, 3.0); is not compiled into a function call, but becomes an instruction call (which obviously takes only a few bytes). A description of the functions can be found at <not available yet>.