Add missing files.
[ttfautohint.git] / doc / ttfautohint-1.pandoc
blob3d8b9a64c5b2b4b6553b8e2342bb495501bdf0ac
1 % ttfautohint
2 % Werner Lemberg
5 <!--
6   Copyright (C) 2011-2015 by Werner Lemberg.
8   This file is part of the ttfautohint library, and may only be used,
9   modified, and distributed under the terms given in `COPYING'.  By
10   continuing to use, modify, or distribute this file you indicate that you
11   have read `COPYING' and understand and accept it fully.
13   The file `COPYING' mentioned in the previous paragraph is distributed
14   with the ttfautohint library.
15 -->
19 Introduction
20 ============
22 **ttfautohint** is a library written in\ C that takes a TrueType font as
23 the input, removes its bytecode instructions (if any), and returns a new
24 font where all glyphs are bytecode hinted using the information given by
25 FreeType's auto-hinting module.  The idea is to provide the excellent
26 quality of the auto-hinter on platforms that don't use FreeType.
28 The library has a single API function, `TTF_autohint`, which is described
29 [below](#the-ttfautohint-api).
31 Bundled with the library there are two front-end programs, [`ttfautohint`
32 and `ttfautohintGUI`](#ttfautohint-and-ttfautohintgui), being a command line
33 program and an application with a Graphics User Interface (GUI),
34 respectively.
37 What exactly are hints?
38 -----------------------
40 To cite [Wikipedia](http://en.wikipedia.org/wiki/Font_hinting):
42 > **Font hinting** (also known as **instructing**) is the use of
43 > mathematical instructions to adjust the display of an outline font so that
44 > it lines up with a rasterized grid.  At low screen resolutions, hinting is
45 > critical for producing a clear, legible text.  It can be accompanied by
46 > antialiasing and (on liquid crystal displays) subpixel rendering for
47 > further clarity.
49 and Apple's [TrueType Reference
50 Manual](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM03/Chap3.html#features):
52 > For optimal results, a font instructor should follow these guidelines:
54 >  - At small sizes, chance effects should not be allowed to magnify small
55 >    differences in the original outline design of a glyph.
57 >  - At large sizes, the subtlety of the original design should emerge.
59 In general, there are three possible ways to hint a glyph.
61  1. The font contains hints (in the original sense of this word) to guide
62     the rasterizer, telling it which shapes of the glyphs need special
63     consideration.  The hinting logic is partly in the font and partly in
64     the rasterizer.  More sophisticated rasterizers are able to produce
65     better rendering results.
67     This is how Type\ 1 and CFF hints work.
69  2. The font contains exact instructions (also called *bytecode*) on how to
70     move the points of its outlines, depending on the resolution of the
71     output device, and which intentionally distort the (outline) shape to
72     produce a well-rasterized result.  The hinting logic is in the font;
73     ideally, all rasterizers simply process these instructions to get the
74     same result on all platforms.
76     This is how TrueType hints work.
78  3. The font gets auto-hinted (at run-time).  The hinting logic is
79     completely in the rasterizer.  No hints in the font are used or needed;
80     instead, the rasterizer scans and analyzes the glyphs to apply
81     corrections by itself.
83     This is how FreeType's auto-hinter works; see
84     [below](#background-and-technical-details) for more.
87 What problems can arise with TrueType hinting?
88 ----------------------------------------------
90 While it is relatively easy to specify PostScript hints (either manually or
91 by an auto-hinter that works at font creation time), creating TrueType
92 hints is far more difficult.  There are at least two reasons:
94   - TrueType instructions form a programming language, operating at a very
95     low level.  They are comparable to assembler code, thus lacking all
96     high-level concepts to make programming more comfortable.
98     Here an example how such code looks like:
100     ```
101         SVTCA[0]
102         PUSHB[ ]  /* 3 values pushed */
103         18 1 0
104         CALL[ ]
105         PUSHB[ ]  /* 2 values pushed */
106         15 4
107         MIRP[01001]
108         PUSHB[ ]  /* 3 values pushed */
109         7 3 0
110         CALL[ ]
111     ```
113     Another major obstacle is the fact that font designers usually aren't
114     programmers.
116   - It is very time consuming to manually hint glyphs.  Given that the
117     number of specialists for TrueType hinting is very limited, hinting a
118     large set of glyphs for a font or font family can become very expensive.
121 Why ttfautohint?
122 ----------------
124 The ttfautohint library brings the excellent quality of FreeType rendering
125 to platforms that don't use FreeType, yet require hinting for text to look
126 good -- like Microsoft Windows.  Roughly speaking, it converts the glyph
127 analysis done by FreeType's auto-hinting module to TrueType bytecode.
128 Internally, the auto-hinter's algorithm resembles PostScript hinting
129 methods; it thus combines all three hinting methods discussed
130 [previously](#what-exactly-are-hints).
132 The simple interface of the front-ends (both on the command line and with
133 the GUI) allows quick hinting of a whole font with a few mouse clicks or a
134 single command on the prompt.  As a result, you get better rendering results
135 with web browsers, for example.
137 Across Windows rendering environments today, fonts processed with
138 ttfautohint look best with ClearType enabled.  This is the default for
139 Windows\ 7.  Good visual results are also seen in recent MacOS\ X versions
140 and GNU/Linux systems (including Android, ChromeOS, and other mobile
141 operating systems) that use FreeType for rendering glyphs.
143 The goal of the project is to generate a 'first pass' of hinting that font
144 developers can refine further for ultimate quality.
147 'Smooth' hinting
148 ----------------
150 Fundamentally, there are two approaches to hinting. The older approach,
151 let's call it 'sharp', popular when text was rendered in pure
152 black-and-white, was to make all stems round to full pixels so that in a
153 text line, all stems would be either one pixel or (at a larger point size)
154 two pixels.  When grayscale antialiasing came about, this approach actually
155 started harming the rendering rather than helping it, because the horizontal
156 and vertical stems would render very dark but round or diagonal stems would
157 render very light.
159 So a new approach was developed, let's call it 'fuzzy', where all stems and
160 other elements are equalized so that in grayscale (or ClearType) rendering,
161 they all are of roughly equal color.  This means that stems are not rounded
162 to full pixels but in fact to fractions of a pixel.  However, with
163 black-and-white renderers, this approach yields poor results because in
164 black-and-white you cannot render a fraction of a pixel, so some stems
165 become one pixel and some become two.
167 The TrueType autohinters in [FontForge] and [FontLab Studio], to name two
168 well-known font editors, take the 'sharp' approach, while the TrueType
169 autohinter in ttfautohint takes the 'fuzzy' approach.
171 In theory, a hybrid approach is possible, using TrueType conditional hints:
172 If the rasterizer is black-and-white, 'sharp' rendering could happen, while
173 if the rasterizer is ClearType, the 'fuzzy' rendering could be used.  It is
174 not intended to add black-and-white auto-hinting to ttfautohint.  However,
175 it is planned to develop an interface so that ttfautohint can cooperate with
176 font editors, providing this hybrid hinting.
180 `ttfautohint` and `ttfautohintGUI`
181 ==================================
183 On all supported platforms (GNU/Linux, Windows, and Mac OS\ X), the GUI
184 looks quite similar; the used toolkit is [Qt], which in turn uses the
185 platform's native widgets.
187 ![`ttfautohintGUI` on GNU/Linux running KDE](img/ttfautohintGUI.png)
189 Both the GUI and console version share the same features, to be discussed in
190 the next subsection.
192 **Warning: ttfautohint cannot always process a font a second time.**
193 If the font contains composite glyphs, and option [`-c`](#hint-composites)
194 is used, reprocessing with ttfautohint will fail.  For this reason it is
195 strongly recommended to *not* delete the original, unhinted font so that you
196 can always rerun ttfautohint.
199 Calling `ttfautohint`
200 ---------------------
203     ttfautohint [OPTION]... [IN-FILE [OUT-FILE]]
206 The command-line binary, `ttfautohint`, works like a Unix filter, this is,
207 it reads data from standard input if no input file name is given, and it
208 sends its output to standard output if no output file name is specified.
210 A typical call looks like the following.
213     ttfautohint -v -f latn foo.ttf foo-autohinted.ttf
216 For demonstration purposes, here the same using a pipe and redirection.
217 Note that Windows's default command line interpreter, `cmd.exe`, doesn't
218 support piping with binary files, unfortunately.
221     cat foo.ttf | ttfautohint -v -f latn > foo-autohinted.ttf
225 Calling `ttfautohintGUI`
226 ------------------------
229     ttfautohintGUI [OPTION]...
232 `ttfautohintGUI` doesn't send any output to a console; however, it accepts
233 the same command line options as `ttfautohint`, setting default values for
234 the GUI.
237 Options
238 -------
240 Long options can be given with one or two dashes, and with and without an
241 equal sign between option and argument.  This means that the following forms
242 are acceptable: `-foo=`*bar*, `--foo=`*bar*, `-foo`\ *bar*, and
243 `--foo`\ *bar*.
245 Below, the section title refers to the command's label in the GUI (if
246 applicable), then comes the name of the corresponding long command line
247 option and its short equivalent, followed by a description.
249 Background and technical details on the meaning of the various options are
250 given [afterwards](#background-and-technical-details).
252 ### Hint Set Range Minimum, Hint Set Range Maximum
254 See '[Hint Sets](#hint-sets)' for a definition and explanation.
256 `--hinting-range-min=`*n*, `-l`\ *n*
257 :   The minimum PPEM value (in pixels) at which hint sets are created.  The
258     default value for *n* is\ 8.
260 `--hinting-range-max=`*n*, `-r`\ *n*
261 :   The maximum PPEM value (in pixels) at which hint sets are created.  The
262     default value for *n* is 50.
264 Increasing the range given by `-l` and `-r` normally makes the font's
265 bytecode larger.
267 ### Default Script
269 `--default-script=`*s*, `-D`\ *s*
270 :   Set default script to tag *s*, which is a string consisting of four
271     lowercase characters like `latn` or `dflt`.  It is needed to specify the
272     OpenType default script: After applying all features that are handled
273     specially (like small caps or superscript), ttfautohint uses this value
274     for the remaining features.  The default value is `latn`.  See
275     [below](#opentype-features) for more details.
277 ### Fallback Script
279 `--fallback-script=`*s*, `-f`\ *s*
280 :   Set fallback script to tag *s*, which is a string consisting of four
281     characters like `latn` or `dflt`.  It gets used for for all glyphs that
282     can't be assigned to a script automatically.  The default value is
283     `none`.  See [below](#scripts) for more details.
285 ### Hinting Limit
287 `--hinting-limit=`*n*, `-G`\ *n*
288 :   The *hinting limit* is the PPEM value (in pixels) where hinting gets
289     switched off (using the `INSTCTRL` bytecode instruction, not the `gasp`
290     table data); it does not influence the file size.  The default value for
291     *n* is 200, which means that the font is not hinted for PPEM values
292     larger than 200.
294     Note that hinting in the range 'hinting-range-max' up to 'hinting-limit'
295     uses the hinting configuration for 'hinting-range-max'.
297     To omit a hinting limit, use `--hinting-limit=0` (or check the 'No
298     Hinting Limit' box in the GUI).  Since this causes internal math
299     overflow in the rasterizer for large pixel values (>\ 1500px approx.) it
300     is strongly recommended to not use this except for testing purposes.
302 ### x Height Increase Limit
304 `--increase-x-height=`*n*, `-x`\ *n*
305 :   Normally, ttfautohint rounds the x\ height to the pixel grid, with a
306     slight preference for rounding up (to use the terminology of TrueType's
307     'Super Round' bytecode instruction, the threshold is 5/8px).  If this
308     flag is set, values in the range 6\ PPEM to *n*\ PPEM are much more
309     often rounded up (setting the threshold to 13/16px).  The default value
310     for *n* is 14.  Use this flag to increase the legibility of small sizes
311     if necessary; you might get weird rendering results otherwise for glyphs
312     like 'a' or 'e', depending on the font design.
314     To switch off this feature, use `--increase-x-height=0` (or check the
315     'No x\ Height Increase' box in the GUI).  To switch off rounding the
316     x\ height to the pixel grid in general, either partially or completely,
317     see '[x Height Snapping Exceptions](#x-height-snapping-exceptions)'.
319     The following FontForge snapshot images use the font '[Mertz
320     Bold](http://code.newtypography.co.uk/mertz-sans/)' (still under
321     development) from [Vernon Adams].
323     ![At 17px, without option `-x` and '`-w ""`', the hole in glyph 'e'
324       looks very grey in the FontForge snapshot, and the GDI ClearType
325       rendering (which is the default on older Windows versions) fills it
326       completely with black because it uses B/W rendering along the y\ axis.
327       FreeType's 'light' autohint mode (which corresponds to ttfautohint's
328       'smooth' stem width algorithm) intentionally aligns horizontal lines
329       to non-integer (but still discrete) values to avoid large glyph shape
330       distortions.](img/e-17px-x14.png)
332     ![The same, this time with option `-x 17` (and
333       '`-w ""`').](img/e-17px-x17.png)
335 ### x Height Snapping Exceptions
337 `--x-height-snapping-exceptions=`*string*, `-X`\ *string*
338 :   A list of comma separated PPEM values or value ranges at which no
339     x\ height snapping shall be applied.  A value range has the form
340     *value*~1~`-`*value*~2~, meaning *value*~1~\ <= PPEM <=\ *value*~2~.
341     *value*~1~ or *value*~2~ (or both) can be missing; a missing value is
342     replaced by the beginning or end of the whole interval of valid PPEM
343     values, respectively (6\ to 32767).  Whitespace is not significant;
344     superfluous commas are ignored, and ranges must be specified in
345     increasing order.  For example, the string `"7-9, 11, 13-"` means the
346     values 7, 8, 9, 11, 13, 14, 15, etc.  Consequently, if the supplied
347     argument is `"-"`, no x\ height snapping takes place at all.  The
348     default is the empty string (`""`), meaning no snapping exceptions.
350     Normally, x\ height snapping means a slight increase in the overall
351     vertical glyph size so that the height of lowercase glyphs gets aligned
352     to the pixel grid (this is a global feature, affecting *all* glyphs of a
353     font).  However, having larger vertical glyph sizes is not always
354     desired, especially if it is not possible to adjust the `usWinAscent`
355     and `usWinDescent` values from the font's `OS/2` table so that they are
356     not too tight.  See '[Windows Compatibility](#windows-compatibility)'
357     for more details.
359 ### Fallback Stem Width
361 `--fallback-stem-width=`*n*, `-H`\ *n*
362 :   Set the horizontal stem width (hinting) value for all scripts that lack
363     proper standard characters in the font.  The value is given in font
364     units and must be a positive integer.  If not set, ttfautohint uses a
365     hard-coded default (50\ units at 2048 units per EM, and linearly scaled
366     for other UPEM values, for example 24\ units at 1000 UPEM).
368     For symbol fonts, you need option `--fallback-script` too (to set up a
369     script at all).
371     In the GUI, uncheck the 'Default Fallback Stem Width' box to activate
372     this feature.
374 ### Windows Compatibility
376 `--windows-compatibility`, `-W`
377 :   This option makes ttfautohint add two artificial blue zones, positioned
378     at the `usWinAscent` and `usWinDescent` values (from the font's `OS/2`
379     table).  The idea is to help ttfautohint so that the hinted glyphs stay
380     within this horizontal stripe since Windows clips everything falling
381     outside.
383     There is a general problem with tight values for `usWinAscent` and
384     `usWinDescent`; a good description is given in the [Vertical Metrics
385     How-To](http://typophile.com/node/13081).  Additionally, there is a
386     special problem with tight values if used in combination with
387     ttfautohint because the auto-hinter tends to slightly increase the
388     vertical glyph dimensions at smaller sizes to improve legibility.  This
389     enlargement can make the heights and depths of glyphs exceed the range
390     given by `usWinAscent` and `usWinDescent`.
392     If ttfautohint is part of the font creation tool chain, and the font
393     designer can adjust those two values, a better solution instead of using
394     option `-W` is to reserve some vertical space for 'padding': For the
395     auto-hinter, the difference between a top or bottom outline point before
396     and after hinting is less than 1px, thus a vertical padding of 2px is
397     sufficient.  Assuming a minimum hinting size of 6ppem, adding two pixels
398     gives an increase factor of 8÷6 = 1.33.  This is near to the default
399     baseline-to-baseline distance used by TeX and other sophisticated text
400     processing applications, namely 1.2×designsize, which gives satisfying
401     results in most cases.  It is also near to the factor 1.25 recommended
402     in the abovementioned how-to.  For example, if the vertical extension of
403     the largest glyph is 2000 units (assuming that it approximately
404     represents the designsize), the sum of `usWinAscent` and `usWinDescent`
405     could be 1.25×2000 = 2500.
407     In case ttfautohint is used as an auto-hinting tool for fonts that can
408     be no longer modified to change the metrics, option `-W` in combination
409     with '`-X "-"`' to suppress any vertical enlargement should prevent
410     almost all clipping.
412 ### Adjust Subglyphs
414 `--adjust-subglyphs`, `-p`
415 :   *Adjusting subglyphs* makes a font's original bytecode be applied to all
416     glyphs before it is replaced with bytecode created by ttfautohint.  This
417     makes only sense if your font already has some hints in it that modify
418     the shape even at EM size (normally 2048px); in particular, some CJK
419     fonts need this because the bytecode is used to scale and shift
420     subglyphs (hence the option's long name).  For most fonts, however, this
421     is not the case.
423 ### Hint Composites
425 `--composites`, `-c`
426 :   By default, the components of a composite glyph get hinted separately.
427     If this flag is set, the composite glyph itself gets hinted (and the
428     hints of the components are ignored).  Using this flag increases the
429     bytecode size a lot, however, it might yield better hinting results.
431     If this option is used (and a font actually contains composite glyphs),
432     ttfautohint currently cannot reprocess its own output for technical
433     reasons, see [below](#the-.ttfautohint-glyph).
435 ### Symbol Font
437 `--symbol`, `-s`
438 :   Process a font that ttfautohint would refuse otherwise because it can't
439     find a single standard character for any of the supported scripts.
441     For all scripts that lack proper standard characters, ttfautohint uses a
442     default (hinting) value for the standard stem width instead of deriving
443     it from a script's set of standard characters (for the latin script, one
444     of them is character 'o').
446     Use this option (usually in combination with the
447     [`--fallback-script`](#fallback-script) and/or
448     [`--fallback-stem-width`](#fallback-stem-width) option) to hint symbol
449     or dingbat fonts or math glyphs, for example, at the expense of possibly
450     poor hinting results at small sizes.
452 ### Dehint
454 `--dehint`, `-d`
455 :   Strip off all hints without generating new hints.  Consequently, all
456     other hinting options are ignored.  This option is intended for testing
457     purposes.
459 ### ttfautohint Info
461 `--no-info`, `-n`
462 :   Don't add ttfautohint version and command line information to the
463     version string or strings (with name ID\ 5) in the font's `name` table.
464     In the GUI, it corresponds to value 'None' in the 'ttfautohint
465     info' combo box.
467     This option is mutually exclusive with option `-I`.
469 `--detailed-info`, `-I`
470 :   Add ttfautohint version and command line information to the version
471     string or strings (with name ID\ 5) in the font's `name` table.  In the
472     GUI, it corresponds to value 'Version and Parameters' in the
473     'ttfautohint info' combo box.
475     This option is mutually exclusive with option `-n`.
477 If neither `-n` nor `-I` is set, the string '`ttfautohint (vNNN)`' gets
478 added to the `name` table (with *NNN* the current version); this correponds
479 to value 'Version' in the 'ttfautohint info' combo box.
481 ### Add TTFA Info Table
483 `--ttfa-info`, `-t`
484 :   Add an SFNT table called `TTFA` to the output font that holds a dump of
485     all parameters; the data resembles the format of the `--debug` option's
486     parameter listing.  In particular, it lists all ttfautohint control
487     instructions (which are *not* shown in the `name` table info).  This
488     option is mainly for archival purposes so that all information used to
489     create a font is stored in the font itself.  Note that such a `TTFA`
490     table gets ignored by all TrueType rendering engines.
492     Forthcoming versions of the ttfautohint front-ends will be able to use
493     this data so that a font can be processed another time with exactly the
494     same parameters, thus providing a means for round-tripping fonts.
496 ### Family Suffix
498 `--family-suffix=`*string*, `-F`\ *string*
499 :   A string that gets appended to the family name in entries with IDs 1, 4,
500     6, 16, and\ 21 in the font's `name` table.  Allowed input is ASCII in
501     the range 0x20-0x7E except characters `%()/<>[]{}`.
503     Assuming an input family name 'Foo', a full name 'Foo Bold', and a
504     family suffix '\ 1', the output family name will be 'Foo 1' and the
505     full name 'Foo 1 Bold'.  For the PostScript name in ID\ 6, ttfautohint
506     uses the suffix with space characters removed (for example 'Foo1Bold').
508     This option is mainly for testing purposes, enabling the operating
509     system to simultaneously display several instances of a font that are
510     processed with different ttfautohint parameters.
512 ### Strong Stem Width and Positioning
514 `--strong-stem-width=`*string*, `-w`\ *string*
515 :   ttfautohint offers two different routines to handle (horizontal) stem
516     widths and stem positions: 'smooth' and 'strong'.  The former uses
517     discrete values that slightly increase the stem contrast with almost no
518     distortion of the outlines, while the latter snaps both stem widths and
519     stem positions to integer pixel values as much as possible, yielding a
520     crisper appearance at the cost of much more distortion.
522     These two routines are mapped onto three possible rendering targets:
524     - grayscale rendering, with or without optimization for subpixel
525       positioning (e.g. Android)
527     - 'GDI ClearType' rendering: the rasterizer version, as returned by the
528       GETINFO bytecode instruction, is in the range 36\ <= version <\ 38 and
529       ClearType is enabled (e.g. Windows XP)
531     - 'DirectWrite ClearType' rendering: the rasterizer version, as returned
532       by the GETINFO bytecode instruction, is >=\ 38, ClearType is enabled,
533       and subpixel positioning is enabled also (e.g. Internet Explorer\ 9
534       running on Windows\ 7)
536     GDI ClearType uses a mode similar to B/W rendering along the vertical
537     axis, while DW ClearType applies grayscale rendering.  Additionally,
538     only DW ClearType provides subpixel positioning along the x\ axis.  For
539     what it's worth, the rasterizers version\ 36 and version\ 38 in
540     Microsoft Windows are two completely different rendering engines.
542     The command line option expects *string* to contain up to three letters
543     with possible values '`g`' for grayscale, '`G`' for GDI ClearType, and
544     '`D`' for DW ClearType.  If a letter is found in *string*, the strong
545     stem width routine is used for the corresponding rendering target (and
546     smooth stem width handling otherwise).  The default value is '`G`', which
547     means that strong stem width handling is activated for GDI ClearType
548     only.  To use smooth stem width handling for all three rendering
549     targets, use the empty string as an argument, usually connoted with
550     '`""`'.
552     In the GUI, simply set the corresponding check box to select the strong
553     width routine for a given rendering target.  If you unset the check box,
554     the smooth width routine gets used.
556     The following images again use the font 'Mertz Bold'.
558     ![The left part shows the glyph 'g' unhinted at 26px, the right part
559      with hints, using the 'smooth' stem algorithm.](img/ff-g-26px.png)
561     ![The same, but this time using the 'strong'
562      algorithm.  Note how the stems are aligned to the pixel
563      grid.](img/ff-g-26px-wD.png)
565 ### Control Instructions File
566 `--control-file=`*file*, `-m`\ *file* (not in `ttfautohintGUI`)
567 :   Specify the name of a control instructions file to manually tweak the
568     hinting process.  This feature can be used to correct glitches in
569     ttfautohint's hinting algorithm.  The syntax used in a control
570     instructions file is given [below](#control-instructions).
572 ### Miscellaneous
574 Watch input files (`ttfautohintGUI` only)
575 :   If this checkbox is set, automatically regenerate the output file as
576     soon as an input file (either the font or the control instructions file)
577     gets modified.
579     Pressing the 'Run' button starts watching.  If an error occurs, watching
580     stops and must be restarted with the 'Run' button.
582 `--ignore-restrictions`, `-i`
583 :   By default, fonts that have bit\ 1 set in the 'fsType' field of the
584     `OS/2` table are rejected.  If you have a permission of the font's legal
585     owner to modify the font, specify this command line option.
587     If this option is not set, `ttfautohintGUI` shows a dialogue to handle
588     such fonts if necessary.
590 `--help`, `-h`
591 :   On the console, print a brief documentation on standard output and exit.
592     This doesn't work with `ttfautohintGUI` on MS Windows.
594 `--version`, `-v`
595 :   On the console, print version information on standard output and exit.
596     This doesn't work with `ttfautohintGUI` on MS Windows.
598 `--debug`
599 :   Print *a lot* of debugging information on standard error while
600     processing a font (you should redirect stderr to a file).  This
601     doesn't work with `ttfautohintGUI` on MS Windows.
603     To reduce the amount of debug data it is recommended to restrict the
604     hinting process to a single PPEM value, e.g.,
606     ```
607        ttfautohint --debug -l 15 -r 15 ... > debug.txt 2>&1
608     ```
612 Background and Technical Details
613 ================================
615 [Real-Time Grid Fitting of Typographic
616 Outlines](http://www.tug.org/TUGboat/tb24-3/lemberg.pdf) is a scholarly
617 paper that describes FreeType's auto-hinter in some detail.  Regarding the
618 described data structures it is slightly out of date, but the algorithm
619 itself hasn't changed in general.
621 The next few subsections are mainly based on this article, introducing some
622 important concepts.  Note that ttfautohint only does hinting along the
623 vertical direction (modifying y\ coordinates only).
626 Segments and Edges
627 ------------------
629 A glyph consists of one or more *contours* (this is, closed curves).  For
630 example, glyph 'O' consists of two contours, while glyph 'I' has only one.
632 ![The letter 'O' has two contours, an inner and an outer one, while letter
633   'I' has only an outer contour.](img/o-and-i)
635 A *segment* is a series of consecutive points of a contour (including its
636 Bézier control points) that are approximately aligned along a coordinate
637 axis.  A segment has one of three possible directions: left, right, or none
638 (which means neither left nor right), derived from the TrueType outline
639 directions.  ttfautohint itself creates segments that contain at least two
640 points.  Using control instructions, however, it is possible to create
641 one-point segments, which are useful for fine-tuning the hinting process.
643 ![A serif.  Contour and control points are represented by squares and
644   circles, respectively.  The bottom 'line' DE is approximately aligned
645   along the horizontal axis, thus it forms a segment of 7\ points.  Together
646   with the two other horizontal segments, BC and FG, they form two edges
647   (BC+FG, DE).](img/segment-edge)
649 An *edge* corresponds to a single coordinate value (allowing for a small
650 threshold) on the main dimension that collects one or more segments, all
651 pointing into the same direction (either left or right, all others are
652 ignored).  While finding segments is done on the unscaled outline, finding
653 edges is bound to the device resolution.  See [below](#hint-sets) for an
654 example.
656 In general, segments and edges pointing into different directions 'repel'
657 each other, thus preventing alignment on the same vertical coordinate if
658 they are near.  Note that this is a simplification, but it should help
659 understand how to manipulate and/or create segments in control instructions
660 files.
662 The analysis to find segments and edges is specific to a writing
663 system, see [below](#writing-systems).
666 Feature Analysis
667 ----------------
669 The auto-hinter analyzes a font in two steps.  Right now, everything
670 described here happens for the horizontal axis only, providing vertical
671 hinting.
673   * Global Analysis
675     This affects the hinting of all glyphs, trying to give them a uniform
676     appearance.
678       + Compute standard horizontal stem width of the font.  The value
679         is normally taken from glyphs that resemble letter 'o'.
681       + Compute blue zones, see [below](#blue-zones).
683     If the stem widths of single glyphs differ by a large value, or if
684     ttfautohint fails to find proper blue zones, hinting becomes quite poor,
685     possibly leading even to severe shape distortions.
688 Table: script-specific standard characters of the 'latin' writing system
690     Script    Standard characters
691   ----------  ---------------------
692   `arab`      'ـ', U+0640, ARABIC TATWEEL
693               'ل', U+0644, ARABIC LETTER LAM
694               'ح', U+062D, ARABIC LETTER HAH
695   `cyrl`      'о', U+043E, CYRILLIC SMALL LETTER O
696               'О', U+041E, CYRILLIC CAPITAL LETTER O
697   `deva`      'ठ', U+0920, DEVANAGARI LETTER TTHA
698               'व', U+0935, DEVANAGARI LETTER VA
699               'ट', U+091F, DEVANAGARI LETTER TTA
700   `grek`      'ο', U+03BF, GREEK SMALL LETTER OMICRON
701               'Ο', U+039F, GREEK CAPITAL LETTER OMICRON
702   `hebr`      'ם', U+05DD, HEBREW LETTER FINAL MEM
703   `lao`       '໐', U+0ED0, LAO DIGIT ZERO
704   `latn`      'o', U+006F, LATIN SMALL LETTER O
705               'O', U+004F, LATIN CAPITAL LETTER O
706               '0', U+0030, DIGIT ZERO
707   `telu`      '౦', U+0C66, TELUGU DIGIT ZERO
708               '౧', U+0C67, TELUGU DIGIT ONE
709   `thai`      'า', U+0E32, THAI CHARACTER SARA AA
710               'ๅ', U+0E45, THAI CHARACTER LAKKHANGYAO
711               '๐', U+0E50, THAI DIGIT ZERO
714 Table: standard characters of the 'latin' writing system, special scripts
716     Script    Standard characters
717   ----------  ---------------------
718   `latb`      'ₒ', U+2092, LATIN SUBSCRIPT SMALL LETTER O
719               '₀', U+2080, SUBSCRIPT ZERO
720   `latp`      'ᵒ', U+1D52, MODIFIER LETTER SMALL O
721               'ᴼ', U+1D3C, MODIFIER LETTER CAPITAL O
722               '⁰', U+2070, SUPERSCRIPT ZERO
725   * Glyph Analysis
727     This is a per-glyph operation.
729       + Find segments and edges.
731       + Link edges together to find stems and serifs.  The abovementioned
732         paper gives more details on what exactly constitutes a stem or a
733         serif and how the algorithm works.
736 Blue Zones
737 ----------
739 ![Two blue zones relevant to the glyph 'a'.  Vertical point coordinates of
740   *all* glyphs within these zones are aligned, provided the blue zone is
741   active (this is, its vertical size is smaller than
742   3/4\ pixels).](img/blue-zones)
744 Outlines of certain characters are used to determine *blue zones*.  This
745 concept is the same as with Type\ 1 fonts: All glyph points that lie in
746 certain small horizontal zones get aligned vertically.
748 Here a series of tables that show the blue zone characters of the latin
749 writing system's available scripts; the values are hard-coded in the source
750 code.  Since the auto-hinter takes mean values it is not necessary that all
751 characters of a zone are present.
754 Table: `arab` blue zones
756   ID    Blue zone                              Characters
757   ----  -----------                            ------------
758   1     top of letters with vertical stroke    ا إ ل ك ط ظ
759   2     bottom of letters                      ت ث ط ظ ك
760   3     glyph joining                          ـ
763 Table: `cyrl` blue zones
765   ID    Blue zone                              Characters
766   ----  -----------                            ------------
767   1     top of capital letters                 Б В Е П З О С Э
768   2     bottom of capital letters              Б В Е Ш З О С Э
769   3     top of small letters                   х п н ш е з о с
770   4     bottom of small letters                х п н ш е з о с
771   5     bottom of descenders of small letters  р у ф
774 Table: `deva` blue zones
776   ID    Blue zone                              Characters
777   ----  -----------                            ------------
778   1     baseline (flat glyphs only)            क न म उ छ ट ठ ड
779   2     top of ascenders                       ई ऐ ओ औ ि ी ो ौ
780   3     top of baseline                        क म अ आ थ ध भ श
781   4     bottom of base characters              क म अ आ थ ध भ श
782   5     bottom of descenders                   ु ृ
784 Contrary to scripts like latin, the baseline in Devanagari is on the top.
785 Note that some fonts have extreme variation in the height of the round
786 elements in Zone\ 3; for this reason we also define Zone\ 1, which must be
787 always present.
790 Table: `grek` blue zones
792   ID    Blue zone                              Characters
793   ----  -----------                            ------------
794   1     top of capital letters                 Γ Β Ε Ζ Θ Ο Ω
795   2     bottom of capital letters              Β Δ Ζ Ξ Θ Ο
796   3     top of 'small beta' like letters       β θ δ ζ λ ξ
797   4     top of small letters                   α ε ι ο π σ τ ω
798   5     bottom of small letters                α ε ι ο π σ τ ω
799   6     bottom of descenders of small letters  β γ η μ ρ φ χ ψ
802 Table: `hebr` blue zones
804   ID    Blue zone                              Characters
805   ----  -----------                            ------------
806   1     top of letters                         ב ד ה ח ך כ ם ס
807   2     bottom of letters                      ב ט כ ם ס צ
808   3     bottom of descenders of letters        ק ך ן ף ץ
811 Table: `lao` blue zones
813   ID    Blue zone                              Characters
814   ----  -----------                            ------------
815   1     top of letters                         າ ດ ອ ມ ລ ວ ຣ ງ
816   2     bottom of letters                      າ ອ ບ ຍ ຣ ຮ ວ ຢ
817   3     top of ascenders                       ປ ຢ ຟ ຝ
818   4     top of large ascenders                 ໂ ໄ ໃ
819   5     bottom of descenders                   ງ ຊ ຖ ຽ ໆ ຯ
822 Table: `latb` blue zones
824   ID    Blue zone                                 Characters
825   ----  -----------                               ------------
826    1    top of capital characters                 ₀ ₃ ₅ ₇ ₈
827    2    bottom of capital characters              ₀ ₁ ₂ ₃ ₈
828    3    top of 'small f' like characters          ᵢ ⱼ ₕ ₖ ₗ
829    4    top of small characters                   ₐ ₑ ₒ ₓ ₙ ₛ ᵥ ᵤ ᵣ
830    5    bottom of small characters                ₐ ₑ ₒ ₓ ₙ ₛ ᵥ ᵤ ᵣ
831    6    bottom of descenders of small characters  ᵦ ᵧ ᵨ ᵩ ₚ
833 Subscript latin characters are similar to normal latin characters.
836 Table: `latn` blue zones
838   ID    Blue zone                              Characters
839   ----  -----------                            ------------
840   1     top of capital letters                 T H E Z O C Q S
841   2     bottom of capital letters              H E Z L O C U S
842   3     top of 'small f' like letters          f i j k d b h
843   4     top of small letters                   x z r o e s c
844   5     bottom of small letters                x z r o e s c
845   6     bottom of descenders of small letters  p q g j y
847 The 'round' characters (e.g. 'OCQS') from Zones 1, 2, and\ 5 are also used
848 to control the overshoot handling; to improve rendering at small sizes,
849 zone\ 4 gets adjusted to be on the pixel grid; cf. the
850 [`--increase-x-height`](#x-height-increase-limit) option.
853 Table: `latp` blue zones
855   ID    Blue zone                                 Characters
856   ----  -----------                               ------------
857   1     top of capital characters                 ⁰ ³ ⁵ ⁷ ᵀ ᴴ ᴱ ᴼ
858   2     bottom of capital characters              ⁰ ¹ ² ³ ᴱ ᴸ ᴼ ᵁ
859   3     top of 'small f' like characters          ᵇ ᵈ ᵏ ʰ ʲ ᶠ ⁱ
860   4     top of small characters                   ᵉ ᵒ ʳ ˢ ˣ ᶜ ᶻ
861   5     bottom of small characters                ᵉ ᵒ ʳ ˢ ˣ ᶜ ᶻ
862   6     bottom of descenders of small characters  ᵖ ʸ ᵍ
864 Superscript latin characters are similar to normal latin characters.
867 Table: `telu` blue zones
869   ID    Blue zone                              Characters
870   ----  -----------                            ------------
871   1     top                                    ఇ ఌ ఙ ఞ ణ ఱ ౯
872   2     bottom                                 అ క చ ర ఽ ౨ ౬
875 Table: `thai` blue zones
877   ID    Blue zone                              Characters
878   ----  -----------                            ------------
879   1     top                                    บ เ แ อ ก า
880   2     bottom                                 บ ป ษ ฯ อ ย ฮ
881   3     ascender                               ป ฝ ฟ
882   4     large ascender                         โ ใ ไ
883   5     descender                              ฎ ฏ ฤ ฦ
884   6     large descender                        ญ ฐ
885   7     top of Thai digits                     ๐ ๑ ๓
888 ![This image shows the relevant glyph terms for vertical blue zone
889   positions.](img/glyph-terms)
892 Grid Fitting
893 ------------
895 Aligning outlines along the grid lines is called *grid fitting*.  It doesn't
896 necessarily mean that the outlines are positioned *exactly* on the grid,
897 however, especially if you want a smooth appearance at different sizes.
898 This is the central routine of the auto-hinter; its actions are highly
899 dependent on the used writing system.  Currently, only one writing system is
900 available (latin), providing support for scripts like Latin or Greek.
902   * Align edges linked to blue zones.
904   * Fit edges to the pixel grid.
906   * Align serif edges.
908   * Handle remaining 'strong' points.  Such points are not part of an edge
909     but are still important for defining the shape.  This roughly
910     corresponds to the `IP` TrueType instruction.
912   * Everything else (the 'weak' points) is handled with an 'IUP'
913     instruction.
915 The following images illustrate the hinting process, using glyph 'a' from
916 the freely available font '[Ubuntu Book](http://font.ubuntu.com)'.  The
917 manual hints were added by [Dalton Maag Ltd], the used application to create
918 the hinting debug snapshots was [FontForge].
920 ![Before hinting.](img/a-before-hinting.png)
922 ![After hinting, using manual hints.](img/a-after-hinting.png)
924 ![After hinting, using ttfautohint.  Note that the hinting process
925   doesn't change horizontal positions.](img/a-after-autohinting.png)
928 Hint Sets
929 ---------
931 In ttfautohint terminology, a *hint set* is the *optimal* configuration for
932 a given PPEM (pixel per EM) value.
934 In the range given by the `--hinting-range-min` and `--hinting-range-max`
935 options, ttfautohint creates hint sets for every PPEM value.  For each
936 glyph, ttfautohint automatically determines whether a new set should be
937 emitted for a PPEM value if it finds that it differs from a previous one.
938 For some glyphs it is possible that one set covers, say, the range
939 8px-1000px, while other glyphs need 10 or more such sets.
941 In the PPEM range below `--hinting-range-min`, ttfautohint always uses just
942 one set, in the PPEM range between `--hinting-range-max` and
943 `--hinting-limit`, it also uses just one set.
945 One of the hinting configuration parameters is the decision which segments
946 form an edge.  For example, let us assume that two segments get aligned on a
947 single horizontal edge at 11px, while two edges are used at 12px.  This
948 change makes ttfautohint emit a new hint set to accomodate this situation.
949 The next images illustrate this, using a Cyrillic letter (glyph 'afii10108')
950 from the 'Ubuntu book' font, processed with ttfautohint.
952 ![Before hinting, size 11px.](img/afii10108-11px-before-hinting.png)
954 ![After hinting, size 11px.  Segments 43-27-28 and 14-15 are aligned on a
955   single edge, as are segments 26-0-1 and
956   20-21.](img/afii10108-11px-after-hinting.png)
958 ![Before hinting, size 12px.](img/afii10108-12px-before-hinting.png)
960 ![After hinting, size 12px.  The segments are not aligned.  While
961   segments 43-27-28 and 20-21 now have almost the same horizontal position,
962   they don't form an edge because the outlines passing through the segments
963   point into different directions.](img/afii10108-12px-after-hinting.png)
965 Obviously, the more hint sets get emitted, the larger the bytecode
966 ttfautohint adds to the output font.  To find a good value\ *n* for
967 `--hinting-range-max`, some experimentation is necessary since *n* depends
968 on the glyph shapes in the input font.  If the value is too low, the hint
969 set created for the PPEM value\ *n* (this hint set gets used for all larger
970 PPEM values) might distort the outlines too much in the PPEM range given
971 by\ *n* and the value set by `--hinting-limit` (at which hinting gets
972 switched off).  If the value is too high, the font size increases due to
973 more hint sets without any noticeable hinting effects.
975 Similar arguments hold for `--hinting-range-min` except that there is no
976 lower limit at which hinting is switched off.
978 An example.  Let's assume that we have a hinting range 10\ <= ppem <=\ 100,
979 and the hinting limit is set to 250.  For a given glyph, ttfautohint finds
980 out that four hint sets must be computed to exactly cover this hinting
981 range: 10-15, 16-40, 41-80, and 81-100.  For ppem values below 10ppem, the
982 hint set covering 10-15ppem is used, for ppem values larger than 100 the
983 hint set covering 81-100ppem is used.  For ppem values larger than 250, no
984 hinting gets applied.
987 Composite Glyphs
988 ----------------
990 The ttfautohint library (and programs) supports two solutions for handling
991 composite glyphs, to be controlled with option
992 [`--composites`](#hint-composites).  This section contains some general
993 information, then covers the case where the option is off, while the next
994 section describes how ttfautohint behaves if this option is activated.
996 Regardless of the `--composites` option, ttfautohint performs a scan over
997 all composite glyphs to assure that components of a composite glyph inherit
998 its style, as described [later](#opentype-features).  However, components
999 that are shifted vertically will be skipped.  For example, if the glyph
1000 'Agrave' uses a shifted 'grave' accent glyph, the accent is ignored.  On the
1001 other hand, if there is a glyph 'agrave' that uses the same 'grave' glyph
1002 vertically unshifted, 'grave' does inherit the style.
1004 If `--composites` is off, components are hinted separately, then put
1005 together.  Separate hinting implies that the current style's blue zones are
1006 applied to all subglyphs in its original, unshifted positions.  In case you
1007 want to shift components vertically, it is *mandatory* to set bit\ 2
1008 (value\ 4), `ROUND_XY_TO_GRID`, in the flag variable of the composite glyph
1009 description to get visually pleasing results, as the images below
1010 demonstrate.
1012 ![Here, the subscript glyphs are composites each having a single element
1013   that is shifted down.  If option `--composites` is not used, subglyphs are
1014   hinted before they are glued together (possibly applying scaling and
1015   shifting).  Because the `ROUND_XY_TO_GRID` flag isn't set, the vertical
1016   translation doesn't align the subglyph to the pixel grid, causing severe
1017   distortions.](img/composite-no-round-xy-to-grid.png)
1019 ![The same as before, but with `ROUND_XY_TO_GRID` set.  Now the subscript
1020   glyphs look identical to the
1021   superscripts.](img/composite-round-xy-to-grid.png)
1023 ![For comparison purposes, here the result *with* option `--composites` (and
1024   no `ROUND_XY_TO_GRID`).  The composite glyphs as a whole get hinted;
1025   consequently, the subscript glyphs get separate blue zones.  At the
1026   displayed size of 16ppem the vertical positions of the subscript blue
1027   zones are rounded differently if compared to the superscript zones, thus
1028   the smaller glyph height.](img/composite-no-round-xy-to-grid-option-c.png)
1031 The '\.ttfautohint' Glyph
1032 -------------------------
1034 If option [`--composites`](#hint-composites) is used, ttfautohint doesn't
1035 hint subglyphs of composite glyphs separately.  Instead, it hints the whole
1036 glyph, this is, composites get recursively expanded internally so that they
1037 form simple glyphs, then hints are applied -- this is the normal working
1038 mode of FreeType's auto-hinter.
1040 One problem, however, must be solved: Hinting for subglyphs (which usually
1041 are used as normal glyphs also) must be deactivated so that nothing but the
1042 final bytecode of the composite gets executed.
1044 The trick used by ttfautohint is to prepend a composite element called
1045 '\.ttfautohint', a dummy glyph with a single point, and which has a single
1046 job: Its bytecode increases a variable (to be more precise, it is a CVT
1047 register called `cvtl_is_subglyph` in the source code), indicating that we
1048 are within a composite glyph.  The final bytecode of the composite glyph
1049 eventually decrements this variable again.
1051 As an example, let's consider composite glyph 'Agrave' ('À'), which has the
1052 subglyph 'A' as the base and 'grave' as its accent.  After processing with
1053 ttfautohint it consists of three components: '\.ttfautohint', 'A', and
1054 'grave' (in this order).
1056   Bytecode of    Action
1057   -------------  --------
1058   .ttfautohint   increase `cvtl_is_subglyph` (now: 1)
1059   A              do nothing because `cvtl_is_subglyph` > 0
1060   grave          do nothing because `cvtl_is_subglyph` > 0
1061   Agrave         decrease `cvtl_is_subglyph` (now: 0)\
1062                  apply hints because `cvtl_is_subglyph` == 0
1064 Some technical details (which you might skip): All glyph point indices get
1065 adjusted since each '\.ttfautohint' subglyph shifts all following indices by
1066 one.  This must be done for both the bytecode and one subformat of
1067 OpenType's `GPOS` anchor tables.
1069 While this approach works fine on all tested platforms, there is one single
1070 drawback: Direct rendering of the '\.ttfautohint' subglyph (this is,
1071 rendering as a stand-alone glyph) disables proper hinting of all glyphs in
1072 the font!  Under normal circumstances this never happens because
1073 '\.ttfautohint' doesn't have an entry in the font's `cmap` table.  (However,
1074 some test and demo programs like FreeType's `ftview` application or other
1075 glyph viewers that are able to bypass the `cmap` table might be affected.)
1078 Writing Systems
1079 ---------------
1081 In FreeType terminology, a writing system is a set of functions that
1082 provides auto-hinting for certain scripts.  Right now, only two writing
1083 systems from FreeType's auto-hinter are available in ttfautohint: 'dummy'
1084 and 'latin'.  The former handles the 'no-script' case; details to 'latin'
1085 follow in the next section.
1088 Scripts
1089 -------
1091 ttfautohint needs to know which script should be used to hint a specific
1092 glyph.  To do so, it checks a glyph's Unicode character code whether it
1093 belongs to a given script.
1095 See '[Character Ranges](#character-ranges)' for a complete list of all
1096 handled scripts and its ranges.  This list is auto-generated from a source
1097 code file, covering the `latin' writing system.  It also covers some
1098 non-latin scripts (in the Unicode sense) that have similar typographical
1099 properties.
1101 In ttfautohint, scripts are identified by four-character tags (if there are
1102 less characters, spaces are appended).  The value `none` indicates 'no
1103 script'.
1105 Each script is represented by two tables to handle 'base' and 'non-base'
1106 characters.  For ttfautohint, a non-base character is something that should
1107 not be affected by blue zones, regardless of whether this is a spacing or
1108 no-spacing glyph.  In other words, non-base characters are hinted using a
1109 script's default stem width without applying blue zones.
1111 Right now, there are two pseudo-scripts that are used as fallbacks: `latb`
1112 and `latp`, used for latin subscript and superscript characters,
1113 respectively.  Its main usage is support of phonetic alphabets like the IPA,
1114 which intermix those characters with normal characters sitting on the
1115 baseline, and which are not specially handled in corresponding OpenType
1116 features like `sups`.
1118 If a glyph's character code is not covered by a script range, it is not
1119 hinted (or rather, it gets hinted by the 'dummy' auto-hinting module that
1120 essentially does nothing).  This can be changed by specifying a *fallback
1121 script*; see option [`--fallback-script`](#fallback-script).
1124 OpenType Features
1125 -----------------
1127 (Please read the [OpenType specification] for details on *features*, `GSUB`,
1128 and `GPOS` tables, and how they relate to scripts.)
1130 For modern OpenType fonts, character ranges are not sufficient to handle
1131 scripts.
1133   * Due to glyph substitution in the font (as specified in a font's `GSUB`
1134     table), which handles ligatures and similar typographic features, there
1135     is no longer a one-to-one mapping from an input Unicode character to a
1136     glyph index.  Some ligatures, like 'fi', actually do have Unicode values
1137     for historical reasons, but most of them don't.  While it is possible to
1138     map ligature glyphs into Unicode's Private Use Area (PUA), code values
1139     from this area are arbitrary by definition and thus unusable for
1140     ttfautohint.
1142   * Some features like `sups` (for handling superscript) completely change
1143     the appearance and even vertical position of the affected glyphs.
1144     Obviously, the blue zones for 'normal' glyphs no longer fit, thus the
1145     auto-hinter puts them into a separate group (called *style* in FreeType
1146     speak), having its own set of blue zones.
1149 Table: OpenType features handled specially by ttfautohint
1151     Feature tag    Description
1152   ---------------  -------------
1153   `c2cp`           petite capitals from capitals
1154   `c2sc`           small capitals from capitals
1155   `ordn`           ordinals
1156   `pcap`           petite capitals
1157   `sinf`           scientific inferiors
1158   `smcp`           small capitals
1159   `subs`           subscript
1160   `sups`           superscript
1161   `titl`           titling
1164 There are two conditions to get a valid style for a feature in a given
1165 script.
1167  1. One of the script's standard characters must be available in the
1168     feature.
1170  2. The feature must provide characters to form at least one blue zone; see
1171     [above](#blue-zones).
1173 An additional complication is that features from the above table might use
1174 data not only from the `GSUB` but also from the `GPOS` table, containing
1175 information for glyph positioning.  For example, the `sups` feature for
1176 superscripts might use the same glyphs as the `subs` feature for subscripts,
1177 simply moved up.  ttfautohint skips such vertically shifted glyphs (except
1178 for accessing standard characters) because glyph positioning happens after
1179 hinting.  Continuing our example, the `sups` feature wouldn't form a style,
1180 contrary to `subs`, which holds the unshifted glyphs.
1182 The remaining OpenType features of a script are not handled specially; the
1183 affected glyphs are simply hinted together with the 'normal' glyphs of the
1184 script.
1186 Note that a font might still contain some features not covered yet: OpenType
1187 has the concept of a *default script*; its data gets used for all scripts
1188 that aren't explicitly handled in a font.  By default, ttfautohint unifies
1189 all affected glyphs from default script features with the `latn` script.
1190 This can be changed with option [`--default-script`](#default-script), if
1191 necessary.
1194 ttfautohint uses the [HarfBuzz] library for handling OpenType features.
1197 SFNT Tables
1198 -----------
1200 ttfautohint touches almost all SFNT tables within a TrueType or OpenType
1201 font.  Note that only OpenType fonts with TrueType outlines are supported.
1202 OpenType fonts with a `CFF` table (this is, with PostScript outlines) won't
1203 work.
1205   * `glyf`: All hints in the table are replaced with new ones.  If option
1206     [`--composites`](#hint-composites) is used, one glyph gets added (namely
1207     the '\.ttfautohint' glyph) and all composites get an additional
1208     component.
1210   * `cvt`, `prep`, and `fpgm`: These tables get replaced with data
1211     necessary for the new hinting bytecode.
1213   * `gasp`: Set up to always use grayscale rendering, for all sizes, with
1214     grid-fitting for standard hinting, and symmetric grid-fitting and
1215     symmetric smoothing for horizontal subpixel hinting (ClearType).
1217   * `DSIG`: If it exists, it gets replaced with a dummy version.
1218     ttfautohint can't digitally sign a font; you have to do that afterwards.
1220   * `name`: The 'version' entries are modified to add information about the
1221     parameters that have been used for calling ttfautohint.  This can be
1222     controlled with the [`--no-info`](#ttfautohint-info) option.
1224   * `GPOS`, `hmtx`, `loca`, `head`, `maxp`, `post`: Updated to fit the
1225     additional '\.ttfautohint' glyph, the additional subglyphs in
1226     composites, and the new hinting bytecode.
1228   * `LTSH`, `hdmx`: Since ttfautohint doesn't do any horizontal hinting,
1229     those tables are superfluous and thus removed.
1231   * `VDMX`: Removed, since it depends on the original bytecode, which
1232     ttfautohint removes.  A font editor might recompute the necessary data
1233     later on.
1236 Problems
1237 --------
1239 ### Interaction With FreeType
1241 Recent versions of FreeType have an experimental extension for handling
1242 subpixel hinting; it is off by default and can be activated by defining the
1243 macro `TT_CONFIG_OPTION_SUBPIXEL_HINTING` at compile time.  This code has
1244 been contributed mainly by [Infinality], being a subset of his original
1245 patch.  Many GNU/Linux distributions activate this code, or provide packages
1246 to activate it.
1248 This extension changes the behaviour of many bytecode instructions to get
1249 better rendering results.  However, not all changes are global; some of them
1250 are specific to certain fonts.  For example, it contains font-specific
1251 improvements for the '[DejaVu] Sans' font family.  The list of affected
1252 fonts is hard-coded; it can be found in FreeType's source code file
1253 `ttsubpix.c`.
1255 If you are going to process such specially-handled fonts with ttfautohint,
1256 serious rendering problems might show up.  Since ttfautohint (intentionally)
1257 doesn't change the font name in the `name` table, the Infinality extension
1258 has no chance to recognize that the hints are different.  All such problems
1259 vanish if the font gets renamed in its `name` table (the name of the font
1260 file itself doesn't matter).
1262 ### Incorrect Unicode Character Map
1264 Fonts with an incorrect Unicode `cmap` table will not be properly hinted by
1265 ttfautohint.  Especially older fonts do cheat; for example, there exist
1266 Hebrew fonts that map its glyphs to character codes 'A', 'B', etc., to make
1267 them work with non-localized versions of Windows\ 98, say.
1269 Since ttfautohint needs to find both standard and blue zone characters, it
1270 relies on correct Unicode values.  If you want to handle such fonts, please
1271 fix their `cmap` tables accordingly.
1273 ### Irregular Glyph Heights
1275 The central concept of ttfautohint's hinting algorithm, as discussed
1276 [above](#segments-and-edges), is to identify horizontal segments at extremum
1277 positions, especially for blue zones.  If such a segment is missing, it
1278 cannot be associated with a blue zone, possibly leading to irregular heights
1279 for the particular glyph.
1281 Normally, a segment has a horizontal length of at least 20\ font units
1282 (assuming 2048 units per EM)^[To be more precise, the sum of the height and
1283 length of a segment must be at least 20 font units, and the height multiplied
1284 by\ 14 must not exceed the length.  Thus (19,1) is also a valid minimum
1285 (length,height) pair, while (18,2) isn't.  The value\ 20 is heuristic and
1286 hard-coded, as is the value\ 14 (corresponding to a slope of approx.
1287 4.1°).].  Using a [Control Instructions File](#control-instructions-file),
1288 however, it is possible to define additional segments at arbitrary points
1289 that help overcome this restriction, making it possible to fix (most of)
1290 such problems.
1292 ### Diagonals
1294 ttfautohint doesn't handle diagonal lines specially.  For thin outlines,
1295 this might lead to strokes that look too thick at smaller sizes.  A font
1296 designer might compensate this to a certain amount by slightly reducing the
1297 stroke width of diagonal lines.  However, in many cases the sub-optimal
1298 appearance of a stroke with borders that don't exactly fit the pixel grid is
1299 not the outline itself but an incorrect gamma value of the monitor: People
1300 tend to not properly adjust it, and the default values of most operating
1301 systems are too low, causing too much darkening of such strokes.  It is thus
1302 of vital importance to compare ttfautohint's results with similar fonts to
1303 exclude any systematic effect not related to the outlines themselves.
1307 Control Instructions
1308 ====================
1310 An entry in a control instructions file has various syntax forms, which are
1311 discussed here.  Brackets indicate optional elements.
1314 Common Syntax Elements
1315 ----------------------
1317 *font‑idx* gives the index of the font in a TrueType Collection, starting
1318 with value\ 0.  If missing, it is set to zero.  For normal TrueType fonts,
1319 only value zero is valid.  A font index can be specified in decimal, octal,
1320 or hexadecimal format, the latter two indicated by the prefixes `0` and
1321 `0x`, respectively.
1323 *glyph‑id* is either a glyph's name as listed in the `post` SFNT table or a
1324 glyph index.  A glyph name consists of characters from the set
1325 '`A-Za-z0-9._`' only and does not start with a digit or period, with the
1326 exceptions of the names '`.notdef`' and '`.null`'.  A glyph index starts
1327 with value\ 0 can be specified in decimal, octal, or hexadecimal format, the
1328 latter two indicated by the prefixes `0` and `0x`, respectively.  Glyph
1329 names are internally converted to glyph indices.
1331 *points* are number ranges, see '[x Height Snapping
1332 Exceptions](#x-height-snapping-exceptions)' for the syntax.
1334 Similar to the Bourne shell (`sh` or `bash`), a comment starts with
1335 character '`#`'; the rest of the line is ignored.  An empty line is ignored
1336 also.  Both the newline character and '`;`' can be used as a separator
1337 between exception entries.  A trailing '`\`' at the end of a line continues
1338 the current line on the next one.
1340 A control instructions file is parsed line by line; later entries override
1341 earlier entries (in case there is something to override).
1344 Style Adjustments
1345 -----------------
1347 This syntax form makes it possible to override the style assignment
1348 algorithm of ttfautohint; see '[Scripts](#scripts)' and '[OpenType
1349 Features](#opentype-features)' for more details.
1351 > *\[*\ font-idx\ *\]*\ \ script\ \ feature\ \ *`@`*\ \ glyph-ids
1353 *script* is a four-letter name of one of the scripts supported by
1354 ttfautohint.  *feature* is one of the four-letter names of features
1355 supported by ttfautohint.
1357 The elements of *glyph-ids* are a list of comma separated *glyph-id* values
1358 or value ranges.  Note that is not necessary that elements are specified in
1359 increasing order.
1361 Assuming that a font contains superscript digits 'zero.sups' to 'nine.sups'
1362 together with the glyphs 'a.sups' and 'o.sups', use a line
1365     cyrl sups @ zero.sups-nine.sups, a.sups, o.sups
1368 to add those glyphs to the style handling Cyrillic superscript glyphs.
1369 However, it is still necessary that the selected script contains proper
1370 [Blue Zone characters](#blue-zones), otherwise those glyphs aren't handled
1371 at all.
1373 Use the `--debug` command line option to see how ttfautohint assigns glyph
1374 indices of a font to styles.
1377 Glyph Adjustments
1378 -----------------
1380 The following syntax forms allows adjustments of a glyph's hinting process.
1382 ### Change Direction of Points, Artificial Segments
1384 > *\[*\ font‑idx\ *\]*\ \ glyph‑id\ \ *`l`\[`eft`\]|`r`\[`ight`\]*\ \ points\ \ *\[*\ *`(`*\ left‑offset\ *`,`*\ right‑offset\ *`)`*\ *\]*\
1386 The mutually exclusive parameters `left` and `right` (which can be
1387 abbreviated as '`l`' and '`r`', respectively) indicate that the following
1388 points have left or right 'out' direction, respectively, overriding
1389 ttfautohint's algorithm for setting point directions.  The 'out direction'
1390 of a point is the direction of the outline *leaving* the point (or passing
1391 the control point).  If the specified direction is identical to what
1392 ttfautohint computes, nothing special happens.  Otherwise, a one-point
1393 segment with the specified direction gets created, see
1394 [above](#segments-and-edges).  By default, its length is zero.  Setting
1395 *left‑offset* and *right‑offset*, you can change the segment's horizontal
1396 start and end position relative to the point position.  *left‑offset* and
1397 *right‑offset* are integers measured in font units.
1399 The following five images, displaying glyphs 'O' and 'Q' from the font
1400 [Halant-Regular](http://www.google.com/fonts/specimen/Halant), demonstrate
1401 how to use direction changes.
1403 ![The outlines of glyphs 'O' and 'Q', as displayed in FontForge.  They are
1404   sufficiently similar to expect that ttfautohint hints them equally.
1405   However, this is not the case.](img/Halant-Regular-O-Q.png)
1407 ![The same glyphs, shown at 12px before hinting.  [Please ignore the outline
1408   distortion in the upper right of glyph 'O'; this is a bug in FontForge
1409   while running the TrueType
1410   debugger.]](img/Halant-Regular-O-Q-unhinted-12px.png)
1412 ![Using only ttfautohint's '`-w gGD`' parameter to force strong stem width
1413   and positioning, the hinting of glyph 'Q' is really bad, making the glyph
1414   vertically two pixels larger!  Reason is that this glyph doesn't contain a
1415   horizontal segment at the baseline blue zone (*y*\ =\ 1; this corresponds
1416   to the segment 13-14 in the 'O' glyph).  Normally, segment 1-2 would form
1417   a 'stem' with the baseline segment (as segment 7-8 does in glyph 'O').
1418   Instead, it forms a stem with segment 19-20, which gets moved down
1419   (*y*\ =\ −1) because the whole glyph appears to be
1420   stretched.](img/Halant-Regular-O-good-Q-badly-hinted-12px.png)
1422 ![To fix the problem, we change the direction of point\ 38 to 'left' by
1423   writing a line '`Q left 38`' (without the quotes) to a control description
1424   file `Halant-Regular.txt`.  Adding option '`-m Halant-Regular.txt`' to
1425   ttfautohint, we get the shown image as a result, which is much better:
1426   Segment 1-2 now properly forms a stem with our artificial one-point
1427   segment\ 38, and the 'O'-like shape is properly positioned.  However,
1428   there is still room for improvement: Segment 19-20 is also positioned at
1429   the baseline, making the connection between the 'O' shape and the tail too
1430   thin.](img/Halant-Regular-O-good-Q-better-hinted-12px.png)
1432 ![By giving the one-point segment\ 38 a horizontal width, we can prevent
1433   that segment 19-20 gets positioned at the baseline: Replace the line in
1434   the previous image description with '`Q left 38 (−70,20)`', making the
1435   segment extend 70 font units to the left and 20 to the right of point\ 38.
1436   The exact offset values don't matter; it's only important to start left of
1437   point\ 19.  Another solution to the problem is to artificially change the
1438   direction of segment 19-20 by adding a second line '`Q right 19-20`' to
1439   the control instructions file; for our 'Q' glyph, this produces almost
1440   exactly the same hinting results.  Note that such direction changes only
1441   influence the hinting process; an outline's direction won't be changed at
1442   all.](img/Halant-Regular-O-good-Q-well-hinted-12px.png)
1444 ### Unset Direction of Points
1446 > *\[*\ font‑idx\ *\]*\ \ glyph‑id\ \ *`n`\[`odir`\]*\ \ points\
1448 Parameter `nodir` (or '`n`') sets the 'out' direction of the following
1449 points to 'no direction', this is, neither left nor right.  If the specified
1450 direction is identical to what ttfautohint computes, nothing special
1451 happens.  Otherwise, ttfautohint no longer considers those points as part of
1452 horizontal segments, thus treating them as ['weak'](#grid-fitting) points.
1454 Modifying or adding segments doesn't directly modify the outlines; it only
1455 influences the hinting process.
1457 ### Delta Exceptions
1459 > *\[*\ font‑idx\ *\]*\ \ glyph‑id\ \ *`t`\[`ouch`\]|`p`\[`oint`\]*\ \ points\ \ *\[*\ *`x`\[`shift`\]*\ x‑shift\ *\]*\ \ *\[*\ *`y`\[`shift`\]*\ y‑shift\ *\]*\ \ *`@`*\ \ ppems\
1461 The mutually exclusive parameters `touch` and `point` (which can be
1462 abbreviated as '`t`' and '`p`', respectively) make ttfautohint apply delta
1463 exceptions for the given points, shifting them by the given values.  Delta
1464 exceptions entered with `touch` are applied before the final 'IUP'
1465 (*interpolate untouched points*) instructions in a glyph's bytecode,
1466 exceptions entered with `point` after 'IUP' (please consult Greg Hitchcock's
1467 [ClearType Whitepaper] for more on pre-IUP and post-IUP delta hints).
1468 Additionally, the `touch` parameter makes the bytecode *touch* the affected
1469 points; such points are no longer affected by 'IUP' at all.  Note that in
1470 ClearType mode all deltas along the x\ axis are discarded, and deltas along
1471 the y\ axis are only executed for touched points.  As a consequence,
1472 vertical delta exceptions entered with `point` should not be used in
1473 ClearType mode.^[Unfortunately, there is a bug in FreeType prior to version
1474 2.5.4 (released in December 2014) that completely disables vertical delta
1475 exceptions if subpixel hinting is activated.  For this reason you should
1476 expect that the `touch` parameter fails on older GNU/Linux distributions.]
1478 *ppems*, similar to *points*, are number ranges, see '[x Height Snapping
1479 Exceptions](#x-height-snapping-exceptions)' for the syntax.
1481 *x‑shift* and *y‑shift* represent real numbers that get rounded to multiples
1482 of 1/8 pixels.  The entries for `xshift` ('`x`') and `yshift` ('`y`') are
1483 optional; if missing, the corresponding value is set to zero.  If both
1484 values are zero, the delta exception entry is ignored as a whole.
1486 Values for *x‑shift* and *y‑shift* must be in the range [−1.0;1.0].  Values
1487 for *ppems* must be in the range [6;53].  Values for *points* are limited by
1488 the number of points in the glyph.
1490 Note that only character '`.`' is recognized as a decimal point, and a
1491 thousands separator is not accepted.
1493 As an example for delta instructions, let's assume that you want to shift
1494 points 2, 3, and\ 4 in glyph `Aacute' at ppem sizes 12 and\ 13 by a vertical
1495 amount of 0.25 pixels.  This corresponds to the line
1498     Aacute  touch 2-4  yshift 0.25  @ 12, 13
1501 in a control instructions file.  Since we use `touch` and not `point`,
1502 points 2, 3, and\ 4 are no longer subject to the final 'IUP' instruction,
1503 which interpolates weak, untouched point positions between strong, touched
1504 ones, cf.  the description
1505 [here](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM05/Chap5.html#IUP).