6 Copyright (C) 2011-2014 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.
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),
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
49 and Apple's [TrueType Reference
50 Manual](https://developer.apple.com/fonts/TTRefMan/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.
60 In general, there are three possible ways to hint a glyph.
62 1. The font contains hints (in the original sense of this word) to guide
63 the rasterizer, telling it which shapes of the glyphs need special
64 consideration. The hinting logic is partly in the font and partly in
65 the rasterizer. More sophisticated rasterizers are able to produce
66 better rendering results.
68 This is how Type\ 1 and CFF hints work.
70 2. The font contains exact instructions (also called *bytecode*) on how to
71 move the points of its outlines, depending on the resolution of the
72 output device, and which intentionally distort the (outline) shape to
73 produce a well-rasterized result. The hinting logic is in the font;
74 ideally, all rasterizers simply process these instructions to get the
75 same result on all platforms.
77 This is how TrueType hints work.
79 3. The font gets auto-hinted (at run-time). The hinting logic is
80 completely in the rasterizer. No hints in the font are used or needed;
81 instead, the rasterizer scans and analyzes the glyphs to apply
82 corrections by itself.
84 This is how FreeType's auto-hinter works; see
85 [below](#background-and-technical-details) for more.
88 What problems can arise with TrueType hinting?
89 ----------------------------------------------
91 While it is relatively easy to specify PostScript hints (either manually or
92 by an auto-hinter that works at font creation time), creating TrueType
93 hints is far more difficult. There are at least two reasons:
95 - TrueType instructions form a programming language, operating at a very
96 low level. They are comparable to assembler code, thus lacking all
97 high-level concepts to make programming more comfortable.
99 Here an example how such code looks like:
103 PUSHB[ ] /* 3 values pushed */
106 PUSHB[ ] /* 2 values pushed */
109 PUSHB[ ] /* 3 values pushed */
114 Another major obstacle is the fact that font designers usually aren't
117 - It is very time consuming to manually hint glyphs. Given that the
118 number of specialists for TrueType hinting is very limited, hinting a
119 large set of glyphs for a font or font family can become very expensive.
125 The ttfautohint library brings the excellent quality of FreeType rendering
126 to platforms that don't use FreeType, yet require hinting for text to look
127 good -- like Microsoft Windows. Roughly speaking, it converts the glyph
128 analysis done by FreeType's auto-hinting module to TrueType bytecode.
129 Internally, the auto-hinter's algorithm resembles PostScript hinting
130 methods; it thus combines all three hinting methods discussed
131 [previously](#what-exactly-are-hints).
133 The simple interface of the front-ends (both on the command line and with
134 the GUI) allows quick hinting of a whole font with a few mouse clicks or a
135 single command on the prompt. As a result, you get better rendering results
136 with web browsers, for example.
138 Across Windows rendering environments today, fonts processed with
139 ttfautohint look best with ClearType enabled. This is the default for
140 Windows\ 7. Good visual results are also seen in recent MacOS\ X versions
141 and GNU/Linux systems (including Android, ChromeOS, and other mobile
142 operating systems) that use FreeType for rendering glyphs.
144 The goal of the project is to generate a 'first pass' of hinting that font
145 developers can refine further for ultimate quality.
149 `ttfautohint` and `ttfautohintGUI`
150 ==================================
152 On all supported platforms (GNU/Linux, Windows, and Mac OS\ X), the GUI
153 looks quite similar; the used toolkit is [Qt], which in turn uses the
154 platform's native widgets.
156 ![`ttfautohintGUI` on GNU/Linux running KDE](img/ttfautohintGUI.png)
158 Both the GUI and console version share the same features, to be discussed in
161 **Warning: ttfautohint cannot always process a font a second time.**
162 If the font contains composite glyphs, and [option `-c`](#hint-composites)
163 is used, reprocessing with ttfautohint will fail. For this reason it is
164 strongly recommended to *not* delete the original, unhinted font so that you
165 can always rerun ttfautohint.
168 Calling `ttfautohint`
169 ---------------------
172 ttfautohint [OPTION]... [IN-FILE [OUT-FILE]]
175 The TTY binary, `ttfautohint`, works like a Unix filter, this is, it reads
176 data from standard input if no input file name is given, and it sends its
177 output to standard output if no output file name is specified.
179 A typical call looks like the following.
182 ttfautohint -v -f latn foo.ttf foo-autohinted.ttf
185 For demonstration purposes, here the same using a pipe and redirection.
186 Note that Windows's default command line interpreter, `cmd.exe`, doesn't
187 support piping with binary files, unfortunately.
190 cat foo.ttf | ttfautohint -v -f latn > foo-autohinted.ttf
194 Calling `ttfautohintGUI`
195 ------------------------
198 ttfautohintGUI [OPTION]...
201 `ttfautohintGUI` doesn't send any output to a console; however, it accepts
202 the same command line options as `ttfautohint`, setting default values for
209 Long options can be given with one or two dashes, and with and without an
210 equal sign between option and argument. This means that the following forms
211 are acceptable: `-foo=`*bar*, `--foo=`*bar*, `-foo`\ *bar*, and
214 Below, the section title refers to the command's label in the GUI (if
215 applicable), then comes the name of the corresponding long command line
216 option and its short equivalent, followed by a description.
218 Background and technical details on the meaning of the various options are
219 given [afterwards](#background-and-technical-details).
221 ### Hint Set Range Minimum, Hint Set Range Maximum
223 See ['Hint Sets'](#hint-sets) for a definition and explanation.
225 `--hinting-range-min=`*n*, `-l`\ *n*
226 : The minimum PPEM value (in pixels) at which hint sets are created. The
227 default value for *n* is\ 8.
229 `--hinting-range-max=`*n*, `-r`\ *n*
230 : The maximum PPEM value (in pixels) at which hint sets are created. The
231 default value for *n* is 50.
235 `--default-script=`*s*, `-D`\ *s*
236 : Set default script to tag *s*, which is a string consisting of four
237 lowercase characters like `latn` or `dflt`. It is needed to specify the
238 OpenType default script: After applying all features that are handled
239 specially (like small caps or superscript), ttfautohint uses this value
240 for the remaining features. The default value is `latn`. See
241 [below](#opentype-features) for more details.
245 `--fallback-script=`*s*, `-f`\ *s*
246 : Set fallback script to tag *s*, which is a string consisting of four
247 characters like `latn` or `dflt`. It gets used for for all glyphs that
248 can't be assigned to a script automatically. See [below](#scripts) for
253 `--hinting-limit=`*n*, `-G`\ *n*
254 : The *hinting limit* is the PPEM value (in pixels) where hinting gets
255 switched off (using the `INSTCTRL` bytecode instruction, not the `gasp`
256 table data); it has zero impact on the file size. The default value for
257 *n* is 200, which means that the font is not hinted for PPEM values
260 Note that hinting in the range 'hinting-range-max' up to 'hinting-limit'
261 uses the hinting configuration for 'hinting-range-max'.
263 To omit a hinting limit, use `--hinting-limit=0` (or check the 'No
264 Hinting Limit' box in the GUI). Since this causes internal math
265 overflow in the rasterizer for large pixel values (>\ 1500px approx.) it
266 is strongly recommended to not use this except for testing purposes.
268 ### x Height Increase Limit
270 `--increase-x-height=`*n*, `-x`\ *n*
271 : Normally, ttfautohint rounds the x\ height to the pixel grid, with a
272 slight preference for rounding up (to use the terminology of TrueType's
273 'Super Round' bytecode instruction, the threshold is 5/8px). If this
274 flag is set, values in the range 6\ PPEM to *n*\ PPEM are much more
275 often rounded up (setting the threshold to 13/16px). The default value
276 for *n* is 14. Use this flag to increase the legibility of small sizes
277 if necessary; you might get weird rendering results otherwise for glyphs
278 like 'a' or 'e', depending on the font design.
280 To switch off this feature, use `--increase-x-height=0` (or check the
281 'No x\ Height Increase' box in the GUI). To switch off rounding the
282 x\ height to the pixel grid in general, either partially or completely,
283 see ['x Height Snapping Exceptions'](#x-height-snapping-exceptions).
285 The following images again use the font 'Mertz Bold'.
287 ![At 17px, without option `-x` and '`-w ""`', the hole in glyph 'e'
288 looks very grey in the FontForge snapshot, and the GDI ClearType
289 rendering (which is the default on older Windows versions) fills it
290 completely with black because it uses B/W rendering along the y\ axis.
291 FreeType's 'light' autohint mode (which corresponds to ttfautohint's
292 'smooth' stem width algorithm) intentionally aligns horizontal lines
293 to non-integer (but still discrete) values to avoid large glyph shape
294 distortions.](img/e-17px-x14.png)
296 ![The same, this time with option `-x 17` (and
297 '`-w ""`').](img/e-17px-x17.png)
299 ### x Height Snapping Exceptions
301 `--x-height-snapping-exceptions=`*string*, `-X`\ *string*
302 : A list of comma separated PPEM values or value ranges at which no
303 x\ height snapping shall be applied. A value range has the form
304 *value1*`-`*value2*, meaning *value1*\ <= PPEM <=\ *value2*. *value1*
305 or *value2* (or both) can be missing; a missing value is replaced by the
306 beginning or end of the whole interval of valid PPEM values,
307 respectively (6\ to 32767). Whitespace is not significant; superfluous
308 commas are ignored, and ranges must be specified in increasing order.
309 For example, the string `"7-9, 11, 13-"` means the values 7, 8, 9, 11,
310 13, 14, 15, etc. Consequently, if the supplied argument is `"-"`, no
311 x\ height snapping takes place at all. The default is the empty string
312 (`""`), meaning no snapping exceptions.
314 Normally, x\ height snapping means a slight increase in the overall
315 vertical glyph size so that the height of lowercase glyphs gets aligned
316 to the pixel grid (this is a global feature, affecting *all* glyphs of a
317 font). However, having larger vertical glyph sizes is not always
318 desired, especially if it is not possible to adjust the `usWinAscent`
319 and `usWinDescent` values from the font's `OS/2` table so that they are
320 not too tight. See ['Windows Compatibility'](#windows-compatibility)
323 ### Fallback Stem Width
325 `--fallback-stem-width=`*n*, `-H`\ *n*
326 : Set the horizontal stem width (hinting) value for all scripts that lack
327 proper standard characters in the font. The value is given in font
328 units and must be a positive integer. If not set, ttfautohint uses a
329 hard-coded default (50\ units at 2048 units per EM, and linearly scaled
330 for other UPEM values, for example 24\ units at 1000 UPEM).
332 For symbol fonts, you need option `--fallback-script` too (to set up a
335 In the GUI, uncheck the 'Default Fallback Stem Width' box to activate
338 ### Windows Compatibility
340 `--windows-compatibility`, `-W`
341 : This option makes ttfautohint add two artificial blue zones, positioned
342 at the `usWinAscent` and `usWinDescent` values (from the font's `OS/2`
343 table). The idea is to help ttfautohint so that the hinted glyphs stay
344 within this horizontal stripe since Windows clips everything falling
347 There is a general problem with tight values for `usWinAscent` and
348 `usWinDescent`; a good description is given in the [Vertical Metrics
349 How-To](http://typophile.com/node/13081). Additionally, there is a
350 special problem with tight values if used in combination with
351 ttfautohint because the auto-hinter tends to slightly increase the
352 vertical glyph dimensions at smaller sizes to improve legibility. This
353 enlargement can make the heights and depths of glyphs exceed the range
354 given by `usWinAscent` and `usWinDescent`.
356 If ttfautohint is part of the font creation tool chain, and the font
357 designer can adjust those two values, a better solution instead of using
358 option `-W` is to reserve some vertical space for 'padding': For the
359 auto-hinter, the difference between a top or bottom outline point before
360 and after hinting is less than 1px, thus a vertical padding of 2px is
361 sufficient. Assuming a minimum hinting size of 6ppem, adding two pixels
362 gives an increase factor of 8÷6 = 1.33. This is near to the default
363 baseline-to-baseline distance used by TeX and other sophisticated text
364 processing applications, namely 1.2×designsize, which gives satisfying
365 results in most cases. It is also near to the factor 1.25 recommended
366 in the abovementioned how-to. For example, if the vertical extension of
367 the largest glyph is 2000 units (assuming that it approximately
368 represents the designsize), the sum of `usWinAscent` and `usWinDescent`
369 could be 1.25×2000 = 2500.
371 In case ttfautohint is used as an auto-hinting tool for fonts that can
372 be no longer modified to change the metrics, option `-W` in combination
373 with '`-X "-"`' to suppress any vertical enlargement should prevent
378 `--adjust-subglyphs`, `-p`
379 : *Adjusting subglyphs* makes a font's original bytecode be applied to all
380 glyphs before it is replaced with bytecode created by ttfautohint. This
381 makes only sense if your font already has some hints in it that modify
382 the shape even at EM size (normally 2048px); in particular, some CJK
383 fonts need this because the bytecode is used to scale and shift
384 subglyphs (hence the option's long name). For most fonts, however, this
390 : By default, the components of a composite glyph get hinted separately.
391 If this flag is set, the composite glyph itself gets hinted (and the
392 hints of the components are ignored). Using this flag increases the
393 bytecode size a lot, however, it might yield better hinting results.
395 If this option is used (and a font actually contains composite glyphs),
396 ttfautohint currently cannot reprocess its own output for technical
397 reasons, see [below](#the-.ttfautohint-glyph).
402 : Process a font that ttfautohint would refuse otherwise because it can't
403 find a single standard character for any of the supported scripts.
405 For all scripts that lack proper standard characters, ttfautohint uses a
406 default (hinting) value for the standard stem width instead of deriving
407 it from a script's set of standard characters (for the latin script, one
408 of them is character 'o').
410 Use this option (usually in combination with option `--fallback-script`)
411 to hint symbol or dingbat fonts or math glyphs, for example, at the
412 expense of possibly poor hinting results at small sizes.
417 : Strip off all hints without generating new hints. Consequently, all
418 other hinting options are ignored. This option is intended for testing
421 ### Add ttfautohint Info
424 : Don't add ttfautohint version and command line information to the
425 version string or strings (with name ID\ 5) in the font's `name` table.
426 In the GUI it is similar: If you uncheck the 'Add ttfautohint info' box,
427 information is not added to the `name` table. Except for testing and
428 development purposes it is strongly recommended to not use this option.
430 ### Strong Stem Width and Positioning
432 `--strong-stem-width=`*string*, `-w`\ *string*
433 : ttfautohint offers two different routines to handle (horizontal) stem
434 widths and stem positions: 'smooth' and 'strong'. The former uses
435 discrete values that slightly increase the stem contrast with almost no
436 distortion of the outlines, while the latter snaps both stem widths and
437 stem positions to integer pixel values as much as possible, yielding a
438 crisper appearance at the cost of much more distortion.
440 These two routines are mapped onto three possible rendering targets:
442 - grayscale rendering, with or without optimization for subpixel
443 positioning (e.g. Android)
445 - 'GDI ClearType' rendering: the rasterizer version, as returned by the
446 GETINFO bytecode instruction, is in the range 36\ <= version <\ 38 and
447 ClearType is enabled (e.g. Windows XP)
449 - 'DirectWrite ClearType' rendering: the rasterizer version, as returned
450 by the GETINFO bytecode instruction, is >=\ 38, ClearType is enabled,
451 and subpixel positioning is enabled also (e.g. Internet Explorer\ 9
452 running on Windows\ 7)
454 GDI ClearType uses a mode similar to B/W rendering along the vertical
455 axis, while DW ClearType applies grayscale rendering. Additionally,
456 only DW ClearType provides subpixel positioning along the x\ axis. For
457 what it's worth, the rasterizers version\ 36 and version\ 38 in
458 Microsoft Windows are two completely different rendering engines.
460 The command line option expects *string* to contain up to three letters
461 with possible values '`g`' for grayscale, '`G`' for GDI ClearType, and
462 '`D`' for DW ClearType. If a letter is found in *string*, the strong
463 stem width routine is used for the corresponding rendering target (and
464 smooth stem width handling otherwise). The default value is '`G`', which
465 means that strong stem width handling is activated for GDI ClearType
466 only. To use smooth stem width handling for all three rendering
467 targets, use the empty string as an argument, usually connoted with
470 In the GUI, simply set the corresponding check box to select the strong
471 width routine for a given rendering target. If you unset the check box,
472 the smooth width routine gets used.
474 The following FontForge snapshot images use the font ['Mertz
475 Bold'](http://code.newtypography.co.uk/mertz-sans/) (still under
476 development) from [Vernon Adams].
478 ![The left part shows the glyph 'g' unhinted at 26px, the right part
479 with hints, using the 'smooth' stem algorithm.](img/ff-g-26px.png)
481 ![The same, but this time using the 'strong'
482 algorithm. Note how the stems are aligned to the pixel
483 grid.](img/ff-g-26px-wD.png)
487 Watch input file (GUI only)
488 : If this checkbox is set, automatically regenerate the output file as
489 soon as the input file gets modified.
491 Pressing the 'Run' button starts watching. If an error occurs, watching
492 stops and must be restarted with the 'Run' button.
494 `--ignore-restrictions`, `-i`
495 : By default, fonts that have bit\ 1 set in the 'fsType' field of the
496 `OS/2` table are rejected. If you have a permission of the font's legal
497 owner to modify the font, specify this command line option.
499 If this option is not set, `ttfautohintGUI` shows a dialogue to handle
500 such fonts if necessary.
503 : On the console, print a brief documentation on standard output and exit.
504 This doesn't work with `ttfautohintGUI` on MS Windows.
507 : On the console, print version information on standard output and exit.
508 This doesn't work with `ttfautohintGUI` on MS Windows.
511 : Print *a lot* of debugging information on standard error while
512 processing a font (you should redirect stderr to a file). This
513 doesn't work with `ttfautohintGUI` on MS Windows.
517 Background and Technical Details
518 ================================
520 [Real-Time Grid Fitting of Typographic
521 Outlines](http://www.tug.org/TUGboat/tb24-3/lemberg.pdf) is a scholarly
522 paper that describes FreeType's auto-hinter in some detail. Regarding the
523 described data structures it is slightly out of date, but the algorithm
524 itself hasn't changed in general.
526 The next few subsections are mainly based on this article, introducing some
527 important concepts. Note that ttfautohint only does hinting along the
528 vertical direction (modifying y\ coordinates only).
534 A glyph consists of one or more *contours* (this is, closed curves). For
535 example, glyph 'O' consists of two contours, while glyph 'I' has only one.
537 ![The letter 'O' has two contours, an inner and an outer one, while letter
538 'I' has only an outer contour.](img/o-and-i)
540 A *segment* is a series of consecutive points of a contour (including its
541 Bézier control points) that are approximately aligned along a coordinate
544 ![A serif. Contour and control points are represented by squares and
545 circles, respectively. The bottom 'line' DE is approximately aligned
546 along the horizontal axis, thus it forms a segment of 7\ points. Together
547 with the two other horizontal segments, BC and FG, they form two edges
548 (BC+FG, DE).](img/segment-edge)
550 An *edge* corresponds to a single coordinate value on the main dimension
551 that collects one or more segments (allowing for a small threshold). While
552 finding segments is done on the unscaled outline, finding edges is bound to
553 the device resolution. See [below](#hint-sets) for an example.
555 The analysis to find segments and edges is specific to a writing
556 system, see [below](#writing-systems).
562 The auto-hinter analyzes a font in two steps. Right now, everything
563 described here happens for the horizontal axis only, providing vertical
568 This affects the hinting of all glyphs, trying to give them a uniform
571 + Compute standard horizontal stem width of the font. The value
572 is normally taken from glyphs that resemble letter 'o'.
574 + Compute blue zones, see [below](#blue-zones).
576 If the stem widths of single glyphs differ by a large value, or if
577 ttfautohint fails to find proper blue zones, hinting becomes quite poor,
578 possibly leading even to severe shape distortions.
581 Table: script-specific standard characters of the 'latin' writing system
583 Script Standard characters
584 ---------- ---------------------
585 `cyrl` 'о', U+043E, CYRILLIC SMALL LETTER O
586 'О', U+041E, CYRILLIC CAPITAL LETTER O
587 `grek` 'ο', U+03BF, GREEK SMALL LETTER OMICRON
588 'Ο', U+039F, GREEK CAPITAL LETTER OMICRON
589 `hebr` 'ם', U+05DD, HEBREW LETTER FINAL MEM
590 `latn` 'o', U+006F, LATIN SMALL LETTER O
591 'O', U+004F, LATIN CAPITAL LETTER O
592 '0', U+0030, DIGIT ZERO
597 This is a per-glyph operation.
599 + Find segments and edges.
601 + Link edges together to find stems and serifs. The abovementioned
602 paper gives more details on what exactly constitutes a stem or a
603 serif and how the algorithm works.
609 ![Two blue zones relevant to the glyph 'a'. Vertical point coordinates of
610 *all* glyphs within these zones are aligned, provided the blue zone is
611 active (this is, its vertical size is smaller than
612 3/4\ pixels).](img/blue-zones)
614 Outlines of certain characters are used to determine *blue zones*. This
615 concept is the same as with Type\ 1 fonts: All glyph points that lie in
616 certain small horizontal zones get aligned vertically.
618 Here a series of tables that show the blue zone characters of the latin
619 writing system's available scripts; the values are hard-coded in the source
620 code. Since the auto-hinter takes mean values it is not necessary that all
621 characters of a zone are present.
624 Table: `latn` blue zones
626 ID Blue zone Characters
627 ---- ----------- ------------
628 1 top of capital letters THEZOCQS
629 2 bottom of capital letters HEZLOCUS
630 3 top of 'small f' like letters fijkdbh
631 4 top of small letters xzroesc
632 5 bottom of small letters xzroesc
633 6 bottom of descenders of small letters pqgjy
636 The 'round' characters (e.g. 'OCQS') from Zones 1, 2, and 5 are also used to
637 control the overshoot handling; to improve rendering at small sizes, zone\ 4
638 gets adjusted to be on the pixel grid; cf. the [`--increase-x-height`
639 option](#x-height-increase-limit).
642 Table: `grek` blue zones
644 ID Blue zone Characters
645 ---- ----------- ------------
646 1 top of capital letters ΓΒΕΖΘΟΩ
647 2 bottom of capital letters ΒΔΖΞΘΟ
648 3 top of 'small beta' like letters βθδζλξ
649 4 top of small letters αειοπστω
650 5 bottom of small letters αειοπστω
651 6 bottom of descenders of small letters βγημρφχψ
654 Table: `cyrl` blue zones
656 ID Blue zone Characters
657 ---- ----------- ------------
658 1 top of capital letters БВЕПЗОСЭ
659 2 bottom of capital letters БВЕШЗОСЭ
660 3 top of small letters хпншезос
661 4 bottom of small letters хпншезос
662 5 bottom of descenders of small letters руф
665 Table: `hebr` blue zones
667 ID Blue zone Characters
668 ---- ----------- ------------
669 1 top of letters בדהחךכםס
670 2 bottom of letters בטכםסצ
671 3 bottom of descenders of letters קךןףץ
674 ![This image shows the relevant glyph terms for vertical blue zone
675 positions.](img/glyph-terms)
681 Aligning outlines along the grid lines is called *grid fitting*. It doesn't
682 necessarily mean that the outlines are positioned *exactly* on the grid,
683 however, especially if you want a smooth appearance at different sizes.
684 This is the central routine of the auto-hinter; its actions are highly
685 dependent on the used writing system. Currently, only one writing system is
686 available (latin), providing support for scripts like Latin or Greek.
688 * Align edges linked to blue zones.
690 * Fit edges to the pixel grid.
694 * Handle remaining 'strong' points. Such points are not part of an edge
695 but are still important for defining the shape. This roughly
696 corresponds to the `IP` TrueType instruction.
698 * Everything else (the 'weak' points) is handled with an `IUP`
701 The following images illustrate the hinting process, using glyph 'a' from
702 the freely available font ['Ubuntu Book'](http://font.ubuntu.com). The
703 manual hints were added by [Dalton Maag Ltd], the used application to create
704 the hinting debug snapshots was [FontForge].
706 ![Before hinting.](img/a-before-hinting.png)
708 ![After hinting, using manual hints.](img/a-after-hinting.png)
710 ![After hinting, using ttfautohint. Note that the hinting process
711 doesn't change horizontal positions.](img/a-after-autohinting.png)
717 In ttfautohint terminology, a *hint set* is the *optimal* configuration for
718 a given PPEM (pixel per EM) value.
720 In the range given by the `--hinting-range-min` and `--hinting-range-max`
721 options, ttfautohint creates hint sets for every PPEM value. For each
722 glyph, ttfautohint automatically determines whether a new set should be
723 emitted for a PPEM value if it finds that it differs from a previous one.
724 For some glyphs it is possible that one set covers, say, the range
725 8px-1000px, while other glyphs need 10 or more such sets.
727 In the PPEM range below `--hinting-range-min`, ttfautohint always uses just
728 one set, in the PPEM range between `--hinting-range-max` and
729 `--hinting-limit`, it also uses just one set.
731 One of the hinting configuration parameters is the decision which segments
732 form an edge. For example, let us assume that two segments get aligned on a
733 single horizontal edge at 11px, while two edges are used at 12px. This
734 change makes ttfautohint emit a new hint set to accomodate this situation.
735 The next images illustrate this, using a Cyrillic letter (glyph 'afii10108')
736 from the 'Ubuntu book' font, processed with ttfautohint.
738 ![Before hinting, size 11px.](img/afii10108-11px-before-hinting.png)
740 ![After hinting, size 11px. Segments 43-27-28 and 14-15 are aligned on a
741 single edge, as are segments 26-0-1 and
742 20-21.](img/afii10108-11px-after-hinting.png)
744 ![Before hinting, size 12px.](img/afii10108-12px-before-hinting.png)
746 ![After hinting, size 12px. The segments are not aligned. While
747 segments 43-27-28 and 20-21 now have almost the same horizontal position,
748 they don't form an edge because the outlines passing through the segments
749 point into different directions.](img/afii10108-12px-after-hinting.png)
751 Obviously, the more hint sets get emitted, the larger the bytecode
752 ttfautohint adds to the output font. To find a good value\ *n* for
753 `--hinting-range-max`, some experimentation is necessary since *n* depends
754 on the glyph shapes in the input font. If the value is too low, the hint
755 set created for the PPEM value\ *n* (this hint set gets used for all larger
756 PPEM values) might distort the outlines too much in the PPEM range given
757 by\ *n* and the value set by `--hinting-limit` (at which hinting gets
758 switched off). If the value is too high, the font size increases due to
759 more hint sets without any noticeable hinting effects.
761 Similar arguments hold for `--hinting-range-min` except that there is no
762 lower limit at which hinting is switched off.
764 An example. Let's assume that we have a hinting range 10\ <= ppem <=\ 100,
765 and the hinting limit is set to 250. For a given glyph, ttfautohint finds
766 out that four hint sets must be computed to exactly cover this hinting
767 range: 10-15, 16-40, 41-80, and 81-100. For ppem values below 10ppem, the
768 hint set covering 10-15ppem is used, for ppem values larger than 100 the
769 hint set covering 81-100ppem is used. For ppem values larger than 250, no
770 hinting gets applied.
776 The ttfautohint library (and programs) supports two solutions for handling
777 composite glyphs, to be controlled with [option
778 `--composites`](#hint-composites). This section contains some general
779 information, then covers the case where the option if off, while the next
780 section describes how ttfautohint behaves if this option is activated.
782 Regardless of the `--composites` option, ttfautohint performs a scan over
783 all composite glyphs to assure that components of a composite glyph inherit
784 its style, as described [later](#opentype-features). However, components
785 that are shifted vertically will be skipped. For example, if the glyph
786 'Agrave' uses a shifted 'grave' accent glyph, the accent is ignored. On the
787 other hand, if there is a glyph 'agrave' that uses the same 'grave' glyph
788 vertically unshifted, 'grave' does inherit the style.
790 If `--composites` is off, components are hinted separately, then put
791 together. Separate hinting implies that the current style's blue zones are
792 applied to all subglyphs in its original, unshifted positions.
795 The '\.ttfautohint' Glyph
796 -------------------------
798 If [option `--composites`](#hint-composites) is used, ttfautohint doesn't
799 hint subglyphs of composite glyphs separately. Instead, it hints the whole
800 glyph, this is, composites get recursively expanded internally so that they
801 form simple glyphs, then hints are applied -- this is the normal working
802 mode of FreeType's auto-hinter.
804 One problem, however, must be solved: Hinting for subglyphs (which usually
805 are used as normal glyphs also) must be deactivated so that nothing but the
806 final bytecode of the composite gets executed.
808 The trick used by ttfautohint is to prepend a composite element called
809 '\.ttfautohint', a dummy glyph with a single point, and which has a single
810 job: Its bytecode increases a variable (to be more precise, it is a CVT
811 register called `cvtl_is_subglyph` in the source code), indicating that we
812 are within a composite glyph. The final bytecode of the composite glyph
813 eventually decrements this variable again.
815 As an example, let's consider composite glyph 'Agrave' ('À'), which has the
816 subglyph 'A' as the base and 'grave' as its accent. After processing with
817 ttfautohint it consists of three components: '\.ttfautohint', 'A', and
818 'grave' (in this order).
821 ------------- --------
822 .ttfautohint increase `cvtl_is_subglyph` (now: 1)
823 A do nothing because `cvtl_is_subglyph` > 0
824 grave do nothing because `cvtl_is_subglyph` > 0
825 Agrave decrease `cvtl_is_subglyph` (now: 0)\
826 apply hints because `cvtl_is_subglyph` == 0
828 Some technical details (which you might skip): All glyph point indices get
829 adjusted since each '\.ttfautohint' subglyph shifts all following indices by
830 one. This must be done for both the bytecode and one subformat of
831 OpenType's `GPOS` anchor tables.
833 While this approach works fine on all tested platforms, there is one single
834 drawback: Direct rendering of the '\.ttfautohint' subglyph (this is,
835 rendering as a stand-alone glyph) disables proper hinting of all glyphs in
836 the font! Under normal circumstances this never happens because
837 '\.ttfautohint' doesn't have an entry in the font's `cmap` table. (However,
838 some test and demo programs like FreeType's `ftview` application or other
839 glyph viewers that are able to bypass the `cmap` table might be affected.)
845 In FreeType terminology, a writing system is a set of functions that
846 provides auto-hinting for certain scripts. Right now, only two writing
847 systems from FreeType's auto-hinter are available in ttfautohint: 'dummy'
848 and 'latin'. The former handles the 'no-script' case; details to 'latin'
849 follow in the next section.
855 ttfautohint needs to know which script should be used to hint a specific
856 glyph. To do so, it checks a glyph's Unicode character code whether it
857 belongs to a given script.
859 Here is the hardcoded list of character ranges that are used for scripts in
860 the 'latin' writing system. As you can see, this also covers some non-latin
861 scripts (in the Unicode sense) that have similar typographical properties.
863 In ttfautohint, scripts are identified by four-character tags. The value
864 `none` indicates 'no script'.
867 Table: `latn` character ranges
869 Character range Description
870 --------------------- -------------
871 `0x0020` - `0x007F` Basic Latin (no control characters)
872 `0x00A0` - `0x00FF` Latin-1 Supplement (no control characters)
873 `0x0100` - `0x017F` Latin Extended-A
874 `0x0180` - `0x024F` Latin Extended-B
875 `0x0250` - `0x02AF` IPA Extensions
876 `0x02B0` - `0x02FF` Spacing Modifier Letters
877 `0x0300` - `0x036F` Combining Diacritical Marks
878 `0x1D00` - `0x1D7F` Phonetic Extensions
879 `0x1D80` - `0x1DBF` Phonetic Extensions Supplement
880 `0x1DC0` - `0x1DFF` Combining Diacritical Marks Supplement
881 `0x1E00` - `0x1EFF` Latin Extended Additional
882 `0x2000` - `0x206F` General Punctuation
883 `0x2070` - `0x209F` Superscripts and Subscripts
884 `0x20A0` - `0x20CF` Currency Symbols
885 `0x2150` - `0x218F` Number Forms
886 `0x2460` - `0x24FF` Enclosed Alphanumerics
887 `0x2C60` - `0x2C7F` Latin Extended-C
888 `0x2E00` - `0x2E7F` Supplemental Punctuation
889 `0xA720` - `0xA7FF` Latin Extended-D
890 `0xFB00` - `0xFB06` Alphabetical Presentation Forms (Latin Ligatures)
891 `0x1D400` - `0x1D7FF` Mathematical Alphanumeric Symbols
892 `0x1F100` - `0x1F1FF` Enclosed Alphanumeric Supplement
895 Table: `grek` character ranges
897 Character range Description
898 --------------------- -------------
899 `0x0370` - `0x03FF` Greek and Coptic
900 `0x1F00` - `0x1FFF` Greek Extended
903 Table: `cyrl` character ranges
905 Character range Description
906 --------------------- -------------
907 `0x0400` - `0x04FF` Cyrillic
908 `0x0500` - `0x052F` Cyrillic Supplement
909 `0x2DE0` - `0x2DFF` Cyrillic Extended-A
910 `0xA640` - `0xA69F` Cyrillic Extended-B
913 Table: `hebr` character ranges
915 Character range Description
916 --------------------- -------------
917 `0x0590` - `0x05FF` Hebrew
918 `0xFB1D` - `0xFB4F` Alphabetic Presentation Forms (Hebrew)
921 If a glyph's character code is not covered by a script range, it is not
922 hinted (or rather, it gets hinted by the 'dummy' auto-hinting module that
923 essentially does nothing). This can be changed by specifying a *fallback
924 script*; see [option `--fallback-script`](#fallback-script).
930 (Please read the [OpenType specification] for details on *features*, `GSUB`,
931 and `GPOS` tables, and how they relate to scripts.)
933 For modern OpenType fonts, character ranges are not sufficient to handle
936 * Due to glyph substitution in the font (as specified in a font's `GSUB`
937 table), which handles ligatures and similar typographic features, there
938 is no longer a one-to-one mapping from an input Unicode character to a
939 glyph index. Some ligatures, like 'fi', actually do have Unicode values
940 for historical reasons, but most of them don't. While it is possible to
941 map ligature glyphs into Unicode's Private Use Area (PUA), code values
942 from this area are arbitrary by definition and thus unusable for
945 * Some features like `sups` (for handling superscript) completely change
946 the appearance and even vertical position of the affected glyphs.
947 Obviously, the blue zones for 'normal' glyphs no longer fit, thus the
948 auto-hinter puts them into a separate group (called *style* in FreeType
949 speak), having its own set of blue zones.
952 Table: OpenType features handled specially by ttfautohint
954 Feature tag Description
955 --------------- -------------
956 `c2cp` petite capitals from capitals
957 `c2sc` small capitals from capitals
959 `pcap` petite capitals
960 `sinf` scientific inferiors
961 `smcp` small capitals
967 There are two conditions to get a valid style for a feature in a given
970 1. One of the script's standard characters must be available in the
973 2. The feature must provide characters to form at least one blue zone; see
974 [above](#blue-zones).
976 An additional complication is that features from the above table might use
977 data not only from the `GSUB` but also from the `GPOS` table, containing
978 information for glyph positioning. For example, the `sups` feature for
979 superscripts might use the same glyphs as the `subs` feature for subscripts,
980 simply moved up. ttfautohint skips such vertically shifted glyphs (except
981 for accessing standard characters) because glyph positioning happens after
982 hinting. Continuing our example, the `sups` feature wouldn't form a style,
983 contrary to `subs`, which holds the unshifted glyphs.
985 The remaining OpenType features of a script are not handled specially; the
986 affected glyphs are simply hinted together with the 'normal' glyphs of the
989 Note that a font might still contain some features not covered yet: OpenType
990 has the concept of a *default script*; its data gets used for all scripts
991 that aren't explicitly handled in a font. By default, ttfautohint unifies
992 all affected glyphs from default script features with the `latn` script.
993 This can be changed with [option `--default-script`](#default-script), if
997 ttfautohint uses the [HarfBuzz] library for handling OpenType features.
1003 ttfautohint touches almost all SFNT tables within a TrueType or OpenType
1004 font. Note that only OpenType fonts with TrueType outlines are supported.
1005 OpenType fonts with a `CFF` table (this is, with PostScript outlines) won't
1008 * `glyf`: All hints in the table are replaced with new ones. If option
1009 [`--composites`](#hint-composites) is used, one glyph gets added (namely
1010 the '\.ttfautohint' glyph) and all composites get an additional
1013 * `cvt`, `prep`, and `fpgm`: These tables get replaced with data
1014 necessary for the new hinting bytecode.
1016 * `gasp`: Set up to always use grayscale rendering, for all sizes, with
1017 grid-fitting for standard hinting, and symmetric grid-fitting and
1018 symmetric smoothing for horizontal subpixel hinting (ClearType).
1020 * `DSIG`: If it exists, it gets replaced with a dummy version.
1021 ttfautohint can't digitally sign a font; you have to do that afterwards.
1023 * `name`: The 'version' entries are modified to add information about the
1024 parameters that have been used for calling ttfautohint. This can be
1025 controlled with the [`--no-info`](#add-ttfautohint-info) option.
1027 * `GPOS`, `hmtx`, `loca`, `head`, `maxp`, `post`: Updated to fit the
1028 additional '\.ttfautohint' glyph, the additional subglyphs in
1029 composites, and the new hinting bytecode.
1031 * `LTSH`, `hdmx`: Since ttfautohint doesn't do any horizontal hinting,
1032 those tables are superfluous and thus removed.
1034 * `VDMX`: Removed, since it depends on the original bytecode, which
1035 ttfautohint removes. A font editor might recompute the necessary data
1042 ### Interaction With FreeType
1044 Recent versions of FreeType have an experimental extension for handling
1045 subpixel hinting; it is off by default and can be activated by defining the
1046 macro `TT_CONFIG_OPTION_SUBPIXEL_HINTING` at compile time. This code has
1047 been contributed mainly by [Infinality], being a subset of his original
1048 patch. Many GNU/Linux distributions activate this code, or provide packages
1051 This extension changes the behaviour of many bytecode instructions to get
1052 better rendering results. However, not all changes are global; some of them
1053 are specific to certain fonts. For example, it contains font-specific
1054 improvements for the '[DejaVu] Sans' font family. The list of affected
1055 fonts is hard-coded; it can be found in FreeType's source code file
1058 If you are going to process such specially-handled fonts with ttfautohint,
1059 serious rendering problems might show up. Since ttfautohint (intentionally)
1060 doesn't change the font name in the `name` table, the Infinality extension
1061 has no chance to recognize that the hints are different. All such problems
1062 vanish if the font gets renamed in its `name` table (the name of the font
1063 file itself doesn't matter).
1065 ### Incorrect Unicode Character Map
1067 Fonts with an incorrect Unicode `cmap` table will not be properly hinted by
1068 ttfautohint. Especially older fonts do cheat; for example, there exist
1069 Hebrew fonts that map its glyphs to character codes 'A', 'B', etc., to make
1070 them work with non-localized versions of Windows\ 98, say.
1072 Since ttfautohint needs to find both standard and blue zone characters, it
1073 relies on correct Unicode values. If you want to handle such fonts, please
1074 fix their `cmap` tables accordingly.
1076 ### Irregular Glyph Heights
1078 The central concept of ttfautohint's hinting algorithm, as discussed
1079 [above](#segments-and-edges), is to identify horizontal segments at extremum
1080 positions, especially for blue zones. If such a segment is missing, it
1081 cannot be associated with a blue zone, possibly leading to irregular heights
1082 for the particular glyph.
1084 If a font designer is able to adjust the outlines, such problems can be
1085 remedied by adding tiny horizontal segments at the problematic extremum
1086 positions. Such segments should have a horizontal length of at least
1087 20\ font units (assuming 2048 units per EM)^[To be more precise, the sum of
1088 the height and width of a segment must be at least 20 font units, and the
1089 height multiplied by\ 14 must not exceed the length. Thus (19,1) is also a
1090 valid minimum (length,height) pair, while (18,2) isn't. The value\ 20 is
1091 heuristic and hard-coded, as is the value\ 14 (corresponding to a slope of
1096 ttfautohint doesn't handle diagonal lines specially. For thin outlines,
1097 this might lead to strokes that look too thick at smaller sizes. A font
1098 designer might compensate this to a certain amount by slightly reducing the
1099 stroke width of diagonal lines. However, in many cases the sub-optimal
1100 appearance of a stroke with borders that don't exactly fit the pixel grid is
1101 not the outline itself but an incorrect gamma value of the monitor: People
1102 tend to not properly adjust it, and the default values of most operating
1103 systems are too low, causing too much darkening of such strokes. It is thus
1104 of vital importance to compare ttfautohint's results with similar fonts to
1105 exclude any systematic effect not related to the outlines themselves.