ttfautohint is a library written in C that takes a TrueType font as the input, removes its bytecode instructions (if any), and returns a new font where all glyphs are bytecode hinted using the information given by FreeType’s auto-hinting module. The idea is to provide the excellent quality of the auto-hinter on platforms that don’t use FreeType.
The library has a single API function,
TTF_autohint, which is described below.
Bundled with the library there are two front-end programs,
ttfautohintGUI, being a command line program and an application with a Graphics User Interface (GUI), respectively.
To cite Wikipedia:
Font hinting (also known as instructing) is the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid. At low screen resolutions, hinting is critical for producing a clear, legible text. It can be accompanied by antialiasing and (on liquid crystal displays) subpixel rendering for further clarity.
and Apple’s TrueType Reference Manual:
For optimal results, a font instructor should follow these guidelines:
At small sizes, chance effects should not be allowed to magnify small differences in the original outline design of a glyph.
At large sizes, the subtlety of the original design should emerge.
In general, there are three possible ways to hint a glyph.
The font contains hints (in the original sense of this word) to guide the rasterizer, telling it which shapes of the glyphs need special consideration. The hinting logic is partly in the font and partly in the rasterizer. More sophisticated rasterizers are able to produce better rendering results.
This is how Type 1 and CFF hints work.
The font contains exact instructions (also called bytecode) on how to move the points of its outlines, depending on the resolution of the output device, and which intentionally distort the (outline) shape to produce a well-rasterized result. The hinting logic is in the font; ideally, all rasterizers simply process these instructions to get the same result on all platforms.
This is how TrueType hints work.
The font gets auto-hinted (at run-time). The hinting logic is completely in the rasterizer. No hints in the font are used or needed; instead, the rasterizer scans and analyzes the glyphs to apply corrections by itself.
This is how FreeType’s auto-hinter works; see below for more.
While it is relatively easy to specify PostScript hints (either manually or by an auto-hinter that works at font creation time), creating TrueType hints is far more difficult. There are at least two reasons:
TrueType instructions form a programming language, operating at a very low level. They are comparable to assembler code, thus lacking all high-level concepts to make programming more comfortable.
Here an example how such code looks like:
SVTCA PUSHB[ ] /* 3 values pushed */ 18 1 0 CALL[ ] PUSHB[ ] /* 2 values pushed */ 15 4 MIRP PUSHB[ ] /* 3 values pushed */ 7 3 0 CALL[ ]
Another major obstacle is the fact that font designers usually aren’t programmers.
It is very time consuming to manually hint glyphs. Given that the number of specialists for TrueType hinting is very limited, hinting a large set of glyphs for a font or font family can become very expensive.
The ttfautohint library brings the excellent quality of FreeType rendering to platforms that don’t use FreeType, yet require hinting for text to look good – like Microsoft Windows. Roughly speaking, it converts the glyph analysis done by FreeType’s auto-hinting module to TrueType bytecode. Internally, the auto-hinter’s algorithm resembles PostScript hinting methods; it thus combines all three hinting methods discussed previously.
The simple interface of the front-ends (both on the command line and with the GUI) allows quick hinting of a whole font with a few mouse clicks or a single command on the prompt. As a result, you get better rendering results with web browsers, for example.
Across Windows rendering environments today, fonts processed with ttfautohint look best with ClearType enabled. This is the default for Windows 7. Good visual results are also seen in recent MacOS X versions and GNU/Linux systems (including Android, ChromeOS, and other mobile operating systems) that use FreeType for rendering glyphs.
The goal of the project is to generate a ‘first pass’ of hinting that font developers can refine further for ultimate quality.
Fundamentally, there are two approaches to hinting. The older approach, let’s call it ‘sharp’, popular when text was rendered in pure black-and-white, was to make all stems round to full pixels so that in a text line, all stems would be either one pixel or (at a larger point size) two pixels. When grayscale antialiasing came about, this approach actually started harming the rendering rather than helping it, because the horizontal and vertical stems would render very dark but round or diagonal stems would render very light.
So a new approach was developed, let’s call it ‘fuzzy’, where all stems and other elements are equalized so that in grayscale (or ClearType) rendering, they all are of roughly equal color. This means that stems are not rounded to full pixels but in fact to fractions of a pixel. However, with black-and-white renderers, this approach yields poor results because in black-and-white you cannot render a fraction of a pixel, so some stems become one pixel and some become two.
In theory, a hybrid approach is possible, using TrueType conditional hints: If the rasterizer is black-and-white, ‘sharp’ rendering could happen, while if the rasterizer is ClearType, the ‘fuzzy’ rendering could be used. It is not intended to add black-and-white auto-hinting to ttfautohint. However, it is planned to develop an interface so that ttfautohint can cooperate with font editors, providing this hybrid hinting.
On all supported platforms (GNU/Linux, Windows, and Mac OS X), the GUI looks quite similar; the used toolkit is Qt, which in turn uses the platform’s native widgets.
Both the GUI and console version share the same features, to be discussed in the next subsection.
Warning: ttfautohint cannot always process a font a second time. If the font contains composite glyphs, and option
-c is used, reprocessing with ttfautohint will fail. For this reason it is strongly recommended to not delete the original, unhinted font so that you can always rerun ttfautohint.
ttfautohint [OPTION]... [IN-FILE [OUT-FILE]]
The command-line binary,
ttfautohint, works like a Unix filter, this is, it reads data from standard input if no input file name is given, and it sends its output to standard output if no output file name is specified.
A typical call looks like the following.
ttfautohint -v -f latn foo.ttf foo-autohinted.ttf
For demonstration purposes, here the same using a pipe and redirection. Note that Windows’s default command line interpreter,
cmd.exe, doesn’t support piping with binary files, unfortunately.
cat foo.ttf | ttfautohint -v -f latn > foo-autohinted.ttf
ttfautohintGUI doesn’t send any output to a console; however, it accepts the same command line options as
ttfautohint, setting default values for the GUI.
Long options can be given with one or two dashes, and with and without an equal sign between option and argument. This means that the following forms are acceptable:
-foo bar, and
Below, the section title refers to the command’s label in the GUI (if applicable), then comes the name of the corresponding long command line option and its short equivalent, followed by a description.
Background and technical details on the meaning of the various options are given afterwards.
See ‘Hint Sets’ for a definition and explanation.
The minimum PPEM value (in pixels) at which hint sets are created. The default value for n is 8.
The maximum PPEM value (in pixels) at which hint sets are created. The default value for n is 50.
Increasing the range given by
-r normally makes the font’s bytecode larger.
dflt. It is needed to specify the OpenType default script: After applying all features that are handled specially (like small caps or superscript), ttfautohint uses this value for the remaining features. The default value is
latn. See below for more details.
dflt. It gets used for for all glyphs that can’t be assigned to a script automatically. The default value is
none. See below for more details.
The hinting limit is the PPEM value (in pixels) where hinting gets switched off (using the
INSTCTRL bytecode instruction, not the
gasp table data); it does not influence the file size. The default value for n is 200, which means that the font is not hinted for PPEM values larger than 200.
Note that hinting in the range ‘hinting-range-max’ up to ‘hinting-limit’ uses the hinting configuration for ‘hinting-range-max’.
To omit a hinting limit, use
--hinting-limit=0 (or check the ‘No Hinting Limit’ box in the GUI). Since this causes internal math overflow in the rasterizer for large pixel values (> 1500px approx.) it is strongly recommended to not use this except for testing purposes.
Normally, ttfautohint rounds the x height to the pixel grid, with a slight preference for rounding up (to use the terminology of TrueType’s ‘Super Round’ bytecode instruction, the threshold is 5/8px). If this flag is set, values in the range 6 PPEM to n PPEM are much more often rounded up (setting the threshold to 13/16px). The default value for n is 14. Use this flag to increase the legibility of small sizes if necessary; you might get weird rendering results otherwise for glyphs like ‘a’ or ‘e’, depending on the font design.
To switch off this feature, use
--increase-x-height=0 (or check the ‘No x Height Increase’ box in the GUI). To switch off rounding the x height to the pixel grid in general, either partially or completely, see ‘x Height Snapping Exceptions’.
A list of comma separated PPEM values or value ranges at which no x height snapping shall be applied. A value range has the form value1
-value2, meaning value1 <= PPEM <= value2. value1 or value2 (or both) can be missing; a missing value is replaced by the beginning or end of the whole interval of valid PPEM values, respectively (6 to 32767). Whitespace is not significant; superfluous commas are ignored, and ranges must be specified in increasing order. For example, the string
"7-9, 11, 13-" means the values 7, 8, 9, 11, 13, 14, 15, etc. Consequently, if the supplied argument is
"-", no x height snapping takes place at all. The default is the empty string (
""), meaning no snapping exceptions.
Normally, x height snapping means a slight increase in the overall vertical glyph size so that the height of lowercase glyphs gets aligned to the pixel grid (this is a global feature, affecting all glyphs of a font). However, having larger vertical glyph sizes is not always desired, especially if it is not possible to adjust the
usWinDescent values from the font’s
OS/2 table so that they are not too tight. See ‘Windows Compatibility’ for more details.
Set the horizontal stem width (hinting) value for all scripts that lack proper standard characters in the font. The value is given in font units and must be a positive integer. If not set, ttfautohint uses a hard-coded default (50 units at 2048 units per EM, and linearly scaled for other UPEM values, for example 24 units at 1000 UPEM).
For symbol fonts, you need option
--fallback-script too (to set up a script at all).
In the GUI, uncheck the ‘Default Fallback Stem Width’ box to activate this feature.
This option makes ttfautohint add two artificial blue zones, positioned at the
usWinDescent values (from the font’s
OS/2 table). The idea is to help ttfautohint so that the hinted glyphs stay within this horizontal stripe since Windows clips everything falling outside.
There is a general problem with tight values for
usWinDescent; a good description is given in the Vertical Metrics How-To. Additionally, there is a special problem with tight values if used in combination with ttfautohint because the auto-hinter tends to slightly increase the vertical glyph dimensions at smaller sizes to improve legibility. This enlargement can make the heights and depths of glyphs exceed the range given by
If ttfautohint is part of the font creation tool chain, and the font designer can adjust those two values, a better solution instead of using option
-W is to reserve some vertical space for ‘padding’: For the auto-hinter, the difference between a top or bottom outline point before and after hinting is less than 1px, thus a vertical padding of 2px is sufficient. Assuming a minimum hinting size of 6ppem, adding two pixels gives an increase factor of 8÷6 = 1.33. This is near to the default baseline-to-baseline distance used by TeX and other sophisticated text processing applications, namely 1.2×designsize, which gives satisfying results in most cases. It is also near to the factor 1.25 recommended in the abovementioned how-to. For example, if the vertical extension of the largest glyph is 2000 units (assuming that it approximately represents the designsize), the sum of
usWinDescent could be 1.25×2000 = 2500.
In case ttfautohint is used as an auto-hinting tool for fonts that can be no longer modified to change the metrics, option
-W in combination with ‘
-X "-"’ to suppress any vertical enlargement should prevent almost all clipping.
By default, the components of a composite glyph get hinted separately. If this flag is set, the composite glyph itself gets hinted (and the hints of the components are ignored). Using this flag increases the bytecode size a lot, however, it might yield better hinting results.
If this option is used (and a font actually contains composite glyphs), ttfautohint currently cannot reprocess its own output for technical reasons, see below.
Process a font that ttfautohint would refuse otherwise because it can’t find a single standard character for any of the supported scripts.
For all scripts that lack proper standard characters, ttfautohint uses a default (hinting) value for the standard stem width instead of deriving it from a script’s set of standard characters (for the latin script, one of them is character ‘o’).
Use this option (usually in combination with the
--fallback-stem-width option) to hint symbol or dingbat fonts or math glyphs, for example, at the expense of possibly poor hinting results at small sizes.
Don’t add ttfautohint version and command line information to the version string or strings (with name ID 5) in the font’s
name table. In the GUI, it corresponds to value ‘None’ in the ‘ttfautohint info’ combo box.
This option is mutually exclusive with option
Add ttfautohint version and command line information to the version string or strings (with name ID 5) in the font’s
name table. In the GUI, it corresponds to value ‘Version and Parameters’ in the ‘ttfautohint info’ combo box.
This option is mutually exclusive with option
-I is set, the string ‘
ttfautohint (vNNN)’ gets added to the
name table (with NNN the current version); this correponds to value ‘Version’ in the ‘ttfautohint info’ combo box.
Add an SFNT table called
TTFA to the output font that holds a dump of all parameters; the data resembles the format of the
--debug option’s parameter listing. In particular, it lists all ttfautohint control instructions (which are not shown in the
name table info). This option is mainly for archival purposes so that all information used to create a font is stored in the font itself. Note that such a
TTFA table gets ignored by all TrueType rendering engines.
Forthcoming versions of the ttfautohint front-ends will be able to use this data so that a font can be processed another time with exactly the same parameters, thus providing a means for round-tripping fonts.
A string that gets appended to the family name in entries with IDs 1, 4, 6, 16, and 21 in the font’s
name table. Allowed input is ASCII in the range 0x20-0x7E except characters
Assuming an input family name ‘Foo’, a full name ‘Foo Bold’, and a family suffix ‘ 1’, the output family name will be ‘Foo 1’ and the full name ‘Foo 1 Bold’. For the PostScript name in ID 6, ttfautohint uses the suffix with space characters removed (for example ‘Foo1Bold’).
This option is mainly for testing purposes, enabling the operating system to simultaneously display several instances of a font that are processed with different ttfautohint parameters.
ttfautohint offers two different routines to handle (horizontal) stem widths and stem positions: ‘smooth’ and ‘strong’. The former uses discrete values that slightly increase the stem contrast with almost no distortion of the outlines, while the latter snaps both stem widths and stem positions to integer pixel values as much as possible, yielding a crisper appearance at the cost of much more distortion.
These two routines are mapped onto three possible rendering targets:
grayscale rendering, with or without optimization for subpixel positioning (e.g. Android)
‘GDI ClearType’ rendering: the rasterizer version, as returned by the GETINFO bytecode instruction, is in the range 36 <= version < 38 and ClearType is enabled (e.g. Windows XP)
‘DirectWrite ClearType’ rendering: the rasterizer version, as returned by the GETINFO bytecode instruction, is >= 38, ClearType is enabled, and subpixel positioning is enabled also (e.g. Internet Explorer 9 running on Windows 7)
GDI ClearType uses a mode similar to B/W rendering along the vertical axis, while DW ClearType applies grayscale rendering. Additionally, only DW ClearType provides subpixel positioning along the x axis. For what it’s worth, the rasterizers version 36 and version 38 in Microsoft Windows are two completely different rendering engines.
The command line option expects string to contain up to three letters with possible values ‘
g’ for grayscale, ‘
G’ for GDI ClearType, and ‘
D’ for DW ClearType. If a letter is found in string, the strong stem width routine is used for the corresponding rendering target (and smooth stem width handling otherwise). The default value is ‘
G’, which means that strong stem width handling is activated for GDI ClearType only. To use smooth stem width handling for all three rendering targets, use the empty string as an argument, usually connoted with ‘
In the GUI, simply set the corresponding check box to select the strong width routine for a given rendering target. If you unset the check box, the smooth width routine gets used.
The following images again use the font ‘Mertz Bold’.
-mfile (not in
If this checkbox is set, automatically regenerate the output file as soon as an input file (either the font or the control instructions file) gets modified.
Pressing the ‘Run’ button starts watching. If an error occurs, watching stops and must be restarted with the ‘Run’ button.
By default, fonts that have bit 1 set in the ‘fsType’ field of the
OS/2 table are rejected. If you have a permission of the font’s legal owner to modify the font, specify this command line option.
If this option is not set,
ttfautohintGUI shows a dialogue to handle such fonts if necessary.
On the console, print a brief documentation on standard output and exit. This doesn’t work with
ttfautohintGUI on MS Windows.
On the console, print version information on standard output and exit. This doesn’t work with
ttfautohintGUI on MS Windows.
Print a lot of debugging information on standard error while processing a font (you should redirect stderr to a file). This doesn’t work with
ttfautohintGUI on MS Windows.
To reduce the amount of debug data it is recommended to restrict the hinting process to a single PPEM value, e.g.,
ttfautohint --debug -l 15 -r 15 ... > debug.txt 2>&1
Real-Time Grid Fitting of Typographic Outlines is a scholarly paper that describes FreeType’s auto-hinter in some detail. Regarding the described data structures it is slightly out of date, but the algorithm itself hasn’t changed in general.
The next few subsections are mainly based on this article, introducing some important concepts. Note that ttfautohint only does hinting along the vertical direction (modifying y coordinates only).
A glyph consists of one or more contours (this is, closed curves). For example, glyph ‘O’ consists of two contours, while glyph ‘I’ has only one.
A segment is a series of consecutive points of a contour (including its Bézier control points) that are approximately aligned along a coordinate axis. A segment has one of three possible directions: left, right, or none (which means neither left nor right), derived from the TrueType outline directions. ttfautohint itself creates segments that contain at least two points. Using control instructions, however, it is possible to create one-point segments, which are useful for fine-tuning the hinting process.
An edge corresponds to a single coordinate value (allowing for a small threshold) on the main dimension that collects one or more segments, all pointing into the same direction (either left or right, all others are ignored). While finding segments is done on the unscaled outline, finding edges is bound to the device resolution. See below for an example.
In general, segments and edges pointing into different directions ‘repel’ each other, thus preventing alignment on the same vertical coordinate if they are near. Note that this is a simplification, but it should help understand how to manipulate and/or create segments in control instructions files.
The analysis to find segments and edges is specific to a writing system, see below.
The auto-hinter analyzes a font in two steps. Right now, everything described here happens for the horizontal axis only, providing vertical hinting.
This affects the hinting of all glyphs, trying to give them a uniform appearance.
Compute standard horizontal stem width of the font. The value is normally taken from glyphs that resemble letter ‘o’.
Compute blue zones, see below.
If the stem widths of single glyphs differ by a large value, or if ttfautohint fails to find proper blue zones, hinting becomes quite poor, possibly leading even to severe shape distortions.
||‘ـ’, U+0640, ARABIC TATWEEL|
|‘ل’, U+0644, ARABIC LETTER LAM|
|‘ح’, U+062D, ARABIC LETTER HAH|
||‘о’, U+043E, CYRILLIC SMALL LETTER O|
|‘О’, U+041E, CYRILLIC CAPITAL LETTER O|
||‘ठ’, U+0920, DEVANAGARI LETTER TTHA|
|‘व’, U+0935, DEVANAGARI LETTER VA|
|‘ट’, U+091F, DEVANAGARI LETTER TTA|
||‘ο’, U+03BF, GREEK SMALL LETTER OMICRON|
|‘Ο’, U+039F, GREEK CAPITAL LETTER OMICRON|
||‘ם’, U+05DD, HEBREW LETTER FINAL MEM|
||‘໐’, U+0ED0, LAO DIGIT ZERO|
||‘o’, U+006F, LATIN SMALL LETTER O|
|‘O’, U+004F, LATIN CAPITAL LETTER O|
|‘0’, U+0030, DIGIT ZERO|
||‘౦’, U+0C66, TELUGU DIGIT ZERO|
|‘౧’, U+0C67, TELUGU DIGIT ONE|
||‘า’, U+0E32, THAI CHARACTER SARA AA|
|‘ๅ’, U+0E45, THAI CHARACTER LAKKHANGYAO|
|‘๐’, U+0E50, THAI DIGIT ZERO|
||‘ₒ’, U+2092, LATIN SUBSCRIPT SMALL LETTER O|
|‘₀’, U+2080, SUBSCRIPT ZERO|
||‘ᵒ’, U+1D52, MODIFIER LETTER SMALL O|
|‘ᴼ’, U+1D3C, MODIFIER LETTER CAPITAL O|
|‘⁰’, U+2070, SUPERSCRIPT ZERO|
This is a per-glyph operation.
Find segments and edges.
Link edges together to find stems and serifs. The abovementioned paper gives more details on what exactly constitutes a stem or a serif and how the algorithm works.
Outlines of certain characters are used to determine blue zones. This concept is the same as with Type 1 fonts: All glyph points that lie in certain small horizontal zones get aligned vertically.
Here a series of tables that show the blue zone characters of the latin writing system’s available scripts; the values are hard-coded in the source code. Since the auto-hinter takes mean values it is not necessary that all characters of a zone are present.
|1||top of letters with vertical stroke||ا إ ل ك ط ظ|
|2||bottom of letters||ت ث ط ظ ك|
|1||top of capital letters||Б В Е П З О С Э|
|2||bottom of capital letters||Б В Е Ш З О С Э|
|3||top of small letters||х п н ш е з о с|
|4||bottom of small letters||х п н ш е з о с|
|5||bottom of descenders of small letters||р у ф|
|1||baseline (flat glyphs only)||क न म उ छ ट ठ ड|
|2||top of ascenders||ई ऐ ओ औ ि ी ो ौ|
|3||top of baseline||क म अ आ थ ध भ श|
|4||bottom of base characters||क म अ आ थ ध भ श|
|5||bottom of descenders||ु ृ|
Contrary to scripts like latin, the baseline in Devanagari is on the top. Note that some fonts have extreme variation in the height of the round elements in Zone 3; for this reason we also define Zone 1, which must be always present.
|1||top of capital letters||Γ Β Ε Ζ Θ Ο Ω|
|2||bottom of capital letters||Β Δ Ζ Ξ Θ Ο|
|3||top of ‘small beta’ like letters||β θ δ ζ λ ξ|
|4||top of small letters||α ε ι ο π σ τ ω|
|5||bottom of small letters||α ε ι ο π σ τ ω|
|6||bottom of descenders of small letters||β γ η μ ρ φ χ ψ|
|1||top of letters||ב ד ה ח ך כ ם ס|
|2||bottom of letters||ב ט כ ם ס צ|
|3||bottom of descenders of letters||ק ך ן ף ץ|
|1||top of letters||າ ດ ອ ມ ລ ວ ຣ ງ|
|2||bottom of letters||າ ອ ບ ຍ ຣ ຮ ວ ຢ|
|3||top of ascenders||ປ ຢ ຟ ຝ|
|4||top of large ascenders||ໂ ໄ ໃ|
|5||bottom of descenders||ງ ຊ ຖ ຽ ໆ ຯ|
|1||top of capital characters||₀ ₃ ₅ ₇ ₈|
|2||bottom of capital characters||₀ ₁ ₂ ₃ ₈|
|3||top of ‘small f’ like characters||ᵢ ⱼ ₕ ₖ ₗ|
|4||top of small characters||ₐ ₑ ₒ ₓ ₙ ₛ ᵥ ᵤ ᵣ|
|5||bottom of small characters||ₐ ₑ ₒ ₓ ₙ ₛ ᵥ ᵤ ᵣ|
|6||bottom of descenders of small characters||ᵦ ᵧ ᵨ ᵩ ₚ|
Subscript latin characters are similar to normal latin characters.
|1||top of capital letters||T H E Z O C Q S|
|2||bottom of capital letters||H E Z L O C U S|
|3||top of ‘small f’ like letters||f i j k d b h|
|4||top of small letters||x z r o e s c|
|5||bottom of small letters||x z r o e s c|
|6||bottom of descenders of small letters||p q g j y|
The ‘round’ characters (e.g. ‘OCQS’) from Zones 1, 2, and 5 are also used to control the overshoot handling; to improve rendering at small sizes, zone 4 gets adjusted to be on the pixel grid; cf. the
|1||top of capital characters||⁰ ³ ⁵ ⁷ ᵀ ᴴ ᴱ ᴼ|
|2||bottom of capital characters||⁰ ¹ ² ³ ᴱ ᴸ ᴼ ᵁ|
|3||top of ‘small f’ like characters||ᵇ ᵈ ᵏ ʰ ʲ ᶠ ⁱ|
|4||top of small characters||ᵉ ᵒ ʳ ˢ ˣ ᶜ ᶻ|
|5||bottom of small characters||ᵉ ᵒ ʳ ˢ ˣ ᶜ ᶻ|
|6||bottom of descenders of small characters||ᵖ ʸ ᵍ|
Superscript latin characters are similar to normal latin characters.
|1||top||ఇ ఌ ఙ ఞ ణ ఱ ౯|
|2||bottom||అ క చ ర ఽ ౨ ౬|
|1||top||บ เ แ อ ก า|
|2||bottom||บ ป ษ ฯ อ ย ฮ|
|3||ascender||ป ฝ ฟ|
|4||large ascender||โ ใ ไ|
|5||descender||ฎ ฏ ฤ ฦ|
|6||large descender||ญ ฐ|
|7||top of Thai digits||๐ ๑ ๓|
Aligning outlines along the grid lines is called grid fitting. It doesn’t necessarily mean that the outlines are positioned exactly on the grid, however, especially if you want a smooth appearance at different sizes. This is the central routine of the auto-hinter; its actions are highly dependent on the used writing system. Currently, only one writing system is available (latin), providing support for scripts like Latin or Greek.
Align edges linked to blue zones.
Fit edges to the pixel grid.
Align serif edges.
Handle remaining ‘strong’ points. Such points are not part of an edge but are still important for defining the shape. This roughly corresponds to the
IP TrueType instruction.
Everything else (the ‘weak’ points) is handled with an ‘IUP’ instruction.
The following images illustrate the hinting process, using glyph ‘a’ from the freely available font ‘Ubuntu Book’. The manual hints were added by Dalton Maag Ltd, the used application to create the hinting debug snapshots was FontForge.
In ttfautohint terminology, a hint set is the optimal configuration for a given PPEM (pixel per EM) value.
In the range given by the
--hinting-range-max options, ttfautohint creates hint sets for every PPEM value. For each glyph, ttfautohint automatically determines whether a new set should be emitted for a PPEM value if it finds that it differs from a previous one. For some glyphs it is possible that one set covers, say, the range 8px-1000px, while other glyphs need 10 or more such sets.
In the PPEM range below
--hinting-range-min, ttfautohint always uses just one set, in the PPEM range between
--hinting-limit, it also uses just one set.
One of the hinting configuration parameters is the decision which segments form an edge. For example, let us assume that two segments get aligned on a single horizontal edge at 11px, while two edges are used at 12px. This change makes ttfautohint emit a new hint set to accomodate this situation. The next images illustrate this, using a Cyrillic letter (glyph ‘afii10108’) from the ‘Ubuntu book’ font, processed with ttfautohint.
Obviously, the more hint sets get emitted, the larger the bytecode ttfautohint adds to the output font. To find a good value n for
--hinting-range-max, some experimentation is necessary since n depends on the glyph shapes in the input font. If the value is too low, the hint set created for the PPEM value n (this hint set gets used for all larger PPEM values) might distort the outlines too much in the PPEM range given by n and the value set by
--hinting-limit (at which hinting gets switched off). If the value is too high, the font size increases due to more hint sets without any noticeable hinting effects.
Similar arguments hold for
--hinting-range-min except that there is no lower limit at which hinting is switched off.
An example. Let’s assume that we have a hinting range 10 <= ppem <= 100, and the hinting limit is set to 250. For a given glyph, ttfautohint finds out that four hint sets must be computed to exactly cover this hinting range: 10-15, 16-40, 41-80, and 81-100. For ppem values below 10ppem, the hint set covering 10-15ppem is used, for ppem values larger than 100 the hint set covering 81-100ppem is used. For ppem values larger than 250, no hinting gets applied.
The ttfautohint library (and programs) supports two solutions for handling composite glyphs, to be controlled with option
--composites. This section contains some general information, then covers the case where the option is off, while the next section describes how ttfautohint behaves if this option is activated.
Regardless of the
--composites option, ttfautohint performs a scan over all composite glyphs to assure that components of a composite glyph inherit its style, as described later. However, components that are shifted vertically will be skipped. For example, if the glyph ‘Agrave’ uses a shifted ‘grave’ accent glyph, the accent is ignored. On the other hand, if there is a glyph ‘agrave’ that uses the same ‘grave’ glyph vertically unshifted, ‘grave’ does inherit the style.
--composites is off, components are hinted separately, then put together. Separate hinting implies that the current style’s blue zones are applied to all subglyphs in its original, unshifted positions. In case you want to shift components vertically, it is mandatory to set bit 2 (value 4),
ROUND_XY_TO_GRID, in the flag variable of the composite glyph description to get visually pleasing results, as the images below demonstrate.
--composites is used, ttfautohint doesn’t hint subglyphs of composite glyphs separately. Instead, it hints the whole glyph, this is, composites get recursively expanded internally so that they form simple glyphs, then hints are applied – this is the normal working mode of FreeType’s auto-hinter.
One problem, however, must be solved: Hinting for subglyphs (which usually are used as normal glyphs also) must be deactivated so that nothing but the final bytecode of the composite gets executed.
The trick used by ttfautohint is to prepend a composite element called ‘.ttfautohint’, a dummy glyph with a single point, and which has a single job: Its bytecode increases a variable (to be more precise, it is a CVT register called
cvtl_is_subglyph in the source code), indicating that we are within a composite glyph. The final bytecode of the composite glyph eventually decrements this variable again.
As an example, let’s consider composite glyph ‘Agrave’ (‘À’), which has the subglyph ‘A’ as the base and ‘grave’ as its accent. After processing with ttfautohint it consists of three components: ‘.ttfautohint’, ‘A’, and ‘grave’ (in this order).
|A||do nothing because
|grave||do nothing because
|apply hints because
Some technical details (which you might skip): All glyph point indices get adjusted since each ‘.ttfautohint’ subglyph shifts all following indices by one. This must be done for both the bytecode and one subformat of OpenType’s
GPOS anchor tables.
While this approach works fine on all tested platforms, there is one single drawback: Direct rendering of the ‘.ttfautohint’ subglyph (this is, rendering as a stand-alone glyph) disables proper hinting of all glyphs in the font! Under normal circumstances this never happens because ‘.ttfautohint’ doesn’t have an entry in the font’s
cmap table. (However, some test and demo programs like FreeType’s
ftview application or other glyph viewers that are able to bypass the
cmap table might be affected.)
In FreeType terminology, a writing system is a set of functions that provides auto-hinting for certain scripts. Right now, only two writing systems from FreeType’s auto-hinter are available in ttfautohint: ‘dummy’ and ‘latin’. The former handles the ‘no-script’ case; details to ‘latin’ follow in the next section.
ttfautohint needs to know which script should be used to hint a specific glyph. To do so, it checks a glyph’s Unicode character code whether it belongs to a given script.
See ‘Character Ranges’ for a complete list of all handled scripts and its ranges. This list is auto-generated from a source code file, covering the `latin’ writing system. It also covers some non-latin scripts (in the Unicode sense) that have similar typographical properties.
In ttfautohint, scripts are identified by four-character tags (if there are less characters, spaces are appended). The value
none indicates ‘no script’.
Each script is represented by two tables to handle ‘base’ and ‘non-base’ characters. For ttfautohint, a non-base character is something that should not be affected by blue zones, regardless of whether this is a spacing or no-spacing glyph. In other words, non-base characters are hinted using a script’s default stem width without applying blue zones.
Right now, there are two pseudo-scripts that are used as fallbacks:
latp, used for latin subscript and superscript characters, respectively. Its main usage is support of phonetic alphabets like the IPA, which intermix those characters with normal characters sitting on the baseline, and which are not specially handled in corresponding OpenType features like
If a glyph’s character code is not covered by a script range, it is not hinted (or rather, it gets hinted by the ‘dummy’ auto-hinting module that essentially does nothing). This can be changed by specifying a fallback script; see option
(Please read the OpenType specification for details on features,
GPOS tables, and how they relate to scripts.)
For modern OpenType fonts, character ranges are not sufficient to handle scripts.
Due to glyph substitution in the font (as specified in a font’s
GSUB table), which handles ligatures and similar typographic features, there is no longer a one-to-one mapping from an input Unicode character to a glyph index. Some ligatures, like ‘fi’, actually do have Unicode values for historical reasons, but most of them don’t. While it is possible to map ligature glyphs into Unicode’s Private Use Area (PUA), code values from this area are arbitrary by definition and thus unusable for ttfautohint.
Some features like
sups (for handling superscript) completely change the appearance and even vertical position of the affected glyphs. Obviously, the blue zones for ‘normal’ glyphs no longer fit, thus the auto-hinter puts them into a separate group (called style in FreeType speak), having its own set of blue zones.
||petite capitals from capitals|
||small capitals from capitals|
There are two conditions to get a valid style for a feature in a given script.
One of the script’s standard characters must be available in the feature.
The feature must provide characters to form at least one blue zone; see above.
An additional complication is that features from the above table might use data not only from the
GSUB but also from the
GPOS table, containing information for glyph positioning. For example, the
sups feature for superscripts might use the same glyphs as the
subs feature for subscripts, simply moved up. ttfautohint skips such vertically shifted glyphs (except for accessing standard characters) because glyph positioning happens after hinting. Continuing our example, the
sups feature wouldn’t form a style, contrary to
subs, which holds the unshifted glyphs.
The remaining OpenType features of a script are not handled specially; the affected glyphs are simply hinted together with the ‘normal’ glyphs of the script.
Note that a font might still contain some features not covered yet: OpenType has the concept of a default script; its data gets used for all scripts that aren’t explicitly handled in a font. By default, ttfautohint unifies all affected glyphs from default script features with the
latn script. This can be changed with option
--default-script, if necessary.
ttfautohint uses the HarfBuzz library for handling OpenType features.
ttfautohint touches almost all SFNT tables within a TrueType or OpenType font. Note that only OpenType fonts with TrueType outlines are supported. OpenType fonts with a
CFF table (this is, with PostScript outlines) won’t work.
glyf: All hints in the table are replaced with new ones. If option
--composites is used, one glyph gets added (namely the ‘.ttfautohint’ glyph) and all composites get an additional component.
fpgm: These tables get replaced with data necessary for the new hinting bytecode.
gasp: Set up to always use grayscale rendering, for all sizes, with grid-fitting for standard hinting, and symmetric grid-fitting and symmetric smoothing for horizontal subpixel hinting (ClearType).
DSIG: If it exists, it gets replaced with a dummy version. ttfautohint can’t digitally sign a font; you have to do that afterwards.
name: The ‘version’ entries are modified to add information about the parameters that have been used for calling ttfautohint. This can be controlled with the
post: Updated to fit the additional ‘.ttfautohint’ glyph, the additional subglyphs in composites, and the new hinting bytecode.
hdmx: Since ttfautohint doesn’t do any horizontal hinting, those tables are superfluous and thus removed.
VDMX: Removed, since it depends on the original bytecode, which ttfautohint removes. A font editor might recompute the necessary data later on.
Recent versions of FreeType have an experimental extension for handling subpixel hinting; it is off by default and can be activated by defining the macro
TT_CONFIG_OPTION_SUBPIXEL_HINTING at compile time. This code has been contributed mainly by Infinality, being a subset of his original patch. Many GNU/Linux distributions activate this code, or provide packages to activate it.
This extension changes the behaviour of many bytecode instructions to get better rendering results. However, not all changes are global; some of them are specific to certain fonts. For example, it contains font-specific improvements for the ‘DejaVu Sans’ font family. The list of affected fonts is hard-coded; it can be found in FreeType’s source code file
If you are going to process such specially-handled fonts with ttfautohint, serious rendering problems might show up. Since ttfautohint (intentionally) doesn’t change the font name in the
name table, the Infinality extension has no chance to recognize that the hints are different. All such problems vanish if the font gets renamed in its
name table (the name of the font file itself doesn’t matter).
Fonts with an incorrect Unicode
cmap table will not be properly hinted by ttfautohint. Especially older fonts do cheat; for example, there exist Hebrew fonts that map its glyphs to character codes ‘A’, ‘B’, etc., to make them work with non-localized versions of Windows 98, say.
Since ttfautohint needs to find both standard and blue zone characters, it relies on correct Unicode values. If you want to handle such fonts, please fix their
cmap tables accordingly.
The central concept of ttfautohint’s hinting algorithm, as discussed above, is to identify horizontal segments at extremum positions, especially for blue zones. If such a segment is missing, it cannot be associated with a blue zone, possibly leading to irregular heights for the particular glyph.
Normally, a segment has a horizontal length of at least 20 font units (assuming 2048 units per EM)1. Using a Control Instructions File, however, it is possible to define additional segments at arbitrary points that help overcome this restriction, making it possible to fix (most of) such problems.
ttfautohint doesn’t handle diagonal lines specially. For thin outlines, this might lead to strokes that look too thick at smaller sizes. A font designer might compensate this to a certain amount by slightly reducing the stroke width of diagonal lines. However, in many cases the sub-optimal appearance of a stroke with borders that don’t exactly fit the pixel grid is not the outline itself but an incorrect gamma value of the monitor: People tend to not properly adjust it, and the default values of most operating systems are too low, causing too much darkening of such strokes. It is thus of vital importance to compare ttfautohint’s results with similar fonts to exclude any systematic effect not related to the outlines themselves.
An entry in a control instructions file has various syntax forms, which are discussed here. Brackets indicate optional elements.
font‑idx gives the index of the font in a TrueType Collection, starting with value 0. If missing, it is set to zero. For normal TrueType fonts, only value zero is valid. A font index can be specified in decimal, octal, or hexadecimal format, the latter two indicated by the prefixes
glyph‑id is either a glyph’s name as listed in the
post SFNT table or a glyph index. A glyph name consists of characters from the set ‘
A-Za-z0-9._’ only and does not start with a digit or period, with the exceptions of the names ‘
.notdef’ and ‘
.null’. A glyph index starts with value 0 can be specified in decimal, octal, or hexadecimal format, the latter two indicated by the prefixes
0x, respectively. Glyph names are internally converted to glyph indices.
points are number ranges, see ‘x Height Snapping Exceptions’ for the syntax.
Similar to the Bourne shell (
bash), a comment starts with character ‘
#’; the rest of the line is ignored. An empty line is ignored also. Both the newline character and ‘
;’ can be used as a separator between exception entries. A trailing ‘
\’ at the end of a line continues the current line on the next one.
A control instructions file is parsed line by line; later entries override earlier entries (in case there is something to override).
[ font-idx ] script feature
script is a four-letter name of one of the scripts supported by ttfautohint. feature is one of the four-letter names of features supported by ttfautohint.
The elements of glyph-ids are a list of comma separated glyph-id values or value ranges. Note that is not necessary that elements are specified in increasing order.
Assuming that a font contains superscript digits ‘zero.sups’ to ‘nine.sups’ together with the glyphs ‘a.sups’ and ‘o.sups’, use a line
cyrl sups @ zero.sups-nine.sups, a.sups, o.sups
to add those glyphs to the style handling Cyrillic superscript glyphs. However, it is still necessary that the selected script contains proper Blue Zone characters, otherwise those glyphs aren’t handled at all.
--debug command line option to see how ttfautohint assigns glyph indices of a font to styles.
The following syntax forms allows adjustments of a glyph’s hinting process.
[ font‑idx ] glyph‑id
ight] points [
The mutually exclusive parameters
right (which can be abbreviated as ‘
l’ and ‘
r’, respectively) indicate that the following points have left or right ‘out’ direction, respectively, overriding ttfautohint’s algorithm for setting point directions. The ‘out direction’ of a point is the direction of the outline leaving the point (or passing the control point). If the specified direction is identical to what ttfautohint computes, nothing special happens. Otherwise, a one-point segment with the specified direction gets created, see above. By default, its length is zero. Setting left‑offset and right‑offset, you can change the segment’s horizontal start and end position relative to the point position. left‑offset and right‑offset are integers measured in font units.
The following five images, displaying glyphs ‘O’ and ‘Q’ from the font Halant-Regular, demonstrate how to use direction changes.
[ font‑idx ] glyph‑id
nodir (or ‘
n’) sets the ‘out’ direction of the following points to ‘no direction’, this is, neither left nor right. If the specified direction is identical to what ttfautohint computes, nothing special happens. Otherwise, ttfautohint no longer considers those points as part of horizontal segments, thus treating them as ‘weak’ points.
Modifying or adding segments doesn’t directly modify the outlines; it only influences the hinting process.
[ font‑idx ] glyph‑id
oint] points [
shift] x‑shift ] [
shift] y‑shift ]
The mutually exclusive parameters
point (which can be abbreviated as ‘
t’ and ‘
p’, respectively) make ttfautohint apply delta exceptions for the given points, shifting them by the given values. Delta exceptions entered with
touch are applied before the final ‘IUP’ (interpolate untouched points) instructions in a glyph’s bytecode, exceptions entered with
point after ‘IUP’ (please consult Greg Hitchcock’s ClearType Whitepaper for more on pre-IUP and post-IUP delta hints). Additionally, the
touch parameter makes the bytecode touch the affected points; such points are no longer affected by ‘IUP’ at all. Note that in ClearType mode all deltas along the x axis are discarded, and deltas along the y axis are only executed for touched points. As a consequence, vertical delta exceptions entered with
point should not be used in ClearType mode.2
ppems, similar to points, are number ranges, see ‘x Height Snapping Exceptions’ for the syntax.
x‑shift and y‑shift represent real numbers that get rounded to multiples of 1/8 pixels. The entries for
y’) are optional; if missing, the corresponding value is set to zero. If both values are zero, the delta exception entry is ignored as a whole.
Values for x‑shift and y‑shift must be in the range [−1.0;1.0]. Values for ppems must be in the range [6;53]. Values for points are limited by the number of points in the glyph.
Note that only character ‘
.’ is recognized as a decimal point, and a thousands separator is not accepted.
As an example for delta instructions, let’s assume that you want to shift points 2, 3, and 4 in glyph `Aacute’ at ppem sizes 12 and 13 by a vertical amount of 0.25 pixels. This corresponds to the line
Aacute touch 2-4 yshift 0.25 @ 12, 13
in a control instructions file. Since we use
touch and not
point, points 2, 3, and 4 are no longer subject to the final ‘IUP’ instruction, which interpolates weak, untouched point positions between strong, touched ones, cf. the description here.
This section documents the single function of the ttfautohint library,
TTF_autohint, together with its callback functions,
TA_Info_Func. All information has been directly extracted from the
ttfautohint.h header file.
Some default values.
#define TA_HINTING_RANGE_MIN 8 #define TA_HINTING_RANGE_MAX 50 #define TA_HINTING_LIMIT 200 #define TA_INCREASE_X_HEIGHT 14
An error type.
typedef int TA_Error;
A callback function to get progress information. curr_idx gives the currently processed glyph index; if it is negative, an error has occurred. num_glyphs holds the total number of glyphs in the font (this value can’t be larger than 65535).
curr_sfnt gives the current subfont within a TrueType Collection (TTC), and num_sfnts the total number of subfonts.
If the return value is non-zero,
TTF_autohint aborts with
TA_Err_Canceled. Use this for a ‘Cancel’ button or similar features in interactive use.
progress_data is a void pointer to user-supplied data.
typedef int (*TA_Progress_Func)(long curr_idx, long num_glyphs, long curr_sfnt, long num_sfnts, void* progress_data);
A callback function to get error information.
error is the value
TTF_autohint returns. See file
ttfautohint-errors.h for a list. Error codes not in this list are directly taken from FreeType; see the FreeType header file
fterrdef.h for more.
error_string, if non-NULL, is a pointer to an error message that represents error.
The next three parameters help identify the origin of text string parsing errors. linenum, if non-zero, contains the line number. line, if non-NULL, is a pointer to the input line that can’t be processed. errpos, if non-NULL, holds a pointer to the position in line where the problem occurs.
error_data is a void pointer to user-supplied data.
typedef void (*TA_Error_Func)(TA_Error error, const char* error_string, unsigned int linenum, const char* line, const char* errpos, void* error_data);
A callback function to access or modify strings in the
name table; it is called in a loop that iterates over all
name table entries. If defined,
TA_Info_Post_Func gets executed after this loop so that the collected data can be written back to the
platform_id, encoding_id, language_id, and name_id are the identifiers of a
name table entry pointed to by str with a length pointed to by str_len (in bytes; the string has no trailing NULL byte). Please refer to the OpenType specification of the
name table for a detailed description of the various parameters, in particular which encoding is used for a given platform and encoding ID.
The string str is allocated with
malloc; the application should reallocate the data if necessary, ensuring that the string length doesn’t exceed 0xFFFF.
info_data is a void pointer to user-supplied data.
If an error occurs, return a non-zero value and don’t modify str and str_len (such errors are handled as non-fatal).
typedef int (*TA_Info_Func)(unsigned short platform_id, unsigned short encoding_id, unsigned short language_id, unsigned short name_id, unsigned short* str_len, unsigned char** str, void* info_data);
A callback function, giving the application the possibility to access or modify strings in the
name table after
TA_Info_Func has iterated over all
name table entries.
It is expected that
TA_Info_Func stores pointers to the
name table entries it wants to access or modify; the only parameter is thus info_data, which is a void pointer to the user-supplied data already provided to
TA_Info_Func. Obviously, calling
TA_Info_Func undefined has no effect.
name table strings are allocated with
malloc; the application should reallocate the data if necessary, ensuring that no string length exceeds 0xFFFF.
If an error occurs, return a non-zero value and don’t modify the affected string and string length (such errors are handled as non-fatal).
typedef int (*TA_Info_Post_Func)(void* info_data);
Read a TrueType font, remove existing bytecode (in the SFNT tables
glyf), and write a new TrueType font with new bytecode based on the autohinting of the FreeType library.
It expects a format string options and a variable number of arguments, depending on the fields in options. The fields are comma separated; whitespace within the format string is not significant, a trailing comma is ignored. Fields are parsed from left to right; if a field occurs multiple times, the last field’s argument wins. The same is true for fields that are mutually exclusive. Depending on the field, zero or one argument is expected.
Note that fields marked as ‘not implemented yet’ are subject to change.
A pointer of type
FILE* to the data stream of the input font, opened for binary reading. Mutually exclusive with
A pointer of type
const char* to a buffer that contains the input font. Needs
in-buffer-len. Mutually exclusive with
A value of type
size_t, giving the length of the input buffer. Needs
A pointer of type
FILE* to the data stream of the output font, opened for binary writing. Mutually exclusive with
A pointer of type
char** to a buffer that contains the output font. Needs
out-buffer-len. Mutually exclusive with
out-file. Deallocate the memory with
A pointer of type
size_t* to a value giving the length of the output buffer. Needs
A pointer of type
FILE* to the data stream of control instructions. Mutually exclusive with
See ‘Control Instructions’ for the syntax used in such a file or buffer.
A pointer of type
const char* to a buffer that contains control instructions. Needs
control-buffer-len. Mutually exclusive with
A value of type
size_t, giving the length of the control instructions buffer. Needs
A pointer of type
TA_Progress_Func, specifying a callback function for progress reports. This function gets called after a single glyph has been processed. If this field is not set or set to NULL, no progress callback function is used.
A pointer of type
void* to user data that is passed to the progress callback function.
A pointer of type
unsigned char** to a string (in UTF-8 encoding) that verbally describes the error code. You must not change the returned value.
A pointer of type
TA_Error_Func, specifying a callback function for error messages. This function gets called right before
TTF_autohint exits. If this field is not set or set to NULL, no error callback function is used.
Use it as a more sophisticated alternative to
A point of type
void* to user data that is passed to the error callback function.
A pointer of type
TA_Info_Func, specifying a callback function for manipulating the
name table. This function gets called for each
name table entry. If not set or set to NULL,
TA_Info_Func is not called.
A pointer of type
TA_Info_Post_Func, specifying a callback function for manipulating the
name table. It is called after the function specified with
info-callback has iterated over all
name table entries. If not set or set to NULL,
TA_Info_Post_Func is not called.
A pointer of type
void* to user data that is passed to the info callback functions.
If this integer is set to 1, lots of debugging information is print to stderr. The default value is 0.
An integer (which must be larger than or equal to 2) giving the lowest PPEM value used for autohinting. If this field is not set, it defaults to
An integer (which must be larger than or equal to the value of
hinting-range-min) giving the highest PPEM value used for autohinting. If this field is not set, it defaults to
An integer (which must be larger than or equal to the value of
hinting-range-max) that gives the largest PPEM value at which hinting is applied. For larger values, hinting is switched off. If this field is not set, it defaults to
TA_HINTING_LIMIT. If it is set to 0, no hinting limit is added to the bytecode.
If this integer is set to 1, composite glyphs get separate hints. This implies adding a special glyph to the font called ‘.ttfautohint’. Setting it to 0 (which is the default), the hints of the composite glyphs’ components are used. Adding hints for composite glyphs increases the size of the resulting bytecode a lot, but it might deliver better hinting results. However, this depends on the processed font and must be checked by inspection.
An integer (1 for ‘on’ and 0 for ‘off’, which is the default) to specify whether native TrueType hinting of the input font shall be applied to all glyphs before passing them to the (internal) autohinter. The used resolution is the em-size in font units; for most fonts this is 2048ppem. Use this only if the old hints move or scale subglyphs independently of the output resolution, for example some exotic CJK fonts.
pre-hinting is a deprecated alias name for this option.
An integer (1 for ‘on’ and 0 for ‘off’, which is the default) that specifies whether horizontal stems should be snapped and positioned to integer pixel values for normal grayscale rendering.
An integer (1 for ‘on’, which is the default, and 0 for ‘off’) that specifies whether horizontal stems should be snapped and positioned to integer pixel values for GDI ClearType rendering, this is, the rasterizer version (as returned by the GETINFO bytecode instruction) is in the range 36 <= version < 38 and ClearType is enabled.
An integer (1 for ‘on’ and 0 for ‘off’, which is the default) that specifies whether horizontal stems should be snapped and positioned to integer pixel values for DW ClearType rendering, this is, the rasterizer version (as returned by the GETINFO bytecode instruction) is >= 38, ClearType is enabled, and subpixel positioning is enabled also.
An integer. For PPEM values in the range 6 <= PPEM <=
increase-x-height, round up the font’s x height much more often than normally (to use the terminology of TrueType’s ‘Super Round’ bytecode instruction, the threshold gets increased from 5/8px to 13/16px). If it is set to 0, this feature is switched off. If this field is not set, it defaults to
TA_INCREASE_X_HEIGHT. Use this flag to improve the legibility of small font sizes if necessary.
A pointer of type
const char* to a null-terminated string that gives a list of comma separated PPEM values or value ranges at which no x height snapping shall be applied. A value range has the form value1
-value2, meaning value1 <= PPEM <= value2. value1 or value2 (or both) can be missing; a missing value is replaced by the beginning or end of the whole interval of valid PPEM values, respectively. Whitespace is not significant; superfluous commas are ignored, and ranges must be specified in increasing order. For example, the string
"3, 5-7, 9-" means the values 3, 5, 6, 7, 9, 10, 11, 12, etc. Consequently, if the supplied argument is
"-", no x height snapping takes place at all. The default is the empty string (
""), meaning no snapping exceptions.
If this integer is set to 1, two artificial blue zones are used, positioned at the
usWinDescent values (from the font’s
OS/2 table). The idea is to help ttfautohint so that the hinted glyphs stay within this horizontal stripe since Windows clips everything falling outside. The default is 0.
A string consisting of four lowercase characters that specifies the default script for OpenType features. After applying all features that are handled specially, use this value for the remaining features. The default value is
"latn"; if set to
"none", no script is used. Valid values can be found in the header file
A string consisting of four lowercase characters that specifies the default script for glyphs that can’t be mapped to a script automatically. If set to
"none" (which is the default), no script is used. Valid values can be found in the header file
Set this integer to 1 if you want to process a font that ttfautohint would refuse otherwise because it can’t find a single standard character for any of the supported scripts. ttfautohint then uses a default (hinting) value for the standard stem width instead of deriving it from a script’s set of standard characters (for the latin script, one of them is character ‘o’). The default value of this option is 0.
Set the horizontal stem width (hinting) value for all scripts that lack proper standard characters. The value is given in font units and must be a positive integer. If not set, or the value is zero, ttfautohint uses a hard-coded default (50 units at 2048 units per EM, and linearly scaled for other UPEM values, for example 24 units at 1000 UPEM).
For symbol fonts (i.e., option
symbol is given),
fallback-stem-width has an effect only if
fallback-script is set also.
If the font has set bit 1 in the ‘fsType’ field of the
OS/2 table, the ttfautohint library refuses to process the font since a permission to do that is required from the font’s legal owner. In case you have such a permission you might set the integer argument to value 1 to make ttfautohint handle the font. The default value is 0.
If set to 1, ttfautohint creates an SFNT table called
TTFA and fills it with information on the parameters used while calling
TTF_autohint. The format of the output data resembles the information at the very beginning of the dump emitted by option
debug. The default value is 0.
Main use of this option is for font editing purposes. For example, after a font editor has added some glyphs, a front-end to
TTF_autohint can parse
TTFA and feed the parameters into another call of
TTF_autohint. The new glyphs are then hinted while hints of the old glyphs stay unchanged.
If this option is not set, and the font to be processed contains a
TTFA table, it gets removed.
Note that such a
TTFA table gets ignored by all font rendering engines. In TrueType Collections, the
TTFA table is added to the first subfont.
If set to 1, remove all hints from the font. All other hinting options are ignored.
Obviously, it is necessary to have an input and an output data stream. All other options are optional.
hinting-range-max specify the range for which the autohinter generates optimized hinting code. If a PPEM value is smaller than the value of
hinting-range-min, hinting still takes place but the configuration created for
hinting-range-min is used. The analogous action is taken for
hinting-range-max, only limited by the value given with
hinting-limit. The font’s
gasp table is set up to always use grayscale rendering with grid-fitting for standard hinting, and symmetric grid-fitting and symmetric smoothing for horizontal subpixel hinting (ClearType).
ttfautohint can process its own output a second time only if option
hint-composites is not set (or if the font doesn’t contain composite glyphs at all). This limitation might change in the future.
TA_Error TTF_autohint(const char* options, ...);
Please read the files
INSTALL.git (both part of the source code bundle) for instructions how to compile the ttfautohint library together with its front-ends using a POSIX compatible shell and compiler.
The generic instructions should work just fine. Since ttfautohint depends on Qt version 4.x.x, FreeType version 2.4.5 or newer, and HarfBuzz version 0.9.19 or newer, you should install packages for these libraries (called ‘libqt4’, ‘libfreetype6’3, and ‘libharfbuzz0’ or similar) together with its development bundles (called ‘libqt4-devel’, ‘freetype2-devel’, and ‘harfbuzz-devel’ or similar) before running ttfautohint’s
ttfautohintGUI.exe are available, being statically linked to Qt, FreeType, and HarfBuzz. This means that the two programs are not dependent on any other program-specific DLL, and you can move them to any place you like.
Hints for compilation with the MinGW environment are given in
Right now, only a precompiled binary
ttfautohint is offered; a ready-to-run app bundle for the GUI version is not yet available.
Detailed instructions to compile both
ttfautohintGUI can be found on ttfautohint’s homepage.
Copyright © 2011-2015 by .
Portions Copyright © 2011-2015 by .
Portions Copyright © 2014 by .
This file is part of the ttfautohint library, and may only be used, modified, and distributed under the terms given in
COPYING. By continuing to use, modify, or distribute this file you indicate that you have read
COPYING and understand and accept it fully.
COPYING mentioned in the previous paragraph is distributed with the ttfautohint library.
||Arabic Presentation Forms-A|
||Arabic Presentation Forms-B|
||Arabic Mathematical Alphabetic Symbols|
There are some characters in the Devanagari Unicode block that are generic to Indic scripts; we omit them so that their presence doesn’t trigger Devanagari.
|(omitting U+093C nukta)|
|(omitting U+0951 udatta, U+0952 anudatta)|
|(omitting U+0964 danda, U+0965 double danda)|
||(new) Rupee sign|
||Greek and Coptic|
||Alphab. Present. Forms (Hebrew)|
||Basic Latin (no control chars)|
||Latin-1 Supplement (no control chars)|
||Spacing Modifier Letters|
||Combining Diacritical Marks|
||Combining Diacritical Marks Extended|
||Phonetic Extensions Supplement|
||Combining Diacritical Marks Supplement|
||Latin Extended Additional|
||Currency Symbols …|
||… except new Rupee sign|
||Alphab. Present. Forms (Latin Ligs)|
||Mathematical Alphanumeric Symbols|
||some small subscript letters|
||subscript digits and letters|
||latin subscript small letter j|
||feminine ordinal indicator|
||superscript two and three|
||superscript one, masc. ord. indic.|
||some latin superscript mod. letters|
||some IPA modifier letters|
||latin superscript modifier letters|
||modifier letter cyrillic en|
||more modifier letters|
||superscript digits and letters|
||modifier letter capital v|
||modifier letter us|
||more modifier letters|
||more modifier letters|
Support for Thai and Lao scripts.
Support for the Arabic script.
Better support for scripts that contain superscript-like and subscript-like glyphs, e.g., the International Phonetic Alphabet (IPA).
Accents and other `non-base’ glyphs are now hinted without snapping to blue zones.
A new control instruction syntax form was added to adjust the mapping between glyphs and styles. Right now, its usage is quite limited; a forthcoming version will give much more flexibility.
touch keyword in a delta instructions file was buggy: If used for a point
P at a ppem value
s, it sometimes led to unwanted movements of
P for ppem values unequal to
s, thus causing outline distortions.
Keywords in control instruction files can be more verbose to increase readability. You can now use
, andy`, respectively.
A new control instruction keyword
touch was added to apply delta instructions before the final IUP bytecode commands, also `touching’ the affected points (to use the TrueType instructions terminology). Such deltas do work even with ClearType if applied to the non-ClearType direction.
Support for the Telugu script.
The amount of information about ttfautohint and its parameters that gets added to the
name table by default has been reduced. A new option
--detailed-info restores the previous behaviour.
ttfautohintGUI crashed if not used with a control instruction file.
ttfautohintGUI now correctly switches to a horizontal two-column layout if the standard one-column layout would exceed the screen height.
A new option
--family-suffix makes it possible to append a suffix to a font’s family name in the
name table. This can be useful during the development process: It helps the operating system to simultaneously display several instances of a font that are processed with different ttfautohint parameters.
The new library option
info-post-callback helps in processing data from the
It is now possible to control the hinting process at a very low level using a ‘control instructions’ file. Right now, two modes are supported:
Adding segments and changing segment directions.
Applying delta exceptions. Note that this doesn’t really work in ClearType.
Please see the documentation for a description and a small tutorial.
In the command-line front-end, use option
--control-file to load such a file.
The idea is to dock ttfautohintGUI to your favourite font and text editor instead of adding a cheap text editor to ttfautohintGUI itself.
With the new option
--fallback-stem-width it is now possible to set a default stem width for all scripts that lack proper standard characters in the font.
--adjust-subglyphs for option
--pre-hinting to better describe its functionality. The short form
-p stays unchanged.
--ttfa-table to add an SFNT table
TTFA to the output font, containing an ASCII dump of all used ttfautohint parameters (including control instructions). Right now, this is mainly for archiving purposes. Forthcoming versions of ttfautohint will be able to re-use this data if a font gets re-processed.
A harmless buglet was fixed that made the
glyf table too large by one byte under some circumstances.
A bug fix taken from FreeType, correcting a crash for unusual outlines.
Better handling of TTC files.
New library options
error-callback-data for improved diagnostics. [No change in the front-ends except better error messages.]
Many other, minor fixes and improvements.
Support for the Devanagari script.
Bug fixes in the computation of strong stem widths. GDI hinting now gives much more consistent results.
Better recognition of script coverage: ttfautohint now properly scans composite glyphs to cover components also.
Improved glyph shape analysis: Non-flat local extrema are now recognized more reliably, and stem detection works better.
Much less memory consumption while handling fonts with complicated glyphs.
-s was partially broken.
GSUBtable. This allows the hinting of glyphs that don’t have an entry in a font’s
cmaptable, for example superscripts or small caps.
Related to this, the new option
--default-script controls the default (fallback) script used for OpenType features.
More than a single standard character is used. For example, the ‘latin’ script uses characters ‘o’, ‘O’, and digit ‘0’. This improves the hinting of fonts (and features) that have only a partial coverage of a script’s character repertoire.
Much better GDI ClearType hinting in the range 30-80ppem (approx.), avoiding overly flat tops and bottoms of round glyphs.
Better handling of non-square pixels (this is, horizontal and vertical resolutions differ) in the created TrueType bytecode.
Improved script support. Besides Cyrillic and Greek, which are now handled separately from Latin, ttfautohint can handle Hebrew.
-f now takes a parameter to specify the fallback script. The corresponding long option name has been renamed from
Work around a bug in display environments that use FreeType 2.5.0 and earlier for rendering: Sometimes, the ‘strong’ stem width routine was used for DW ClearType (this is, subpixel hinting in FreeType is enabled) even if ‘smooth’ was selected while generating the font with ttfautohint.
--componentshas been replaced with
--composites: By default, the components of a composite glyph are now hinted separately, since tests has shown that this gives good results in most cases. If this option is set, however, the composite glyph itself gets hinted (and the hints of the components are ignored).
An unfortunate side effect is that ttfautohint’s option
-c (which stays as a shorthand for
--composites) now does exactly the opposite as in previous releases.
Older versions of Monotype’s ‘iType’ bytecode interpreter have a serious bug: The DIV instruction rounds the result, while the correct operation is truncation. This caused ‘exploding characters’ with fonts hinted by ttfautohint. Since many printers contain this rasterizer without any possibility to update to a non-buggy version, ttfautohint now contains work-arounds to circumvent the problem.
Better support for glyphs where some points have almost the same position (for example glyph ‘Oslash’ in font ‘Roboto-Thin’).
Better support for glyphs that use explicit ‘on’ points around round extrema.
--dehint to strip off all hints without generating new hints. This option is intended for testing purposes.
Minor fixes to the created bytecode for compatibility.
Minor GUI improvements.
--windows-compatibility that adds two artificial blue zones at vertical positions given by ‘usWinAscent’ and ‘usWinDescent’. This helps ttfautohint’s hinting algorithm reduce the possibility of clipping if those two values are very tight.
--x-height-snapping-exceptions, making ttfautohint avoid x-height snapping for selected PPEM values. Useful in combination with
Minor fixes to the created bytecode for compatibility and robustness.
--componentsto treat components of composite glyphs separately. This greatly reduces the bytecode size.
I’m waiting for reports whether this option works for most fonts; in case this is true I’m inverting the option, making it the default (and the old behaviour optional).
Full support of TTCs, this is, all subfonts get auto-hinted now.
The upper limit of the
--increase-x-height option has been removed.
Drag-and-drop support in the GUI.
The command-line version of ttfautohint now acts like a (Unix) filter, this is, it accepts stdin and stdout as input and output, respectively.
Less memory consumption.
A new, ‘strong’ routine to handle stem widths and positions has been added, to be selected with the
--strong-stem-width command line option. If it is active, stem widths and positions are snapped to the grid as much as possible. This algorithm is useful for GDI ClearType support.
A new command line option
--debug (not available for ttfautohintGUI) to print very detailed debugging information.
The created bytecode has been reduced in size, making it approx. 20% smaller.
--symbol to use standard stem height and width values instead of using character ‘o’ (which may be missing). Use this option for symbol fonts or math glyphs.
More documentation (in text, HTML, and PDF format). It’s still incomplete, though.
--ignore-permissions has been renamed to
--ignore-restrictions. The short form is still
Defaults for various parameters have been set to more sensible values:
--increase-x-height now has a mandatory argument (in the range 6-20 or value 0 to disable it, default value is 14).
-x to increase the x height of the font for small PPEM values by rounding up far more often then rounding down.
Add option ‘
-G n’ to switch off hinting completely above value
ttfautohint now appends version information and the used parameters to the ‘Version’ field(s) in the ‘name’ table. This can be suppressed with option
The improved handling of composite glyphs in 0.6 was buggy under certain circumstances, making ttfautohint crash and FontValidator complain.
Dropout handling has been activated.
Improved handling of composite glyphs.
-p to pre-hint glyphs with original hints before conversion takes place.
Don’t add a
DSIG table if there is none in the input font.
Human-readable error messages instead of hexadecimal error codes.
Better tests (both at runtime and compile time) to reject too old FreeType versions.
Rendering on iOS is now expected to give good results.
No bad rendering at very large PPEM values.
glyftable was one byte too short, making the font invalid.
To be more precise, the sum of the height and length of a segment must be at least 20 font units, and the height multiplied by 14 must not exceed the length. Thus (19,1) is also a valid minimum (length,height) pair, while (18,2) isn’t. The value 20 is heuristic and hard-coded, as is the value 14 (corresponding to a slope of approx. 4.1°).↩
Unfortunately, there is a bug in FreeType prior to version 2.5.4 (released in December 2014) that completely disables vertical delta exceptions if subpixel hinting is activated. For this reason you should expect that the
touch parameter fails on older GNU/Linux distributions.↩
The number ‘6’ indicates the version of the shared library of FreeType, which is not directly related to the source code version of FreeType.↩