File: ttfautohint-1.pandoc

package info (click to toggle)
ttfautohint 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,504 kB
  • ctags: 4,347
  • sloc: ansic: 38,386; sh: 5,749; cpp: 4,131; perl: 340; makefile: 309; sed: 39
file content (1794 lines) | stat: -rw-r--r-- 80,631 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
% ttfautohint
% Werner Lemberg
%

<!--
  Copyright (C) 2011-2016 by Werner Lemberg.

  This file is part of the ttfautohint library, and may only be used,
  modified, and distributed under the terms given in `COPYING'.  By
  continuing to use, modify, or distribute this file you indicate that you
  have read `COPYING' and understand and accept it fully.

  The file `COPYING' mentioned in the previous paragraph is distributed
  with the ttfautohint library.
-->



Introduction
============

**ttfautohint** is a library written in\ C that takes a TrueType font as
the input, removes its bytecode instructions (if any), and returns a new
font where all glyphs are bytecode hinted using the information given by
FreeType's auto-hinting module.  The idea is to provide the excellent
quality of the auto-hinter on platforms that don't use FreeType.

The library has a single API function, `TTF_autohint`, which is described
[below](#the-ttfautohint-api).

Bundled with the library there are two front-end programs, [`ttfautohint`
and `ttfautohintGUI`](#ttfautohint-and-ttfautohintgui), being a command line
program and an application with a Graphics User Interface (GUI),
respectively.


What exactly are hints?
-----------------------

To cite [Wikipedia](http://en.wikipedia.org/wiki/Font_hinting):

> **Font hinting** (also known as **instructing**) is the use of
> mathematical instructions to adjust the display of an outline font so that
> it lines up with a rasterized grid.  At low screen resolutions, hinting is
> critical for producing a clear, legible text.  It can be accompanied by
> antialiasing and (on liquid crystal displays) subpixel rendering for
> further clarity.

and Apple's [TrueType Reference
Manual](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM03/Chap3.html#features):

> For optimal results, a font instructor should follow these guidelines:
>
>  - At small sizes, chance effects should not be allowed to magnify small
>    differences in the original outline design of a glyph.
>
>  - At large sizes, the subtlety of the original design should emerge.

In general, there are three possible ways to hint a glyph.

 1. The font contains hints (in the original sense of this word) to guide
    the rasterizer, telling it which shapes of the glyphs need special
    consideration.  The hinting logic is partly in the font and partly in
    the rasterizer.  More sophisticated rasterizers are able to produce
    better rendering results.

    This is how Type\ 1 and CFF hints work.

 2. The font contains exact instructions (also called *bytecode*) on how to
    move the points of its outlines, depending on the resolution of the
    output device, and which intentionally distort the (outline) shape to
    produce a well-rasterized result.  The hinting logic is in the font;
    ideally, all rasterizers simply process these instructions to get the
    same result on all platforms.

    This is how TrueType hints work.

 3. The font gets auto-hinted (at run-time).  The hinting logic is
    completely in the rasterizer.  No hints in the font are used or needed;
    instead, the rasterizer scans and analyzes the glyphs to apply
    corrections by itself.

    This is how FreeType's auto-hinter works; see
    [below](#background-and-technical-details) for more.


What problems can arise with TrueType hinting?
----------------------------------------------

While it is relatively easy to specify PostScript hints (either manually or
by an auto-hinter that works at font creation time), creating TrueType
hints is far more difficult.  There are at least two reasons:

  - TrueType instructions form a programming language, operating at a very
    low level.  They are comparable to assembler code, thus lacking all
    high-level concepts to make programming more comfortable.

    Here an example how such code looks like:

    ```
        SVTCA[0]
        PUSHB[ ]  /* 3 values pushed */
        18 1 0
        CALL[ ]
        PUSHB[ ]  /* 2 values pushed */
        15 4
        MIRP[01001]
        PUSHB[ ]  /* 3 values pushed */
        7 3 0
        CALL[ ]
    ```

    Another major obstacle is the fact that font designers usually aren't
    programmers.

  - It is very time consuming to manually hint glyphs.  Given that the
    number of specialists for TrueType hinting is very limited, hinting a
    large set of glyphs for a font or font family can become very expensive.


Why ttfautohint?
----------------

The ttfautohint library brings the excellent quality of FreeType rendering
to platforms that don't use FreeType, yet require hinting for text to look
good -- like Microsoft Windows.  Roughly speaking, it converts the glyph
analysis done by FreeType's auto-hinting module to TrueType bytecode.
Internally, the auto-hinter's algorithm resembles PostScript hinting
methods; it thus combines all three hinting methods discussed
[previously](#what-exactly-are-hints).

The simple interface of the front-ends (both on the command line and with
the GUI) allows quick hinting of a whole font with a few mouse clicks or a
single command on the prompt.  As a result, you get better rendering results
with web browsers, for example.

Across Windows rendering environments today, fonts processed with
ttfautohint look best with ClearType enabled.  This is the default for
Windows\ 7.  Good visual results are also seen in recent MacOS\ X versions
and GNU/Linux systems (including Android, ChromeOS, and other mobile
operating systems) that use FreeType for rendering glyphs.

The goal of the project is to generate a 'first pass' of hinting that font
developers can refine further for ultimate quality.


'Smooth' hinting
----------------

Fundamentally, there are two approaches to hinting. The older approach,
let's call it 'sharp', popular when text was rendered in pure
black-and-white, was to make all stems round to full pixels so that in a
text line, all stems would be either one pixel or (at a larger point size)
two pixels.  When grayscale antialiasing came about, this approach actually
started harming the rendering rather than helping it, because the horizontal
and vertical stems would render very dark but round or diagonal stems would
render very light.

So a new approach was developed, let's call it 'fuzzy', where all stems and
other elements are equalized so that in grayscale (or ClearType) rendering,
they all are of roughly equal color.  This means that stems are not rounded
to full pixels but in fact to fractions of a pixel.  However, with
black-and-white renderers, this approach yields poor results because in
black-and-white you cannot render a fraction of a pixel, so some stems
become one pixel and some become two.

The TrueType auto-hinters in [FontForge] and [FontLab Studio], to name two
well-known font editors, take the 'sharp' approach, while the TrueType
auto-hinter in ttfautohint takes the 'fuzzy' approach.

In theory, a hybrid approach is possible, using TrueType conditional hints:
If the rasterizer is black-and-white, 'sharp' rendering could happen, while
if the rasterizer is ClearType, the 'fuzzy' rendering could be used.  It is
not intended to add black-and-white auto-hinting to ttfautohint.  However,
it is planned to develop an interface so that ttfautohint can cooperate with
font editors, providing this hybrid hinting.



`ttfautohint` and `ttfautohintGUI`
==================================

On all supported platforms (GNU/Linux, Windows, and Mac OS\ X), the GUI
looks quite similar; the used toolkit is [Qt], which in turn uses the
platform's native widgets.

![`ttfautohintGUI` on GNU/Linux running KDE](img/ttfautohintGUI.png)

Both the GUI and console version share the same features, to be discussed in
the next subsection.

**Warning: ttfautohint cannot always process a font a second time.**
If the font contains composite glyphs, and option [`-c`](#hint-composites)
is used, reprocessing with ttfautohint will fail.  For this reason it is
strongly recommended to *not* delete the original, unhinted font so that you
can always rerun ttfautohint.


Calling `ttfautohint`
---------------------

```
    ttfautohint [OPTION]... [IN-FILE [OUT-FILE]]
```

The command-line binary, `ttfautohint`, works like a Unix filter, this is,
it reads data from standard input if no input file name is given, and it
sends its output to standard output if no output file name is specified.

A typical call looks like the following.

```
    ttfautohint -v -f latn foo.ttf foo-autohinted.ttf
```

For demonstration purposes, here the same using a pipe and redirection.
Note that Windows's default command line interpreter, `cmd.exe`, doesn't
support piping with binary files, unfortunately.

```
    cat foo.ttf | ttfautohint -v -f latn > foo-autohinted.ttf
```


Calling `ttfautohintGUI`
------------------------

```
    ttfautohintGUI [OPTION]...
```

`ttfautohintGUI` doesn't send any output to a console; however, it accepts
(almost) the same command line options as `ttfautohint`, setting default
values for the GUI.

The following command line options are not available in `ttfautohintGUI`;
however, the corresponding functionality can be selected interactively:
[`--control-file`](#control-instructions-file),
[`--reference`](#blue-zone-reference-font),
[`--reference-index`](#reference-face-index).

Two options, namely `--ttfa-info` and `--debug`, emit information at
standard output and standard error, respectively; they are thus not
available in `ttfautohintGUI` at all.


Options
-------

Long options can be given with one or two dashes, and with and without an
equal sign between option and argument.  This means that the following forms
are acceptable: `-foo=`*bar*, `--foo=`*bar*, `-foo`\ *bar*, and
`--foo`\ *bar*.

Below, the section title refers to the command's label in the GUI (if
applicable), then comes the name of the corresponding long command line
option and its short equivalent, followed by a description.

Background and technical details on the meaning of the various options are
given [afterwards](#background-and-technical-details).

### Control Instructions File

`--control-file=`*file*, `-m`\ *file*
:   Specify the name of a control instructions file to manually tweak the
    hinting process.  This feature can be used to correct glitches in
    ttfautohint's hinting algorithm.  The syntax used in a control
    instructions file is given [below](#control-instructions).

    `ttfautohintGUI` doesn't have this command line option.

### Blue Zone Reference Font

`--reference=`*file*, `-R`\ *file*
:   Derive all blue zones from the given font, which can either be a normal
    TrueType font or a TrueType collection – for the latter you can select
    the face index with a [separate option](#reference-face-index).

    Use this to harmonize font families, avoiding ugly height differences at
    small sizes.

    ![Fira Regular and Bold (version 4.106), auto-hinted with ttfautohint
    and displayed at 16px using Internet Explorer\ 11 under Windows\ 8.1.
    The bold series shown on the right side uses the regular variant as the
    reference font.](img/fira-16px-ie11-win81.png)

    To make this work the reference font must obviously be similar enough to
    the font to be hinted; in particular, it must have proper blue zone
    characters so that ttfautohint can derive blue zones at all.

    `ttfautohintGUI` doesn't have this command line option.

### Hint Set Range Minimum, Hint Set Range Maximum

See '[Hint Sets](#hint-sets)' for a definition and explanation.

`--hinting-range-min=`*n*, `-l`\ *n*
:   The minimum PPEM value (in pixels) at which hint sets are created.  The
    default value for *n* is\ 8.

`--hinting-range-max=`*n*, `-r`\ *n*
:   The maximum PPEM value (in pixels) at which hint sets are created.  The
    default value for *n* is 50.

Increasing the range given by `-l` and `-r` normally makes the font's
bytecode larger.

### Default Script

`--default-script=`*s*, `-D`\ *s*
:   Set default script to tag *s*, which is a string consisting of four
    lowercase characters like `latn` or `dflt`.  It is needed to specify the
    OpenType default script: After applying all features that are handled
    specially (like small caps or superscript), ttfautohint uses this value
    for the remaining features.  The default value is `latn`.  See
    [below](#opentype-features) for more details.

### Fallback Script

`--fallback-script=`*s*, `-f`\ *s*
:   Set fallback script to tag *s*, which is a string consisting of four
    characters like `latn` or `dflt`.  It gets used for for all glyphs that
    can't be assigned to a script automatically.  The default value is
    `none`.  See [below](#scripts) for more details.

`--fallback-scaling`, `-S`
:   Use scaling for glyphs covered by the fallback script, not hinting.  See
    [below](#scripts) for more details.

### Hinting Limit

`--hinting-limit=`*n*, `-G`\ *n*
:   The *hinting limit* is the PPEM value (in pixels) where hinting gets
    switched off (using the `INSTCTRL` bytecode instruction, not the `gasp`
    table data); it does not influence the file size.  The default value for
    *n* is 200, which means that the font is not hinted for PPEM values
    larger than 200.

    Note that hinting in the range 'hinting-range-max' up to 'hinting-limit'
    uses the hinting configuration for 'hinting-range-max'.

    To omit a hinting limit, use `--hinting-limit=0` (or check the 'No
    Hinting Limit' box in the GUI).  Since this causes internal math
    overflow in the rasterizer for large pixel values (>\ 1500px approx.) it
    is strongly recommended to not use this except for testing purposes.

### x Height Increase Limit

`--increase-x-height=`*n*, `-x`\ *n*
:   Normally, ttfautohint rounds the x\ height to the pixel grid, with a
    slight preference for rounding up (to use the terminology of TrueType's
    'Super Round' bytecode instruction, the threshold is 5/8px).  If this
    flag is set, values in the range 6\ PPEM to *n*\ PPEM are much more
    often rounded up (setting the threshold to 13/16px).  The default value
    for *n* is 14.  Use this flag to increase the legibility of small sizes
    if necessary; you might get weird rendering results otherwise for glyphs
    like 'a' or 'e', depending on the font design.

    To switch off this feature, use `--increase-x-height=0` (or check the
    'No x\ Height Increase' box in the GUI).  To switch off rounding the
    x\ height to the pixel grid in general, either partially or completely,
    see '[x Height Snapping Exceptions](#x-height-snapping-exceptions)'.

    The following FontForge snapshot images use the font '[Mertz
    Bold](https://github.com/vernnobile/mertzFont/tree/master/FINAL/Mertz-Bold)'
    from Vernon Adams.

    ![At 17px, without option `-x` and '`-w ""`', the hole in glyph 'e'
      looks very grey in the FontForge snapshot, and the GDI ClearType
      rendering (which is the default on older Windows versions) fills it
      completely with black because it uses B/W rendering along the y\ axis.
      FreeType's 'light' autohint mode (which corresponds to ttfautohint's
      'smooth' stem width algorithm) intentionally aligns horizontal lines
      to non-integer (but still discrete) values to avoid large glyph shape
      distortions.](img/e-17px-x14.png)

    ![The same, this time with option `-x 17` (and
      '`-w ""`').](img/e-17px-x17.png)

### x Height Snapping Exceptions

`--x-height-snapping-exceptions=`*string*, `-X`\ *string*
:   A list of comma separated PPEM values or value ranges at which no
    x\ height snapping shall be applied.  A value range has the form
    *value*~1~`-`*value*~2~, meaning *value*~1~\ <= PPEM <=\ *value*~2~.
    *value*~1~ or *value*~2~ (or both) can be missing; a missing value is
    replaced by the beginning or end of the whole interval of valid PPEM
    values, respectively (6\ to 32767).  Whitespace is not significant;
    superfluous commas are ignored, and ranges must be specified in
    increasing order.  For example, the string `"7-9, 11, 13-"` means the
    values 7, 8, 9, 11, 13, 14, 15, etc.  Consequently, if the supplied
    argument is `"-"`, no x\ height snapping takes place at all.  The
    default is the empty string (`""`), meaning no snapping exceptions.

    Normally, x\ height snapping means a slight increase in the overall
    vertical glyph size so that the height of lowercase glyphs gets aligned
    to the pixel grid (this is a global feature, affecting *all* glyphs of a
    font).  However, having larger vertical glyph sizes is not always
    desired, especially if it is not possible to adjust the `usWinAscent`
    and `usWinDescent` values from the font's `OS/2` table so that they are
    not too tight.  See '[Windows Compatibility](#windows-compatibility)'
    for more details.

### Fallback Stem Width

`--fallback-stem-width=`*n*, `-H`\ *n*
:   Set the horizontal stem width (hinting) value for all scripts that lack
    proper standard characters in the font.  The value is given in font
    units and must be a positive integer.  If not set, ttfautohint uses a
    hard-coded default (50\ units at 2048 units per EM, and linearly scaled
    for other UPEM values, for example 24\ units at 1000 UPEM).

    For symbol fonts, you need option `--fallback-script` too (to set up a
    script at all).

    In the GUI, uncheck the 'Default Fallback Stem Width' box to activate
    this feature.

### Windows Compatibility

`--windows-compatibility`, `-W`
:   This option makes ttfautohint add two artificial blue zones, positioned
    at the `usWinAscent` and `usWinDescent` values (from the font's `OS/2`
    table).  The idea is to help ttfautohint so that the hinted glyphs stay
    within this horizontal stripe since Windows clips everything falling
    outside.

    There is a general problem with tight values for `usWinAscent` and
    `usWinDescent`; a good description is given in the [Vertical Metrics
    How-To](http://typophile.com/node/13081).  Additionally, there is a
    special problem with tight values if used in combination with
    ttfautohint because the auto-hinter tends to slightly increase the
    vertical glyph dimensions at smaller sizes to improve legibility.  This
    enlargement can make the heights and depths of glyphs exceed the range
    given by `usWinAscent` and `usWinDescent`.

    If ttfautohint is part of the font creation tool chain, and the font
    designer can adjust those two values, a better solution instead of using
    option `-W` is to reserve some vertical space for 'padding': For the
    auto-hinter, the difference between a top or bottom outline point before
    and after hinting is less than 1px, thus a vertical padding of 2px is
    sufficient.  Assuming a minimum hinting size of 6ppem, adding two pixels
    gives an increase factor of 8÷6 = 1.33.  This is near to the default
    baseline-to-baseline distance used by TeX and other sophisticated text
    processing applications, namely 1.2×designsize, which gives satisfying
    results in most cases.  It is also near to the factor 1.25 recommended
    in the abovementioned how-to.  For example, if the vertical extension of
    the largest glyph is 2000 units (assuming that it approximately
    represents the designsize), the sum of `usWinAscent` and `usWinDescent`
    could be 1.25×2000 = 2500.

    In case ttfautohint is used as an auto-hinting tool for fonts that can
    be no longer modified to change the metrics, option `-W` in combination
    with '`-X "-"`' to suppress any vertical enlargement should prevent
    almost all clipping.

### Adjust Subglyphs

`--adjust-subglyphs`, `-p`
:   *Adjusting subglyphs* makes a font's original bytecode be applied to all
    glyphs before it is replaced with bytecode created by ttfautohint.  This
    makes only sense if your font already has some hints in it that modify
    the shape even at EM size (normally 2048px); in particular, some CJK
    fonts need this because the bytecode is used to scale and shift
    subglyphs (hence the option's long name).  For most fonts, however, this
    is not the case.

### Hint Composites

`--composites`, `-c`
:   By default, the components of a composite glyph get hinted separately.
    If this flag is set, the composite glyph itself gets hinted (and the
    hints of the components are ignored).  Using this flag increases the
    bytecode size a lot, however, it might yield better hinting results.

    If this option is used (and a font actually contains composite glyphs),
    ttfautohint currently cannot reprocess its own output for technical
    reasons, see [below](#the-.ttfautohint-glyph).

### Symbol Font

`--symbol`, `-s`
:   Process a font that ttfautohint would refuse otherwise because it can't
    find a single standard character for any of the supported scripts.

    For all scripts that lack proper standard characters, ttfautohint uses a
    default (hinting) value for the standard stem width instead of deriving
    it from a script's set of standard characters (for the latin script, one
    of them is character 'o').

    Use this option (usually in combination with the
    [`--fallback-script`](#fallback-script) and/or
    [`--fallback-stem-width`](#fallback-stem-width) option) to hint symbol
    or dingbat fonts or math glyphs, for example.

### Dehint

`--dehint`, `-d`
:   Strip off all hints without generating new hints.  Consequently, all
    other hinting options are ignored.  This option is intended for testing
    purposes.

### ttfautohint Info

`--no-info`, `-n`
:   Don't add ttfautohint version and command line information to the
    version string or strings (with name ID\ 5) in the font's `name` table.
    In the GUI, it corresponds to value 'None' in the 'ttfautohint
    info' combo box.

    This option is mutually exclusive with option `-I`.

`--detailed-info`, `-I`
:   Add ttfautohint version and command line information to the version
    string or strings (with name ID\ 5) in the font's `name` table.  In the
    GUI, it corresponds to value 'Version and Parameters' in the
    'ttfautohint info' combo box.

    This option is mutually exclusive with option `-n`.

If neither `-n` nor `-I` is set, the string '`ttfautohint (vNNN)`' gets
added to the `name` table (with *NNN* the current version); this correponds
to value 'Version' in the 'ttfautohint info' combo box.

### Add TTFA Info Table

`--ttfa-table`, `-t`
:   Add an SFNT table called `TTFA` to the output font that holds a dump of
    all parameters; the data resembles the format of the `--debug` option's
    parameter listing.  In particular, it lists all ttfautohint control
    instructions (which are *not* shown in the `name` table info).  This
    option is mainly for archival purposes so that all information used to
    create a font is stored in the font itself.  Note that such a `TTFA`
    table gets ignored by all TrueType rendering engines.

    Forthcoming versions of the ttfautohint front-ends will be able to use
    this data so that a font can be processed another time with exactly the
    same parameters, thus providing a means for round-tripping fonts.

### Family Suffix

`--family-suffix=`*string*, `-F`\ *string*
:   A string that gets appended to the family name in entries with IDs 1, 4,
    6, 16, and\ 21 in the font's `name` table.  Allowed input is ASCII in
    the range 0x20-0x7E except characters `%()/<>[]{}`.

    Assuming an input family name 'Foo', a full name 'Foo Bold', and a
    family suffix '\ 1', the output family name will be 'Foo 1' and the
    full name 'Foo 1 Bold'.  For the PostScript name in ID\ 6, ttfautohint
    uses the suffix with space characters removed (for example 'Foo1Bold').

    This option is mainly for testing purposes, enabling the operating
    system to simultaneously display several instances of a font that are
    processed with different ttfautohint parameters.

### Reference Face Index

`--reference-index=`*n*, `-Z`\ *n*
:   Set the face index for the [blue zone reference
    font](#blue-zone-reference-font) if the font is a TrueType collection
    (`.ttc`).  For normal TrueType fonts, the value is always zero (which is
    also the default).

    `ttfautohintGUI` doesn't have this command line option.

### Strong Stem Width and Positioning

`--strong-stem-width=`*string*, `-w`\ *string*
:   ttfautohint offers two different routines to handle (horizontal) stem
    widths and stem positions: 'smooth' and 'strong'.  The former uses
    discrete values that slightly increase the stem contrast with almost no
    distortion of the outlines, while the latter snaps both stem widths and
    stem positions to integer pixel values as much as possible, yielding a
    crisper appearance at the cost of much more distortion.

    These two routines are mapped onto three possible rendering targets:

    - grayscale rendering, with or without optimization for subpixel
      positioning (e.g. Android)

    - 'GDI ClearType' rendering: the rasterizer version, as returned by the
      GETINFO bytecode instruction, is in the range 36\ <= version <\ 38 and
      ClearType is enabled (e.g. Windows XP)

    - 'DirectWrite ClearType' rendering: the rasterizer version, as returned
      by the GETINFO bytecode instruction, is >=\ 38, ClearType is enabled,
      and subpixel positioning is enabled also (e.g. Internet Explorer\ 9
      running on Windows\ 7)

    GDI ClearType uses a mode similar to B/W rendering along the vertical
    axis, while DW ClearType applies grayscale rendering.  Additionally,
    only DW ClearType provides subpixel positioning along the x\ axis.  For
    what it's worth, the rasterizers version\ 36 and version\ 38 in
    Microsoft Windows are two completely different rendering engines.

    The command line option expects *string* to contain up to three letters
    with possible values '`g`' for grayscale, '`G`' for GDI ClearType, and
    '`D`' for DW ClearType.  If a letter is found in *string*, the strong
    stem width routine is used for the corresponding rendering target (and
    smooth stem width handling otherwise).  The default value is '`G`', which
    means that strong stem width handling is activated for GDI ClearType
    only.  To use smooth stem width handling for all three rendering
    targets, use the empty string as an argument, usually connoted with
    '`""`'.

    In the GUI, simply set the corresponding check box to select the strong
    width routine for a given rendering target.  If you unset the check box,
    the smooth width routine gets used.

    The following images again use the font 'Mertz Bold'.

    ![The left part shows the glyph 'g' unhinted at 26px, the right part
     with hints, using the 'smooth' stem algorithm.](img/ff-g-26px.png)

    ![The same, but this time using the 'strong'
     algorithm.  Note how the stems are aligned to the pixel
     grid.](img/ff-g-26px-wD.png)

### Miscellaneous

Watch input files\ \ \ (`ttfautohintGUI` only)
:   If this checkbox is set, automatically regenerate the output file as
    soon as an input file (either the font, the control instructions file,
    or the reference font) gets modified.

    Pressing the 'Run' button starts watching.  If an error occurs, watching
    stops and must be restarted with the 'Run' button.

`--ignore-restrictions`, `-i`
:   By default, fonts that have bit\ 1 set in the 'fsType' field of the
    `OS/2` table are rejected.  If you have a permission of the font's legal
    owner to modify the font, specify this command line option.

    If this option is not set, `ttfautohintGUI` shows a dialogue to handle
    such fonts if necessary.

`--help`, `-h`
:   On the console, print a brief documentation on standard output and exit.
    This doesn't work with `ttfautohintGUI` on MS Windows.

`--version`, `-v`
:   On the console, print version information on standard output and exit.
    This doesn't work with `ttfautohintGUI` on MS Windows.

`--ttfa-info`, `-T`\ \ \ (not in `ttfautohintGUI`)
:   Print [`TTFA` table](#add-ttfa-info-table) of the input font on standard
    output if present, then exit.

`--debug`\ \ \ (not in `ttfautohintGUI`)
:   Print *a lot* of debugging information on standard error while
    processing a font (you should redirect stderr to a file).

    To reduce the amount of debug data it is recommended to restrict the
    hinting process to a single PPEM value, e.g.,

    ```
       ttfautohint --debug -l 15 -r 15 ... > debug.txt 2>&1
    ```



Background and Technical Details
================================

[Real-Time Grid Fitting of Typographic
Outlines](http://www.tug.org/TUGboat/tb24-3/lemberg.pdf) is a scholarly
paper that describes FreeType's auto-hinter in some detail.  Regarding the
described data structures it is slightly out of date, but the algorithm
itself hasn't changed in general.

The next few subsections are mainly based on this article, introducing some
important concepts.  Note that ttfautohint only does hinting along the
vertical direction (modifying y\ coordinates only).


Segments and Edges
------------------

A glyph consists of one or more *contours* (this is, closed curves).  For
example, glyph 'O' consists of two contours, while glyph 'I' has only one.

![The letter 'O' has two contours, an inner and an outer one, while letter
  'I' has only an outer contour.](img/o-and-i)

A *segment* is a series of consecutive points of a contour (including its
Bézier control points) that are approximately aligned along a coordinate
axis.  A segment has one of three possible directions: left, right, or none
(which means neither left nor right), derived from the TrueType outline
directions.  ttfautohint itself creates segments that contain at least two
points.  Using control instructions, however, it is possible to create
one-point segments, which are useful for fine-tuning the hinting process.

![A serif.  Contour and control points are represented by squares and
  circles, respectively.  The bottom 'line' DE is approximately aligned
  along the horizontal axis, thus it forms a segment of 7\ points.  Together
  with the two other horizontal segments, BC and FG, they form two edges
  (BC+FG, DE).](img/segment-edge)

An *edge* corresponds to a single coordinate value (allowing for a small
threshold) on the main dimension that collects one or more segments, all
pointing into the same direction (either left or right, all others are
ignored).  While finding segments is done on the unscaled outline, finding
edges is bound to the device resolution.  See [below](#hint-sets) for an
example.

In general, segments and edges pointing into different directions 'repel'
each other, thus preventing alignment on the same vertical coordinate if
they are near.  Note that this is a simplification, but it should help
understand how to manipulate and/or create segments in control instructions
files.

The analysis to find segments and edges is specific to a writing
system, see [below](#writing-systems).


Feature Analysis
----------------

The auto-hinter analyzes a font in two steps.  Right now, everything
described here happens for the horizontal axis only, providing vertical
hinting.

  * Global Analysis

    This affects the hinting of all glyphs, trying to give them a uniform
    appearance.

      + Compute standard horizontal stem width of the font.  The value
        is normally taken from glyphs that resemble letter 'o'.

      + Compute blue zones, see [below](#blue-zones).

    If the stem widths of single glyphs differ by a large value, or if
    ttfautohint fails to find proper blue zones, hinting becomes quite poor,
    possibly leading even to severe shape distortions.


Table: script-specific standard characters of the 'latin' writing system

    Script    Standard characters
  ----------  ---------------------
  `arab`      'ـ', U+0640, ARABIC TATWEEL
              'ل', U+0644, ARABIC LETTER LAM
              'ح', U+062D, ARABIC LETTER HAH
  `armn`      'օ', U+0585, ARMENIAN SMALL LETTER OH
              'Օ', U+0555, ARMENIAN CAPITAL LETTER OH
  `beng`      '০', U+09E6, BENGALI DIGIT ZERO
              '৪', U+09EA, BENGALI DIGIT FOUR
  `cyrl`      'о', U+043E, CYRILLIC SMALL LETTER O
              'О', U+041E, CYRILLIC CAPITAL LETTER O
  `cher`      'Ꭴ', U+13A4, CHEROKEE LETTER U
              'Ꮕ', U+13C5, CHEROKEE LETTER NV
              'ꮕ', U+AB95, CHEROKEE SMALL LETTER NV
  `deva`      'ठ', U+0920, DEVANAGARI LETTER TTHA
              'व', U+0935, DEVANAGARI LETTER VA
              'ट', U+091F, DEVANAGARI LETTER TTA
  `ethi`      'ዐ', U+12D0, ETHIOPIC SYLLABLE PHARYNGEAL A
  `geor`      'ი', U+10D8, GEORGIAN LETTER IN
              'ე', U+10D4, GEORGIAN LETTER EN
              'ა', U+10D0, GEORGIAN LETTER AN
  `geok`      'Ⴖ', U+10B6, GEORGIAN CAPITAL LETTER GHAN
              'Ⴑ', U+10B1, GEORGIAN CAPITAL LETTER SAN
              'ⴙ', U+2D19, GEORGIAN SMALL LETTER CHIN
  `grek`      'ο', U+03BF, GREEK SMALL LETTER OMICRON
              'Ο', U+039F, GREEK CAPITAL LETTER OMICRON
  `gujr`      'ટ', U+0A9F, GUJARATI LETTER TTA
              '૦', U+0AE6, GUJARATI DIGIT ZERO
  `guru`      'ਠ', U+0A20, GURMUKHI LETTER TTHA
              'ਰ', U+0A30, GURMUKHI LETTER RA
              '੦', U+0A66, GURMUKHI DIGIT ZERO
  `hebr`      'ם', U+05DD, HEBREW LETTER FINAL MEM
  `knda`      '೦', U+0CE6, KANNADA DIGIT ZERO
              'ಬ', U+0CAC, KANNADA LETTER BA
  `khmr`      '០', U+17E0, KHMER DIGIT ZERO
  `lao`       '໐', U+0ED0, LAO DIGIT ZERO
  `latn`      'o', U+006F, LATIN SMALL LETTER O
              'O', U+004F, LATIN CAPITAL LETTER O
              '0', U+0030, DIGIT ZERO
  `mlym`      'ഠ', U+0D20, MALAYALAM LETTER TTHA
              'റ', U+0D31, MALAYALAM LETTER RRA
  `mymr`      'ဝ', U+101D, MYANMAR LETTER WA
              'င', U+1004, MYANMAR LETTER NGA
              'ဂ', U+1002, MYANMAR LETTER GA
  `sinh`      'ට', U+0DA7, SINHALA LETTER ALPAPRAANA TTAYANNA
  `taml`      '௦', U+0BE6, TAMIL DIGIT ZERO
  `telu`      '౦', U+0C66, TELUGU DIGIT ZERO
              '౧', U+0C67, TELUGU DIGIT ONE
  `thai`      'า', U+0E32, THAI CHARACTER SARA AA
              'ๅ', U+0E45, THAI CHARACTER LAKKHANGYAO
              '๐', U+0E50, THAI DIGIT ZERO


Table: standard characters of the 'latin' writing system, special scripts

    Script    Standard characters
  ----------  ---------------------
  `khms`      '᧡', U+19E1, KHMER SYMBOL MUOY KOET
              '᧪', U+19EA, KHMER SYMBOL DAP KOET
  `latb`      'ₒ', U+2092, LATIN SUBSCRIPT SMALL LETTER O
              '₀', U+2080, SUBSCRIPT ZERO
  `latp`      'ᵒ', U+1D52, MODIFIER LETTER SMALL O
              'ᴼ', U+1D3C, MODIFIER LETTER CAPITAL O
              '⁰', U+2070, SUPERSCRIPT ZERO


  * Glyph Analysis

    This is a per-glyph operation.

      + Find segments and edges.

      + Link edges together to find stems and serifs.  The abovementioned
        paper gives more details on what exactly constitutes a stem or a
        serif and how the algorithm works.


Blue Zones
----------

![Two blue zones relevant to the glyph 'a'.  Vertical point coordinates of
  *all* glyphs within these zones are aligned, provided the blue zone is
  active (this is, its vertical size is smaller than
  3/4\ pixels).](img/blue-zones)

Outlines of certain characters are used to determine *blue zones*.  This
concept is the same as with Type\ 1 fonts: All glyph points that lie in
certain small horizontal zones get aligned vertically.

Here a series of tables that show the blue zone characters of the latin
writing system's available scripts; the values are hard-coded in the source
code.  Since the auto-hinter takes mean values it is not necessary that all
characters of a zone are present.

'Round' characters in blue zones (e.g., the top and bottom of 'O' or the
bottom of 'g') are used to control overshoot handling.

Blue zones marked with an asterisk are x\ height blue zones, which are
adjusted to be on the pixel grid (to improve rendering at small sizes) by
scaling the remaining blue zones before they are adjusted to the grid.  See
also option [`--increase-x-height`](#x-height-increase-limit).


Table: `arab` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of letters with vertical stroke    ا إ ل ك ط ظ
  2     bottom of letters                      ت ث ط ظ ك
  3     glyph joining                          ـ


Table: `armn` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of capital letters                 Ա Մ Ւ Փ Բ Գ Դ Օ
  2     bottom of capital letters              Ւ Ո Փ Ճ Շ Ս Տ Օ
  3     top of ascenders of small letters      ե է ի մ վ փ ֆ փ
  4*    top of small letters                   ա յ ւ ս գ ջ ր օ
  5     bottom of small letters                հ ո ճ ա ե ծ ս օ
  6     bottom of descenders of small letters  բ ը ի լ ղ պ փ ց


Table: `beng` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     baseline (flat glyphs only)            অ ড ত ন ব ভ ল ক
  2     top of ascenders                       ই ট ঠ ি ী ৈ ৗ
  3*    top of baseline                        ও এ ড ত ন ব ল ক
  4     bottom of base characters              অ ড ত ন ব ভ ল ক

Contrary to scripts like latin, the baseline in Bengali is on the top, and
we hint from top to bottom.


Table: `cher` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of capital letters                 Ꮖ Ꮋ Ꭼ Ꮓ Ꭴ Ꮳ Ꭶ Ꮥ
  2     bottom of capital letters              Ꮖ Ꮋ Ꭼ Ꮓ Ꭴ Ꮳ Ꭶ Ꮥ
  3     top of ascenders of small letters      ꮒ ꮤ ꮶ ꭴ ꭾ ꮗ ꮝ ꮿ
  4*    top of small letters                   ꮖ ꭼ ꮓ ꮠ ꮳ ꭶ ꮥ ꮻ
  5     bottom of small letters                ꮖ ꭼ ꮓ ꮠ ꮳ ꭶ ꮥ ꮻ
  6     bottom of descenders of small letters  ᏸ ꮐ ꭹ ꭻ


Table: `cyrl` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of capital letters                 Б В Е П З О С Э
  2     bottom of capital letters              Б В Е Ш З О С Э
  3*    top of small letters                   х п н ш е з о с
  4     bottom of small letters                х п н ш е з о с
  5     bottom of descenders of small letters  р у ф


Table: `deva` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of ascenders                       ई ऐ ओ औ ि ी ो ौ
  2     top of baseline                        क म अ आ थ ध भ श
  3*    top of baseline (flat glyphs only)     क न म उ छ ट ठ ड
  4     bottom of base characters              क न म उ छ ट ठ ड
  5     bottom of descenders                   ु ृ

Contrary to scripts like latin, the baseline in Devanagari is on the top,
and we hint from top to bottom.  Note that some fonts have extreme variation
in the height of the round elements in Zone\ 3; for this reason we also
define Zone\ 1, which must be always present.


Table: `ethi` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of letters                         ሀ ሃ ዘ ፐ ማ በ ዋ ዐ
  2     bottom of letters                      ለ ሐ በ ዘ ሀ ሪ ዐ ጨ


Table: `geok` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of Asomtavruli letters             Ⴑ Ⴇ Ⴙ Ⴜ Ⴄ Ⴅ Ⴓ Ⴚ
  2     bottom of Asomtavruli letters          Ⴄ Ⴅ Ⴇ Ⴈ Ⴆ Ⴑ Ⴊ Ⴋ
  3*    top of Nuskhuri letters                ⴁ ⴗ ⴂ ⴄ ⴅ ⴇ ⴔ ⴖ
  4     bottom of Nuskhuri letters             ⴈ ⴌ ⴖ ⴎ ⴃ ⴆ ⴋ ⴢ
  5     top of ascender Nuskhuri letters       ⴐ ⴑ ⴓ ⴕ ⴙ ⴛ ⴡ ⴣ
  6     bottom of Nuskhuri descender letters   ⴄ ⴅ ⴔ ⴕ ⴁ ⴂ ⴘ ⴝ

Georgian Asomtavruli and Nuskhuri form the old ecclesiastical script,
Khutsuri.  Note that fonts show a great variation in height and depth of
ascender and descender letter forms.


Table: `geor` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1*    top of Mkhedruli letters               გ დ ე ვ თ ი ო ღ
  2     bottom of Mkhedruli letters            ა ზ მ ს შ ძ ხ ჰ
  3     top of ascender Mkhedruli letters      ს ხ ქ ზ მ შ ჩ წ
  4     bottom of descender Mkhedruli letters  ე ვ ჟ ტ უ ფ ქ ყ

Georgian Mkhedruli support is incomplete; it doesn't yet contain characters
for Mtavruli (which are not yet encoded in Unicode), the uppercase glyph
variants of Mkhedruli.


Table: `grek` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of capital letters                 Γ Β Ε Ζ Θ Ο Ω
  2     bottom of capital letters              Β Δ Ζ Ξ Θ Ο
  3     top of 'small beta' like letters       β θ δ ζ λ ξ
  4*    top of small letters                   α ε ι ο π σ τ ω
  5     bottom of small letters                α ε ι ο π σ τ ω
  6     bottom of descenders of small letters  β γ η μ ρ φ χ ψ


Table: `gujr` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1*    top of letters                         ત ન ઋ ઌ છ ટ ર ૦
  2     bottom of letters                      ખ ગ ઘ ઞ ઇ ઈ ઠ જ
  3     top of ascenders                       ઈ ઊ િ ી લી શ્ચિ જિ સી
  4     bottom of descenders                   ુ ૃ ૄ ખુ છૃ છૄ
  5     top of Gujarati digits                 ૦ ૧ ૨ ૩ ૭


Table: `guru` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of ascenders                       ਇ ਈ ਉ ਏ ਓ ੳ ਿ ੀ
  2     top of baseline                        ਕ ਗ ਙ ਚ ਜ ਤ ਧ ਸ
  3*    top of baseline (flat glyphs only)     ਕ ਗ ਙ ਚ ਜ ਤ ਧ ਸ
  4     bottom of characters                   ਅ ਏ ਓ ਗ ਜ ਠ ਰ ਸ
  5     top of Gurmukhi digits                 ੦ ੧ ੨ ੩ ੭


Table: `hebr` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of letters                         ב ד ה ח ך כ ם ס
  2     bottom of letters                      ב ט כ ם ס צ
  3     bottom of descenders of letters        ק ך ן ף ץ


Table: `knda` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of letters                         ಇ ಊ ಐ ಣ ಸಾ ನಾ ದಾ ರಾ
  2     bottom of letters                      ಅ ಉ ಎ ಲ ೦ ೨ ೬ ೭


Table: `khmr` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1*    top of letters                         ខ ទ ន ឧ ឩ ា
  2     top of subscript cluster components    ក្ក ក្ខ ក្គ ក្ថ
  3     bottom of letters                      ខ ឃ ច ឋ ប ម យ ឲ
  4     bottom of descenders                   ត្រ រៀ ឲ្យ អឿ
  5     bottom of large descenders             ន្ត្រៃ ង្ខ្យ ក្បៀ ច្រៀ ន្តឿ ល្បឿ


Table: `khms` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1*    top of symbols for waxing              ᧠ ᧡
  2     bottom of symbols for waning           ᧶ ᧹

Khmer symbols are used for lunar dates.


Table: `lao` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1*    top of letters                         າ ດ ອ ມ ລ ວ ຣ ງ
  2     bottom of letters                      າ ອ ບ ຍ ຣ ຮ ວ ຢ
  3     top of ascenders                       ປ ຢ ຟ ຝ
  4     top of large ascenders                 ໂ ໄ ໃ
  5     bottom of descenders                   ງ ຊ ຖ ຽ ໆ ຯ


Table: `latb` blue zones

  ID    Blue zone                                 Characters
  ----  -----------                               ------------
  1     top of capital characters                 ₀ ₃ ₅ ₇ ₈
  2     bottom of capital characters              ₀ ₁ ₂ ₃ ₈
  3     top of 'small f' like characters          ᵢ ⱼ ₕ ₖ ₗ
  4*    top of small characters                   ₐ ₑ ₒ ₓ ₙ ₛ ᵥ ᵤ ᵣ
  5     bottom of small characters                ₐ ₑ ₒ ₓ ₙ ₛ ᵥ ᵤ ᵣ
  6     bottom of descenders of small characters  ᵦ ᵧ ᵨ ᵩ ₚ

Subscript latin characters are similar to normal latin characters.


Table: `latn` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of capital letters                 T H E Z O C Q S
  2     bottom of capital letters              H E Z L O C U S
  3     top of 'small f' like letters          f i j k d b h
  4*    top of small letters                   x z r o e s c
  5     bottom of small letters                x z r o e s c
  6     bottom of descenders of small letters  p q g j y


Table: `latp` blue zones

  ID    Blue zone                                 Characters
  ----  -----------                               ------------
  1     top of capital characters                 ⁰ ³ ⁵ ⁷ ᵀ ᴴ ᴱ ᴼ
  2     bottom of capital characters              ⁰ ¹ ² ³ ᴱ ᴸ ᴼ ᵁ
  3     top of 'small f' like characters          ᵇ ᵈ ᵏ ʰ ʲ ᶠ ⁱ
  4*    top of small characters                   ᵉ ᵒ ʳ ˢ ˣ ᶜ ᶻ
  5     bottom of small characters                ᵉ ᵒ ʳ ˢ ˣ ᶜ ᶻ
  6     bottom of descenders of small characters  ᵖ ʸ ᵍ

Superscript latin characters are similar to normal latin characters.


Table: `mlym` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of letters                         ഒ ട ഠ റ ച പ ച്ച പ്പ
  2     bottom of letters                      ട ഠ ധ ശ ഘ ച ഥ ല


Table: `mymr` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1*    top of letters                         ခ ဂ င ဒ ဝ ၥ ၊ ။
  2     bottom of letters                      င ဎ ဒ ပ ဗ ဝ ၊ ။
  3     top of ascenders of characters         ဩ ြ ၍ ၏ ၆ ါ ိ
  3     bottom of descenders of letters        ဉ ည ဥ ဩ ဨ ၂ ၅ ၉


Table: `sinh` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of letters                         ඉ ක ඝ ඳ ප ය ල ෆ
  2     bottom of letters                      එ ඔ ඝ ජ ට ථ ධ ර
  3     bottom of descenders of letters        ද ඳ උ ල තූ තු බු දු


Table: `taml` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top of letters                         உ ஒ ஓ ற ஈ க ங ச
  2     bottom of letters                      க ச ல ஶ உ ங ட ப


Table: `telu` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1     top                                    ఇ ఌ ఙ ఞ ణ ఱ ౯
  2     bottom                                 అ క చ ర ఽ ౨ ౬


Table: `thai` blue zones

  ID    Blue zone                              Characters
  ----  -----------                            ------------
  1*    top                                    บ เ แ อ ก า
  2     bottom                                 บ ป ษ ฯ อ ย ฮ
  3     ascender                               ป ฝ ฟ
  4     large ascender                         โ ใ ไ
  5     descender                              ฎ ฏ ฤ ฦ
  6     large descender                        ญ ฐ
  7     top of Thai digits                     ๐ ๑ ๓


![This image shows the relevant glyph terms for vertical blue zone
  positions.](img/glyph-terms)


Grid Fitting
------------

Aligning outlines along the grid lines is called *grid fitting*.  It doesn't
necessarily mean that the outlines are positioned *exactly* on the grid,
however, especially if you want a smooth appearance at different sizes.
This is the central routine of the auto-hinter; its actions are highly
dependent on the used writing system.  Currently, only one writing system is
available (latin), providing support for scripts like Latin or Greek.

  * Align edges linked to blue zones.

  * Fit edges to the pixel grid.

  * Align serif edges.

  * Handle remaining 'strong' points.  Such points are not part of an edge
    but are still important for defining the shape.  This roughly
    corresponds to the `IP` TrueType instruction.

  * Everything else (the 'weak' points) is handled with an 'IUP'
    instruction.

The following images illustrate the hinting process, using glyph 'a' from
the freely available font '[Ubuntu Book](http://font.ubuntu.com)'.  The
manual hints were added by [Dalton Maag Ltd], the used application to create
the hinting debug snapshots was [FontForge].

![Before hinting.](img/a-before-hinting.png)

![After hinting, using manual hints.](img/a-after-hinting.png)

![After hinting, using ttfautohint.  Note that the hinting process
  doesn't change horizontal positions.](img/a-after-autohinting.png)


Hint Sets
---------

In ttfautohint terminology, a *hint set* is the *optimal* configuration for
a given PPEM (pixel per EM) value.

In the range given by the `--hinting-range-min` and `--hinting-range-max`
options, ttfautohint creates hint sets for every PPEM value.  For each
glyph, ttfautohint automatically determines whether a new set should be
emitted for a PPEM value if it finds that it differs from a previous one.
For some glyphs it is possible that one set covers, say, the range
8px-1000px, while other glyphs need 10 or more such sets.

In the PPEM range below `--hinting-range-min`, ttfautohint always uses just
one set, in the PPEM range between `--hinting-range-max` and
`--hinting-limit`, it also uses just one set.

One of the hinting configuration parameters is the decision which segments
form an edge.  For example, let us assume that two segments get aligned on a
single horizontal edge at 11px, while two edges are used at 12px.  This
change makes ttfautohint emit a new hint set to accomodate this situation.
The next images illustrate this, using a Cyrillic letter (glyph 'afii10108')
from the 'Ubuntu book' font, processed with ttfautohint.

![Before hinting, size 11px.](img/afii10108-11px-before-hinting.png)

![After hinting, size 11px.  Segments 43-27-28 and 14-15 are aligned on a
  single edge, as are segments 26-0-1 and
  20-21.](img/afii10108-11px-after-hinting.png)

![Before hinting, size 12px.](img/afii10108-12px-before-hinting.png)

![After hinting, size 12px.  The segments are not aligned.  While
  segments 43-27-28 and 20-21 now have almost the same horizontal position,
  they don't form an edge because the outlines passing through the segments
  point into different directions.](img/afii10108-12px-after-hinting.png)

Obviously, the more hint sets get emitted, the larger the bytecode
ttfautohint adds to the output font.  To find a good value\ *n* for
`--hinting-range-max`, some experimentation is necessary since *n* depends
on the glyph shapes in the input font.  If the value is too low, the hint
set created for the PPEM value\ *n* (this hint set gets used for all larger
PPEM values) might distort the outlines too much in the PPEM range given
by\ *n* and the value set by `--hinting-limit` (at which hinting gets
switched off).  If the value is too high, the font size increases due to
more hint sets without any noticeable hinting effects.

Similar arguments hold for `--hinting-range-min` except that there is no
lower limit at which hinting is switched off.

An example.  Let's assume that we have a hinting range 10\ <= ppem <=\ 100,
and the hinting limit is set to 250.  For a given glyph, ttfautohint finds
out that four hint sets must be computed to exactly cover this hinting
range: 10-15, 16-40, 41-80, and 81-100.  For ppem values below 10ppem, the
hint set covering 10-15ppem is used, for ppem values larger than 100 the
hint set covering 81-100ppem is used.  For ppem values larger than 250, no
hinting gets applied.


Composite Glyphs
----------------

The ttfautohint library (and programs) supports two solutions for handling
composite glyphs, to be controlled with option
[`--composites`](#hint-composites).  This section contains some general
information, then covers the case where the option is off, while the next
section describes how ttfautohint behaves if this option is activated.

Regardless of the `--composites` option, ttfautohint performs a scan over
all composite glyphs to assure that components of a composite glyph inherit
its style, as described [later](#opentype-features).  However, components
that are shifted vertically will be skipped.  For example, if the glyph
'Agrave' uses a shifted 'grave' accent glyph, the accent is ignored.  On the
other hand, if there is a glyph 'agrave' that uses the same 'grave' glyph
vertically unshifted, 'grave' does inherit the style.

If `--composites` is off, components are hinted separately, then put
together.  Separate hinting implies that the current style's blue zones are
applied to all subglyphs in its original, unshifted positions.  In case you
want to shift components vertically, it is *mandatory* to set bit\ 2
(value\ 4), `ROUND_XY_TO_GRID`, in the flag variable of the composite glyph
description to get visually pleasing results, as the images below
demonstrate.

![Here, the subscript glyphs are composites each having a single element
  that is shifted down.  If option `--composites` is not used, subglyphs are
  hinted before they are glued together (possibly applying scaling and
  shifting).  Because the `ROUND_XY_TO_GRID` flag isn't set, the vertical
  translation doesn't align the subglyph to the pixel grid, causing severe
  distortions.](img/composite-no-round-xy-to-grid.png)

![The same as before, but with `ROUND_XY_TO_GRID` set.  Now the subscript
  glyphs look identical to the
  superscripts.](img/composite-round-xy-to-grid.png)

![For comparison purposes, here the result *with* option `--composites` (and
  no `ROUND_XY_TO_GRID`).  The composite glyphs as a whole get hinted;
  consequently, the subscript glyphs get separate blue zones.  At the
  displayed size of 16ppem the vertical positions of the subscript blue
  zones are rounded differently if compared to the superscript zones, thus
  the smaller glyph height.](img/composite-no-round-xy-to-grid-option-c.png)


The '\.ttfautohint' Glyph
-------------------------

If option [`--composites`](#hint-composites) is used, ttfautohint doesn't
hint subglyphs of composite glyphs separately.  Instead, it hints the whole
glyph, this is, composites get recursively expanded internally so that they
form simple glyphs, then hints are applied -- this is the normal working
mode of FreeType's auto-hinter.

One problem, however, must be solved: Hinting for subglyphs (which usually
are used as normal glyphs also) must be deactivated so that nothing but the
final bytecode of the composite gets executed.

The trick used by ttfautohint is to prepend a composite element called
'\.ttfautohint', a dummy glyph with a single point, and which has a single
job: Its bytecode increases a variable (to be more precise, it is a CVT
register called `cvtl_is_subglyph` in the source code), indicating that we
are within a composite glyph.  The final bytecode of the composite glyph
eventually decrements this variable again.

As an example, let's consider composite glyph 'Agrave' ('À'), which has the
subglyph 'A' as the base and 'grave' as its accent.  After processing with
ttfautohint it consists of three components: '\.ttfautohint', 'A', and
'grave' (in this order).

  Bytecode of    Action
  -------------  --------
  .ttfautohint   increase `cvtl_is_subglyph` (now: 1)
  A              do nothing because `cvtl_is_subglyph` > 0
  grave          do nothing because `cvtl_is_subglyph` > 0
  Agrave         decrease `cvtl_is_subglyph` (now: 0)
                 apply hints because `cvtl_is_subglyph` == 0

Some technical details (which you might skip): All glyph point indices get
adjusted since each '\.ttfautohint' subglyph shifts all following indices by
one.  This must be done for both the bytecode and one subformat of
OpenType's `GPOS` anchor tables.

While this approach works fine on all tested platforms, there is one single
drawback: Direct rendering of the '\.ttfautohint' subglyph (this is,
rendering as a stand-alone glyph) disables proper hinting of all glyphs in
the font!  Under normal circumstances this never happens because
'\.ttfautohint' doesn't have an entry in the font's `cmap` table.  (However,
some test and demo programs like FreeType's `ftview` application or other
glyph viewers that are able to bypass the `cmap` table might be affected.)


Writing Systems
---------------

In FreeType terminology, a writing system is a set of functions that
provides auto-hinting for certain scripts.  Right now, only two writing
systems from FreeType's auto-hinter are available in ttfautohint: 'dummy'
and 'latin'.  The former handles the 'no-script' case; details to 'latin'
follow in the next section.


Scripts
-------

ttfautohint needs to know which script should be used to hint a specific
glyph.  To do so, it checks a glyph's Unicode character code whether it
belongs to a given script.

See '[Character Ranges](#character-ranges)' for a complete list of all
handled scripts and its ranges.  This list is auto-generated from a source
code file, covering the 'latin' writing system.  It also covers some
non-latin scripts (in the Unicode sense) that have similar typographical
properties.

In ttfautohint, scripts are identified by four-character tags (if there are
less characters, spaces are appended).  The value `none` indicates 'no
script'.

Each script is represented by two tables to handle 'base' and 'non-base'
characters.  For ttfautohint, a non-base character is something that should
not be affected by blue zones, regardless of whether this is a spacing or
no-spacing glyph.  In other words, non-base characters are hinted using a
script's default stem width without applying blue zones.

Right now, there are two pseudo-scripts that are used as fallbacks: `latb`
and `latp`, used for latin subscript and superscript characters,
respectively.  Its main usage is support of phonetic alphabets like the IPA,
which intermix those characters with normal characters sitting on the
baseline, and which are not specially handled in corresponding OpenType
features like `sups`.

If a glyph's character code is not covered by a script range, it is handled
by a *fallback script*.  By default, the fallback script is `none`, which
indicates handling by the 'latin' writing system without applying
script-specific blue zones (but aligning stems to the grid if possible).
The fallback script can be changed; see option
[`--fallback-script`](#fallback-script).

The user can also select whether uncovered glyphs are either hinted (which
is the default) or scaled only with the fallback script's scaling
parameters.  This can be controlled with option
[`--fallback-scaling`](#fallback-script).  Note that fallback scaling only
makes sense if the fallback script has x\ height blue zones, e.g., `cyrl` or
`latn`.

As a special case, specifying `none` as a fallback script and switching on
fallback scaling ('`-f none -S`'), no hinting is applied at all to uncovered
glyphs – using `none` always implies a scaling factor of\ 1.


OpenType Features
-----------------

(Please read the [OpenType specification] for details on *features*, `GSUB`,
and `GPOS` tables, and how they relate to scripts.)

For modern OpenType fonts, character ranges are not sufficient to handle
scripts.

  * Due to glyph substitution in the font (as specified in a font's `GSUB`
    table), which handles ligatures and similar typographic features, there
    is no longer a one-to-one mapping from an input Unicode character to a
    glyph index.  Some ligatures, like 'fi', actually do have Unicode values
    for historical reasons, but most of them don't.  While it is possible to
    map ligature glyphs into Unicode's Private Use Area (PUA), code values
    from this area are arbitrary by definition and thus unusable for
    ttfautohint.

  * Some features like `sups` (for handling superscript) completely change
    the appearance and even vertical position of the affected glyphs.
    Obviously, the blue zones for 'normal' glyphs no longer fit, thus the
    auto-hinter puts them into a separate group (called *style* in FreeType
    speak), having its own set of blue zones.


Table: OpenType features handled specially by ttfautohint

    Feature tag    Description
  ---------------  -------------
  `c2cp`           petite capitals from capitals
  `c2sc`           small capitals from capitals
  `ordn`           ordinals
  `pcap`           petite capitals
  `sinf`           scientific inferiors
  `smcp`           small capitals
  `subs`           subscript
  `sups`           superscript
  `titl`           titling


There are two conditions to get a valid style for a feature in a given
script.

 1. One of the script's standard characters must be available in the
    feature.

 2. The feature must provide characters to form at least one blue zone; see
    [above](#blue-zones).

An additional complication is that features from the above table might use
data not only from the `GSUB` but also from the `GPOS` table, containing
information for glyph positioning.  For example, the `sups` feature for
superscripts might use the same glyphs as the `subs` feature for subscripts,
simply moved up.  ttfautohint skips such vertically shifted glyphs (except
for accessing standard characters) because glyph positioning happens after
hinting.  Continuing our example, the `sups` feature wouldn't form a style,
contrary to `subs`, which holds the unshifted glyphs.

The remaining OpenType features of a script are not handled specially; the
affected glyphs are simply hinted together with the 'normal' glyphs of the
script.

Note that a font might still contain some features not covered yet: OpenType
has the concept of a *default script*; its data gets used for all scripts
that aren't explicitly handled in a font.  By default, ttfautohint unifies
all affected glyphs from default script features with the `latn` script.
This can be changed with option [`--default-script`](#default-script), if
necessary.


ttfautohint uses the [HarfBuzz] library for handling OpenType features.


SFNT Tables
-----------

ttfautohint touches almost all SFNT tables within a TrueType or OpenType
font.  Note that only OpenType fonts with TrueType outlines are supported.
OpenType fonts with a `CFF` table (this is, with PostScript outlines) won't
work.

  * `glyf`: All hints in the table are replaced with new ones.  If option
    [`--composites`](#hint-composites) is used, one glyph gets added (namely
    the '\.ttfautohint' glyph) and all composites get an additional
    component.

  * `cvt`, `prep`, and `fpgm`: These tables get replaced with data
    necessary for the new hinting bytecode.

  * `gasp`: Set up to always use grayscale rendering, for all sizes, with
    grid-fitting for standard hinting, and symmetric grid-fitting and
    symmetric smoothing for horizontal subpixel hinting (ClearType).

  * `DSIG`: If it exists, it gets replaced with a dummy version.
    ttfautohint can't digitally sign a font; you have to do that afterwards.

  * `name`: The 'version' entries are modified to add information about the
    parameters that have been used for calling ttfautohint.  This can be
    controlled with the [`--no-info`](#ttfautohint-info) option.

  * `GPOS`, `hmtx`, `loca`, `head`, `maxp`, `post`: Updated to fit the
    additional '\.ttfautohint' glyph, the additional subglyphs in
    composites, and the new hinting bytecode.

  * `LTSH`, `hdmx`: Since ttfautohint doesn't do any horizontal hinting,
    those tables are superfluous and thus removed.

  * `VDMX`: Removed, since it depends on the original bytecode, which
    ttfautohint removes.  A font editor might recompute the necessary data
    later on.


Problems
--------

### Interaction With FreeType

Recent versions of FreeType have an experimental extension for handling
subpixel hinting; it is off by default and can be activated by defining the
macro `TT_CONFIG_OPTION_SUBPIXEL_HINTING` at compile time.  This code has
been contributed mainly by [Infinality], being a subset of his original
patch.  Many GNU/Linux distributions activate this code, or provide packages
to activate it.

This extension changes the behaviour of many bytecode instructions to get
better rendering results.  However, not all changes are global; some of them
are specific to certain fonts.  For example, it contains font-specific
improvements for the '[DejaVu] Sans' font family.  The list of affected
fonts is hard-coded; it can be found in FreeType's source code file
`ttsubpix.c`.

If you are going to process such specially-handled fonts with ttfautohint,
serious rendering problems might show up.  Since ttfautohint (intentionally)
doesn't change the font name in the `name` table, the Infinality extension
has no chance to recognize that the hints are different.  All such problems
vanish if the font gets renamed in its `name` table (the name of the font
file itself doesn't matter).

### Incorrect Unicode Character Map

Fonts with an incorrect Unicode `cmap` table will not be properly hinted by
ttfautohint.  Especially older fonts do cheat; for example, there exist
Hebrew fonts that map its glyphs to character codes 'A', 'B', etc., to make
them work with non-localized versions of Windows\ 98, say.

Since ttfautohint needs to find both standard and blue zone characters, it
relies on correct Unicode values.  If you want to handle such fonts, please
fix their `cmap` tables accordingly.

### Irregular Glyph Heights

The central concept of ttfautohint's hinting algorithm, as discussed
[above](#segments-and-edges), is to identify horizontal segments at extremum
positions, especially for blue zones.  If such a segment is missing, it
cannot be associated with a blue zone, possibly leading to irregular heights
for the particular glyph.

Normally, a segment has a horizontal length of at least 20\ font units
(assuming 2048 units per EM)^[To be more precise, the sum of the height and
length of a segment must be at least 20 font units, and the height multiplied
by\ 14 must not exceed the length.  Thus (19,1) is also a valid minimum
(length,height) pair, while (18,2) isn't.  The value\ 20 is heuristic and
hard-coded, as is the value\ 14 (corresponding to a slope of approx.
4.1°).].  Using a [Control Instructions File](#control-instructions-file),
however, it is possible to define additional segments at arbitrary points
that help overcome this restriction, making it possible to fix (most of)
such problems.

### Diagonals

ttfautohint doesn't handle diagonal lines specially.  For thin outlines,
this might lead to strokes that look too thick at smaller sizes.  A font
designer might compensate this to a certain amount by slightly reducing the
stroke width of diagonal lines.  However, in many cases the sub-optimal
appearance of a stroke with borders that don't exactly fit the pixel grid is
not the outline itself but an incorrect gamma value of the monitor: People
tend to not properly adjust it, and the default values of most operating
systems are too low, causing too much darkening of such strokes.  It is thus
of vital importance to compare ttfautohint's results with similar fonts to
exclude any systematic effect not related to the outlines themselves.


Extending ttfautohint with new scripts
--------------------------------------

Right now, adding new scripts to ttfautohint only works on the source code
level, this is, you have to patch the C\ source code.

The process itself isn't very complicated; it is demonstrated best by
example.  The following commits in ttfautohint add Ethiopian and Armenian,
respectively.

| [http://repo.or.cz/ttfautohint.git/commitdiff/d14c7c0758539921b58f2854777175fde1267fb1]([http://repo.or.cz/ttfautohint.git/commitdiff/d14c7c0758539921b58f2854777175fde1267fb1)
| [http://repo.or.cz/ttfautohint.git/commitdiff/b5022cd9635b8b0d3b910310b69f4a57fe055fd0]([http://repo.or.cz/ttfautohint.git/commitdiff/b5022cd9635b8b0d3b910310b69f4a57fe055fd0)

It shows that you have to do the following steps.

  * Add blue zone character data to the file `lib/tablue.dat`.

  * Add the proper Unicode ranges to `lib/taranges.c`, following the
    structure of similar entries.

  * Similarly, the files `lib/tastyles.h` and `lib/ttfautohint-script.h`
    must be updated.  The latter holds the information on the used default
    character or characters; it also references the corresponding script tag
    `HB_SCRIPT_XXX` as used by the HarfBuzz library.

If there are any questions, please contact the [FreeType mailing
list](https://lists.nongnu.org/mailman/listinfo/freetype) for help.  Note
that the script data in ttfautohint are hold in sync with FreeType's
auto-hinter.


Control Instructions
====================

An entry in a control instructions file has various syntax forms, which are
discussed here.  Brackets indicate optional elements.


Common Syntax Elements
----------------------

*font‑idx* gives the index of the font in a TrueType Collection, starting
with value\ 0.  If missing, it is set to zero.  For normal TrueType fonts,
only value zero is valid.  A font index can be specified in decimal, octal,
or hexadecimal format, the latter two indicated by the prefixes `0` and
`0x`, respectively.

*glyph‑id* is either a glyph's name as listed in the `post` SFNT table or a
glyph index.  A glyph name consists of characters from the set
'`A-Za-z0-9._`' only and does not start with a digit or period, with the
exceptions of the names '`.notdef`' and '`.null`'.  A glyph index starts
with value\ 0 can be specified in decimal, octal, or hexadecimal format, the
latter two indicated by the prefixes `0` and `0x`, respectively.  Glyph
names are internally converted to glyph indices.

*points* are number ranges, see '[x Height Snapping
Exceptions](#x-height-snapping-exceptions)' for the syntax.

Similar to the Bourne shell (`sh` or `bash`), a comment starts with
character '`#`'; the rest of the line is ignored.  An empty line is ignored
also.  Both the newline character and '`;`' can be used as a separator
between exception entries.  A trailing '`\`' at the end of a line continues
the current line on the next one.

A control instructions file is parsed line by line; later entries override
earlier entries (in case there is something to override).


Style Adjustments
-----------------

This syntax form makes it possible to override the style assignment
algorithm of ttfautohint; see '[Scripts](#scripts)' and '[OpenType
Features](#opentype-features)' for more details.

> *\[*\ font-idx\ *\]*\ \ script\ \ feature\ \ *`@`*\ \ glyph-ids

*script* is a four-letter name of one of the scripts supported by
ttfautohint.  *feature* is one of the four-letter names of features
supported by ttfautohint.

The elements of *glyph-ids* are a list of comma separated *glyph-id* values
or value ranges.  Note that is not necessary that elements are specified in
increasing order.

Assuming that a font contains superscript digits 'zero.sups' to 'nine.sups'
together with the glyphs 'a.sups' and 'o.sups', use a line

```
    cyrl sups @ zero.sups-nine.sups, a.sups, o.sups
```

to add those glyphs to the style handling Cyrillic superscript glyphs.
However, it is still necessary that the selected script contains proper
[Blue Zone characters](#blue-zones), otherwise those glyphs aren't handled
at all.

Use the `--debug` command line option to see how ttfautohint assigns glyph
indices of a font to styles.


Glyph Adjustments
-----------------

The following syntax forms allows adjustments of a glyph's hinting process.

### Change Direction of Points, Artificial Segments

> *\[*\ font‑idx\ *\]*\ \ glyph‑id\ \ *`l`\[`eft`\]|`r`\[`ight`\]*\ \ points\ \ *\[*\ *`(`*\ left‑offset\ *`,`*\ right‑offset\ *`)`*\ *\]*\

The mutually exclusive parameters `left` and `right` (which can be
abbreviated as '`l`' and '`r`', respectively) indicate that the following
points have left or right 'out' direction, respectively, overriding
ttfautohint's algorithm for setting point directions.  The 'out direction'
of a point is the direction of the outline *leaving* the point (or passing
the control point).  If the specified direction is identical to what
ttfautohint computes, nothing special happens.  Otherwise, a one-point
segment with the specified direction gets created, see
[above](#segments-and-edges).  By default, its length is zero.  Setting
*left‑offset* and *right‑offset*, you can change the segment's horizontal
start and end position relative to the point position.  *left‑offset* and
*right‑offset* are integers measured in font units.

The following five images, displaying glyphs 'O' and 'Q' from the font
[Halant-Regular](http://www.google.com/fonts/specimen/Halant), demonstrate
how to use direction changes.

![The outlines of glyphs 'O' and 'Q', as displayed in FontForge.  They are
  sufficiently similar to expect that ttfautohint hints them equally.
  However, this is not the case.](img/Halant-Regular-O-Q.png)

![The same glyphs, shown at 12px before hinting.  [Please ignore the outline
  distortion in the upper right of glyph 'O'; this is a bug in FontForge
  while running the TrueType
  debugger.]](img/Halant-Regular-O-Q-unhinted-12px.png)

![Using only ttfautohint's '`-w gGD`' parameter to force strong stem width
  and positioning, the hinting of glyph 'Q' is really bad, making the glyph
  vertically two pixels larger!  Reason is that this glyph doesn't contain a
  horizontal segment at the baseline blue zone (*y*\ =\ 1; this corresponds
  to the segment 13-14 in the 'O' glyph).  Normally, segment 1-2 would form
  a 'stem' with the baseline segment (as segment 7-8 does in glyph 'O').
  Instead, it forms a stem with segment 19-20, which gets moved down
  (*y*\ =\ −1) because the whole glyph appears to be
  stretched.](img/Halant-Regular-O-good-Q-badly-hinted-12px.png)

![To fix the problem, we change the direction of point\ 38 to 'left' by
  writing a line '`Q left 38`' (without the quotes) to a control description
  file `Halant-Regular.txt`.  Adding option '`-m Halant-Regular.txt`' to
  ttfautohint, we get the shown image as a result, which is much better:
  Segment 1-2 now properly forms a stem with our artificial one-point
  segment\ 38, and the 'O'-like shape is properly positioned.  However,
  there is still room for improvement: Segment 19-20 is also positioned at
  the baseline, making the connection between the 'O' shape and the tail too
  thin.](img/Halant-Regular-O-good-Q-better-hinted-12px.png)

![By giving the one-point segment\ 38 a horizontal width, we can prevent
  that segment 19-20 gets positioned at the baseline: Replace the line in
  the previous image description with '`Q left 38 (−70,20)`', making the
  segment extend 70 font units to the left and 20 to the right of point\ 38.
  The exact offset values don't matter; it's only important to start left of
  point\ 19.  Another solution to the problem is to artificially change the
  direction of segment 19-20 by adding a second line '`Q right 19-20`' to
  the control instructions file; for our 'Q' glyph, this produces almost
  exactly the same hinting results.  Note that such direction changes only
  influence the hinting process; an outline's direction won't be changed at
  all.](img/Halant-Regular-O-good-Q-well-hinted-12px.png)

### Unset Direction of Points

> *\[*\ font‑idx\ *\]*\ \ glyph‑id\ \ *`n`\[`odir`\]*\ \ points\

Parameter `nodir` (or '`n`') sets the 'out' direction of the following
points to 'no direction', this is, neither left nor right.  If the specified
direction is identical to what ttfautohint computes, nothing special
happens.  Otherwise, ttfautohint no longer considers those points as part of
horizontal segments, thus treating them as ['weak'](#grid-fitting) points.

Modifying or adding segments doesn't directly modify the outlines; it only
influences the hinting process.

### Delta Exceptions

> *\[*\ font‑idx\ *\]*\ \ glyph‑id\ \ *`t`\[`ouch`\]|`p`\[`oint`\]*\ \ points\ \ *\[*\ *`x`\[`shift`\]*\ x‑shift\ *\]*\ \ *\[*\ *`y`\[`shift`\]*\ y‑shift\ *\]*\ \ *`@`*\ \ ppems\

The mutually exclusive parameters `touch` and `point` (which can be
abbreviated as '`t`' and '`p`', respectively) make ttfautohint apply delta
exceptions for the given points, shifting them by the given values.  Delta
exceptions entered with `touch` are applied before the final 'IUP'
(*interpolate untouched points*) instructions in a glyph's bytecode,
exceptions entered with `point` after 'IUP' (please consult Greg Hitchcock's
[ClearType Whitepaper] for more on pre-IUP and post-IUP delta hints).
Additionally, the `touch` parameter makes the bytecode *touch* the affected
points; such points are no longer affected by 'IUP' at all.  Note that in
ClearType mode all deltas along the x\ axis are discarded, and deltas along
the y\ axis are only executed for touched points.  As a consequence,
vertical delta exceptions entered with `point` should not be used in
ClearType mode.^[Unfortunately, there is a bug in FreeType prior to version
2.5.4 (released in December 2014) that completely disables vertical delta
exceptions if subpixel hinting is activated.  For this reason you should
expect that the `touch` parameter fails on older GNU/Linux distributions.]

*ppems*, similar to *points*, are number ranges, see '[x Height Snapping
Exceptions](#x-height-snapping-exceptions)' for the syntax.

*x‑shift* and *y‑shift* represent real numbers that get rounded to multiples
of 1/8 pixels.  The entries for `xshift` ('`x`') and `yshift` ('`y`') are
optional; if missing, the corresponding value is set to zero.  If both
values are zero, the delta exception entry is ignored as a whole.

Values for *x‑shift* and *y‑shift* must be in the range [−1.0;1.0].  Values
for *ppems* must be in the range [6;53].  Values for *points* are limited by
the number of points in the glyph.

Note that only character '`.`' is recognized as a decimal point, and a
thousands separator is not accepted.

As an example for delta instructions, let's assume that you want to shift
points 2, 3, and\ 4 in glyph 'Aacute' at ppem sizes 12 and\ 13 by a vertical
amount of 0.25 pixels.  This corresponds to the line

```
    Aacute  touch 2-4  yshift 0.25  @ 12, 13
```

in a control instructions file.  Since we use `touch` and not `point`,
points 2, 3, and\ 4 are no longer subject to the final 'IUP' instruction,
which interpolates weak, untouched point positions between strong, touched
ones, cf.  the description
[here](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM05/Chap5.html#IUP).