README for gasp tools

This directory contains some useful tools for refining the GASP table
settings in fonts.

Background

The GASP (Grid-fitting And Scan-conversion Procedure) table contains
data about which hinting and antialiasing method will produce the best
results. It exists in two versions. Version 0 selects between b/w
hinted, grayscale hinted, and grayscale unhinted renderings. However,
most modern Windows browsers implement ClearType, and generally
override the settings in the GASP table.

Version 1 provides additional flags that have an effect on rendering
of fonts with Microsoft's newer DirectWrite rendering technology (such
as used in Internet Explorer 9).  While there are many possible
combinations of flags, in IE9 the only flag that seems to have any
effect is GASP_SYMMETRIC_GRIDFIT (0x0008). When this flag is off,
rendering is similar to earlier ClearType GDI rendering, which often
has very serious artifacts when stems are not carefully aligned to
pixel boundaries, as well as roughness in larger sizes even with
carefully hinted fonts. When the flag is on, antialising is applied in
both X and Y directions, which generally results in smoother
rendering, but also lower contrast (a blurrier appearance).

For any given font file, it's likely that X-only antialiasing will
look better at some sizes, and XY antialiasing at others. The purpose
of this tool is to preview the font in a range of sizes (in the
browser), and to insert the updated GASP table into the font to
represent the best set of choices.

Building

These tools were developed on Linux and are not guaranteed to work on
other platforms, although it's likely it could be made to work.

You'll need an up-to-date version (as of November 2010) of the
FontForge python library. You should also have ttf2eot, and should
edit gasp-preview.py to point to the binary for that.

Using

First, create a scratch directory and run gasp-preview.py on your font
file. This will create a file "test.html" and some associated
resources. View this file in Internet Explorer 9 (or another browser
that supports the DirectWrite rendering subsystem).

A table presents each size in X-only and XY rendering variants. Click
on the variant that looks better to you. If neither choice is
selected, it will default to the value of the next smaller size (as is
represented visually by a pale yellow highlight).

The result of your choices is captured in a short code string. For
example, for Inconsolata, X looks best at 11 and 13 ppem, and XY looks
better at all other sizes. The corresponding code string is:
xy11x12xy13x14xy

You can apply this setting to the font using the setgasp.py script.
The first argument is the filename of the font, and the second is the
code string as above. Note that setgasp.py overwrites the font file -
be sure to save the old one if you care about it (or, better yet, use
a version control system such as Mercurial).

Additional notes

For poorly hinted fonts, DirectWrite rendering may actually be
significantly improved by suppressing the hinting (especially at
larger sizes). In theory, the GASP table provides a way to do this,
but in practice IE9 does not seem to respect the relevant
bits. Probably the best way to control this is to use the INSTCTRL
bytecode (likely wrapped in a conditional).
