Commit 79e36baebba4532dff92ca1ca43c4dc2f779fd32

Infinality 2012-06-18T10:36:06

[truetype] Support subpixel hinting. This is the large, famous `Infinality' patch to support ClearType bytecode which has been available from http://www.infinality.net/blog/ for some time, and which has been refined over the last years. While still experimental, it is now mature enough to be included directly into FreeType. Most of the code is based on the ClearType whitepaper written by Greg Hitchcock http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx which gives a detailed overview of the necessary changes to the Microsoft rasterizer so that older fonts are supported. However, a lot of details are still missing, and this patches provides a framework to easily handle rendering issues down to the glyph level of certain fonts. Note that ClearType support is not completely implemented! In particular, full support for the options `compatible_widths', `symmetrical_smoothing, and `bgr' (via the GETINFO bytecode instruction) is missing. * src/truetype/ttsubpix.c: New file, providing code to handle `tweaks', this is, rules for certain glyphs in certain fonts (including wildcards) which need a special treatment. * src/truetype/ttsubpix.h: New file, holding the tweaking rules. * include/freetype/config/ftoption.h, src/devel/ftoption.h (TT_CONFIG_OPTION_SUBPIXEL_HINTING): New macro. * include/freetype/internal/ftobjs.h (FT_PIX_FLOOR_GRID, FT_PIX_ROUND_GRID, FT_PIX_CEIL_GRID): New macros. * src/truetype/truetype.c [TT_USE_BYTECODE_INTERPRETER]: Include `ttsubpix.c'. * src/truetype/ttgload.c: Include `ttsubpix.h'. [All changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.] (tt_get_metrics): Set tweak flags. (TT_Hint_Glyph): Call `FT_Outline_EmboldenXY' if necessary. (TT_Process_Simple_Glyph): Compensate emboldening if necessary. (compute_glyph_metrics): Handle `compatible widths' option. (tt_loader_init): Handle ClearType GETINFO information bits. * src/truetype/rules.mk (TT_DRC_SRC): Updated. * src/truetype/ttinterp.c: Include `ttsubpix.h'. [Where necessary, changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.] (Direct_Move, Direct_Move_X): Extended. (Round_None, Round_To_Grid, Round_To_Half_Grid, Round_Down_To_Grid, Round_Up_To_Grid, Round_To_Double_Grid, Round_Super, Round_Super_45, SetSuperRound): Add parameter to handle the number of grid lines per pixel. (SET_SuperRound, ROUND_None, CUR_Func_round): Updated. (DO_SROUND, DOS45ROUND, DO_ODD, DO_EVEN): Updated. (DO_ROUND, DO_NROUND): Updated. (DO_RS): Take care of `Typeman' bytecode patterns. (Ins_FDEF): Add some debugging code. Commented out. (Ins_ENDF): Restore state. (Ins_CALL, Ins_LOOPCALL): Handle inline delta functions. (Ins_MD): Handle `Vacuform' rounds. (Move_Zp2_Point, Ins_SHPIX, Ins_MSIRP, Ins_MDAP, Ins_MIAP, Ins_MDRP, Ins_MIRP): Handle tweaks. (Ins_ALIGNRP): Add tweak guard. (Ins_IUP, Ins_DELTAP): Handle tweaks. (Ins_GETINFO): Handle new ClearType bits. (TT_RunIns): Handle tweaks. * src/truetype/ttinterp.h: Updated. (SPH_TweakRule, SPH_ScaleRule): New structures for tweaks. (TT_ExecContextRec): Add members for subpixel hinting support. * src/truetype/ttobjs.h (TT_DefRecord): Add `inline_delta' member.

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
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
diff --git a/ChangeLog b/ChangeLog
index 23b23d8..4e5f716 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,85 @@
+2012-06-18  Infinality  <infinality@infinality.net>
+
+	[truetype] Support subpixel hinting.
+
+	This is the large, famous `Infinality' patch to support ClearType
+	bytecode which has been available from
+	http://www.infinality.net/blog/ for some time, and which has been
+	refined over the last years.  While still experimental, it is now
+	mature enough to be included directly into FreeType.
+
+	Most of the code is based on the ClearType whitepaper written by
+	Greg Hitchcock
+
+	  http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx
+
+	which gives a detailed overview of the necessary changes to the
+	Microsoft rasterizer so that older fonts are supported.  However, a
+	lot of details are still missing, and this patches provides a
+	framework to easily handle rendering issues down to the glyph level
+	of certain fonts.
+
+	Note that ClearType support is not completely implemented!  In
+	particular, full support for the options `compatible_widths',
+	`symmetrical_smoothing, and `bgr' (via the GETINFO bytecode
+	instruction) is missing.
+
+	* src/truetype/ttsubpix.c: New file, providing code to handle
+	`tweaks', this is, rules for certain glyphs in certain fonts
+	(including wildcards) which need a special treatment.
+
+	* src/truetype/ttsubpix.h: New file, holding the tweaking rules.
+
+	* include/freetype/config/ftoption.h, src/devel/ftoption.h
+	(TT_CONFIG_OPTION_SUBPIXEL_HINTING): New macro.
+
+	* include/freetype/internal/ftobjs.h (FT_PIX_FLOOR_GRID,
+	FT_PIX_ROUND_GRID, FT_PIX_CEIL_GRID): New macros.
+
+	* src/truetype/truetype.c [TT_USE_BYTECODE_INTERPRETER]: Include
+	`ttsubpix.c'.
+
+	* src/truetype/ttgload.c: Include `ttsubpix.h'.
+	[All changes below are guarded by TT_CONFIG_OPTION_SUBPIXEL_HINTING.]
+
+	(tt_get_metrics): Set tweak flags.
+	(TT_Hint_Glyph): Call `FT_Outline_EmboldenXY' if necessary.
+	(TT_Process_Simple_Glyph): Compensate emboldening if necessary.
+	(compute_glyph_metrics): Handle `compatible widths' option.
+	(tt_loader_init): Handle ClearType GETINFO information bits.
+
+	* src/truetype/rules.mk (TT_DRC_SRC): Updated.
+
+	* src/truetype/ttinterp.c: Include `ttsubpix.h'.
+	[Where necessary, changes below are guarded by
+	TT_CONFIG_OPTION_SUBPIXEL_HINTING.]
+
+	(Direct_Move, Direct_Move_X): Extended.
+	(Round_None, Round_To_Grid, Round_To_Half_Grid, Round_Down_To_Grid,
+	Round_Up_To_Grid, Round_To_Double_Grid, Round_Super, Round_Super_45,
+	SetSuperRound): Add parameter to handle the number of grid lines per
+	pixel.
+	(SET_SuperRound, ROUND_None, CUR_Func_round): Updated.
+	(DO_SROUND, DOS45ROUND, DO_ODD, DO_EVEN): Updated.
+	(DO_ROUND, DO_NROUND): Updated.
+	(DO_RS): Take care of `Typeman' bytecode patterns.
+	(Ins_FDEF): Add some debugging code.  Commented out.
+	(Ins_ENDF): Restore state.
+	(Ins_CALL, Ins_LOOPCALL): Handle inline delta functions.
+	(Ins_MD): Handle `Vacuform' rounds.
+	(Move_Zp2_Point, Ins_SHPIX, Ins_MSIRP, Ins_MDAP, Ins_MIAP,
+	Ins_MDRP, Ins_MIRP): Handle tweaks.
+	(Ins_ALIGNRP): Add tweak guard.
+	(Ins_IUP, Ins_DELTAP): Handle tweaks.
+	(Ins_GETINFO): Handle new ClearType bits.
+	(TT_RunIns): Handle tweaks.
+
+	* src/truetype/ttinterp.h: Updated.
+	(SPH_TweakRule, SPH_ScaleRule): New structures for tweaks.
+	(TT_ExecContextRec): Add members for subpixel hinting support.
+
+	* src/truetype/ttobjs.h (TT_DefRecord): Add `inline_delta' member.
+
 2012-06-15  Werner Lemberg  <wl@gnu.org>
 
 	* Version 2.4.10 released.
diff --git a/devel/ftoption.h b/devel/ftoption.h
index ba7db16..6b2a40f 100644
--- a/devel/ftoption.h
+++ b/devel/ftoption.h
@@ -560,6 +560,28 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*                                                                       */
+  /* Define TT_CONFIG_OPTION_SUBPIXEL_HINTING if you want to compile       */
+  /* EXPERIMENTAL subpixel hinting support into the TrueType driver.  This */
+  /* replaces the native TrueType hinting mechanism when anything but      */
+  /* FT_RENDER_MODE_MONO is requested.                                     */
+  /*                                                                       */
+  /* Enabling this causes the TrueType driver to ignore instructions under */
+  /* certain conditions.  This is done in accordance with the guide here,  */
+  /* with some minor differences:                                          */
+  /*                                                                       */
+  /*  http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx */
+  /*                                                                       */
+  /* By undefining this, you only compile the code necessary to hint       */
+  /* TrueType glyphs with native TT hinting.                               */
+  /*                                                                       */
+  /*   This option requires TT_CONFIG_OPTION_BYTECODE_INTERPRETER to be    */
+  /*   defined.                                                            */
+  /*                                                                       */
+#define TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* If you define TT_CONFIG_OPTION_UNPATENTED_HINTING, a special version  */
   /* of the TrueType bytecode interpreter is used that doesn't implement   */
   /* any of the patented opcodes and algorithms.  The patents related to   */
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index 66bc43b..a73fff4 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -560,6 +560,28 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*                                                                       */
+  /* Define TT_CONFIG_OPTION_SUBPIXEL_HINTING if you want to compile       */
+  /* EXPERIMENTAL subpixel hinting support into the TrueType driver.  This */
+  /* replaces the native TrueType hinting mechanism when anything but      */
+  /* FT_RENDER_MODE_MONO is requested.                                     */
+  /*                                                                       */
+  /* Enabling this causes the TrueType driver to ignore instructions under */
+  /* certain conditions.  This is done in accordance with the guide here,  */
+  /* with some minor differences:                                          */
+  /*                                                                       */
+  /*  http://www.microsoft.com/typography/cleartype/truetypecleartype.aspx */
+  /*                                                                       */
+  /* By undefining this, you only compile the code necessary to hint       */
+  /* TrueType glyphs with native TT hinting.                               */
+  /*                                                                       */
+  /*   This option requires TT_CONFIG_OPTION_BYTECODE_INTERPRETER to be    */
+  /*   defined.                                                            */
+  /*                                                                       */
+/* #define TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* If you define TT_CONFIG_OPTION_UNPATENTED_HINTING, a special version  */
   /* of the TrueType bytecode interpreter is used that doesn't implement   */
   /* any of the patented opcodes and algorithms.  The patents related to   */
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index eee3d24..d4da5da 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -81,6 +81,14 @@ FT_BEGIN_HEADER
 #define FT_PIX_ROUND( x )     FT_PIX_FLOOR( (x) + 32 )
 #define FT_PIX_CEIL( x )      FT_PIX_FLOOR( (x) + 63 )
 
+  /*
+   *  These are used in ttinterp.c for subpixel hinting with an
+   *  adjustable grids-per-pixel value.
+   */
+#define FT_PIX_FLOOR_GRID( x, n )  ( (x) & ~( 64 / (n) - 1 ) )
+#define FT_PIX_ROUND_GRID( x, n )  FT_PIX_FLOOR_GRID( (x) + 32 / (n), (n) )
+#define FT_PIX_CEIL_GRID( x, n )   FT_PIX_FLOOR_GRID( (x) + 63 / (n), (n) )
+
 
   /*
    *  Return the highest power of 2 that is <= value; this correspond to
diff --git a/src/truetype/rules.mk b/src/truetype/rules.mk
index 507ef16..d4b69f5 100644
--- a/src/truetype/rules.mk
+++ b/src/truetype/rules.mk
@@ -3,7 +3,7 @@
 #
 
 
-# Copyright 1996-2000, 2001, 2003, 2004, 2011 by
+# Copyright 1996-2001, 2003-2004, 2011-2012 by
 # David Turner, Robert Wilhelm, and Werner Lemberg.
 #
 # This file is part of the FreeType project, and may only be used, modified,
@@ -31,7 +31,8 @@ TT_DRV_SRC := $(TT_DIR)/ttdriver.c \
               $(TT_DIR)/ttinterp.c \
               $(TT_DIR)/ttobjs.c   \
               $(TT_DIR)/ttpic.c    \
-              $(TT_DIR)/ttpload.c
+              $(TT_DIR)/ttpload.c  \
+              $(TT_DIR)/ttsubpix.c
 
 # TrueType driver headers
 #
diff --git a/src/truetype/truetype.c b/src/truetype/truetype.c
index 4bd1209..576912b 100644
--- a/src/truetype/truetype.c
+++ b/src/truetype/truetype.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType TrueType driver component (body only).                      */
 /*                                                                         */
-/*  Copyright 1996-2001, 2004, 2006 by                                     */
+/*  Copyright 1996-2001, 2004, 2006, 2012 by                               */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -27,6 +27,7 @@
 
 #ifdef TT_USE_BYTECODE_INTERPRETER
 #include "ttinterp.c"
+#include "ttsubpix.c"
 #endif
 
 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 22cbc09..a88a705 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -32,6 +32,7 @@
 #endif
 
 #include "tterrors.h"
+#include "ttsubpix.h"
 
 
   /*************************************************************************/
@@ -149,6 +150,15 @@
     loader->top_bearing  = top_bearing;
     loader->vadvance     = advance_height;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( loader->exec )
+      loader->exec->sph_tweak_flags = 0;
+
+    /* this may not be the right place for this, but it works */
+    if ( loader->exec && loader->exec->ignore_x_mode )
+      sph_set_tweaks( loader, glyph_index );
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     if ( !loader->linear_def )
     {
       loader->linear_def = 1;
@@ -813,6 +823,13 @@
       loader->pp4 = zone->cur[zone->n_points - 1];
     }
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( loader->exec->sph_tweak_flags & SPH_TWEAK_DEEMBOLDEN )
+      FT_Outline_EmboldenXY( &loader->gloader->current.outline, -24, 0 );
+
+    else if ( loader->exec->sph_tweak_flags & SPH_TWEAK_EMBOLDEN )
+      FT_Outline_EmboldenXY( &loader->gloader->current.outline, 24, 0 );
+#endif
     return TT_Err_Ok;
   }
 
@@ -835,6 +852,14 @@
     FT_Outline*     outline;
     FT_Int          n_points;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    TT_Face     face           = (TT_Face)loader->face;
+    FT_String*  family         = face->root.family_name;
+    FT_Int      ppem           = loader->size->metrics.x_ppem;
+    FT_String*  style          = face->root.style_name;
+    FT_Int      x_scale_factor = 1000;
+#endif
+
 
     outline  = &gloader->current.outline;
     n_points = outline->n_points;
@@ -889,6 +914,32 @@
                      loader->zone.n_points + 4 );
     }
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    /* scale, but only if enabled and only if TT hinting is being used */
+    if ( IS_HINTED( loader->load_flags ) )
+      x_scale_factor = scale_test_tweak( face, family, ppem, style,
+                                         loader->glyph_index, X_SCALING_Rules,
+                                         X_SCALING_RULES_SIZE );
+    /* scale the glyph */
+    if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ||
+         x_scale_factor != 1000                         )
+    {
+      FT_Vector*  vec     = outline->points;
+      FT_Vector*  limit   = outline->points + n_points;
+      FT_Fixed    x_scale = FT_MulDiv(
+                              ((TT_Size)loader->size)->metrics.x_scale,
+                              x_scale_factor, 1000 );
+      FT_Fixed    y_scale = ((TT_Size)loader->size)->metrics.y_scale;
+
+
+      /* compensate for any scaling by de/emboldening; */
+      /* the amount was determined via experimentation */
+      if ( x_scale_factor != 1000 && ppem > 11 )
+        FT_Outline_EmboldenXY( outline,
+                               FT_MulDiv( 16 * ppem,
+                                          1000 - x_scale_factor,
+                                          0x1000L ), 0 );
+#else
     /* scale the glyph */
     if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
     {
@@ -896,6 +947,7 @@
       FT_Vector*  limit   = outline->points + n_points;
       FT_Fixed    x_scale = ((TT_Size)loader->size)->metrics.x_scale;
       FT_Fixed    y_scale = ((TT_Size)loader->size)->metrics.y_scale;
+#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
 
       for ( ; vec < limit; vec++ )
@@ -1648,12 +1700,26 @@
     {
       FT_Byte*  widthp;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+      FT_Bool  ignore_x_mode;
+
+
+      ignore_x_mode = FT_BOOL( FT_LOAD_TARGET_MODE( loader->load_flags ) !=
+                               FT_RENDER_MODE_MONO );
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
       widthp = tt_face_get_device_metrics( face,
                                            size->root.metrics.x_ppem,
                                            glyph_index );
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+      if ( widthp                                                   &&
+           ( ( ignore_x_mode && loader->exec->compatible_widths ) ||
+              !ignore_x_mode                                      ||
+              SPH_OPTION_BITMAP_WIDTHS                            ) )
+#else
       if ( widthp )
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
         glyph->metrics.horiAdvance = *widthp << 6;
     }
 
@@ -1848,6 +1914,15 @@
     {
       TT_ExecContext  exec;
       FT_Bool         grayscale;
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+      FT_Bool         subpixel_hinting;
+      FT_Bool         grayscale_hinting;
+#if 0
+      FT_Bool         compatible_widths;
+      FT_Bool         symmetrical_smoothing;
+      FT_Bool         bgr;
+#endif
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
 
       if ( !size->cvt_ready )
@@ -1865,11 +1940,86 @@
       if ( !exec )
         return TT_Err_Could_Not_Find_Context;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
+      subpixel_hinting = FT_BOOL( ( FT_LOAD_TARGET_MODE( load_flags )
+                                    != FT_RENDER_MODE_MONO )          &&
+                                  SPH_OPTION_SET_SUBPIXEL             );
+
+      if ( subpixel_hinting )
+        grayscale = grayscale_hinting = FALSE;
+
+      else if ( SPH_OPTION_SET_GRAYSCALE )
+      {
+        grayscale = grayscale_hinting = TRUE;
+        subpixel_hinting = FALSE;
+      }
+
+      if ( FT_IS_TRICKY( glyph->face ) )
+        subpixel_hinting = grayscale_hinting = FALSE;
+
+      exec->ignore_x_mode      = subpixel_hinting || grayscale_hinting;
+      exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION;
+      if ( exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 )
+        exec->rasterizer_version = 35;
+
+#if 1
+      exec->compatible_widths     = SPH_OPTION_SET_COMPATIBLE_WIDTHS;
+      exec->symmetrical_smoothing = FALSE;
+      exec->bgr                   = FALSE;
+#else /* 0 */
+      exec->compatible_widths =
+        FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) !=
+                 TT_LOAD_COMPATIBLE_WIDTHS );
+      exec->symmetrical_smoothing =
+        FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) !=
+                 TT_LOAD_SYMMETRICAL_SMOOTHING );
+      exec->bgr =
+        FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) !=
+                 TT_LOAD_BGR );
+#endif /* 0 */
+
+#else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
       grayscale =
         FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != FT_RENDER_MODE_MONO );
 
+#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
       TT_Load_Context( exec, face, size );
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
+      /* a change from mono to subpixel rendering (and vice versa) */
+      /* requires a re-execution of the CVT program                */
+      if ( subpixel_hinting != exec->subpixel_hinting )
+      {
+        FT_UInt  i;
+
+
+        exec->subpixel_hinting = subpixel_hinting;
+
+        for ( i = 0; i < size->cvt_size; i++ )
+          size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
+        tt_size_run_prep( size, pedantic );
+      }
+
+      /* a change from mono to grayscale rendering (and vice versa) */
+      /* requires a re-execution of the CVT program                 */
+      if ( grayscale != exec->grayscale_hinting )
+      {
+        FT_UInt  i;
+
+
+        exec->grayscale_hinting = grayscale_hinting;
+
+        for ( i = 0; i < size->cvt_size; i++ )
+          size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
+        tt_size_run_prep( size, pedantic );
+      }
+
+#else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
       /* a change from mono to grayscale rendering (and vice versa) */
       /* requires a re-execution of the CVT program                 */
       if ( grayscale != exec->grayscale )
@@ -1887,6 +2037,8 @@
         tt_size_run_prep( size, pedantic );
       }
 
+#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
       /* see whether the cvt program has disabled hinting */
       if ( exec->GS.instruct_control & 1 )
         load_flags |= FT_LOAD_NO_HINTING;
diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c
index 3a8680f..bba2853 100644
--- a/src/truetype/ttinterp.c
+++ b/src/truetype/ttinterp.c
@@ -27,13 +27,16 @@
 #include FT_SYSTEM_H
 
 #include "ttinterp.h"
-
 #include "tterrors.h"
+#include "ttsubpix.h"
 
 
 #ifdef TT_USE_BYTECODE_INTERPRETER
 
 
+#define xxxSPH_DEBUG
+#define xxxSPH_DEBUG_MORE_VERBOSE
+
 #define TT_MULFIX           FT_MulFix
 #define TT_MULDIV           FT_MulDiv
 #define TT_MULDIV_NO_ROUND  FT_MulDiv_No_Round
@@ -153,11 +156,11 @@
 #define NORMalize( x, y, v ) \
           Normalize( EXEC_ARG_ x, y, v )
 
-#define SET_SuperRound( scale, flags ) \
-          SetSuperRound( EXEC_ARG_ scale, flags )
+#define SET_SuperRound( scale, flags, res ) \
+          SetSuperRound( EXEC_ARG_ scale, flags, res )
 
-#define ROUND_None( d, c ) \
-          Round_None( EXEC_ARG_ d, c )
+#define ROUND_None( d, c, e ) \
+          Round_None( EXEC_ARG_ d, c, e )
 
 #define INS_Goto_CodeRange( range, ip ) \
           Ins_Goto_CodeRange( EXEC_ARG_ range, ip )
@@ -168,8 +171,8 @@
 #define CUR_Func_move_orig( z, p, d ) \
           CUR.func_move_orig( EXEC_ARG_ z, p, d )
 
-#define CUR_Func_round( d, c ) \
-          CUR.func_round( EXEC_ARG_ d, c )
+#define CUR_Func_round( d, c, e ) \
+          CUR.func_round( EXEC_ARG_ d, c, e )
 
 #define CUR_Func_read_cvt( index ) \
           CUR.func_read_cvt( EXEC_ARG_ index )
@@ -1850,6 +1853,10 @@
 
     if ( v != 0 )
     {
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+      if ( !CUR.ignore_x_mode                                ||
+           ( CUR.sph_tweak_flags & SPH_TWEAK_ALLOW_X_DMOVE ) )
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
       zone->cur[point].x += TT_MULDIV( distance,
                                        v * 0x10000L,
                                        CUR.F_dot_P );
@@ -1932,6 +1939,10 @@
   {
     FT_UNUSED_EXEC;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( !CUR.ignore_x_mode                                 ||
+         ( CUR.sph_tweak_flags & SPH_TWEAK_ALLOW_X_DMOVEX ) )
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
     zone->cur[point].x += distance;
     zone->tags[point]  |= FT_CURVE_TAG_TOUCH_X;
   }
@@ -1994,6 +2005,8 @@
   /*                                                                       */
   /*    compensation :: The engine compensation.                           */
   /*                                                                       */
+  /*    resolution   :: The number of grid lines per pixel.                */
+  /*                                                                       */
   /* <Return>                                                              */
   /*    The compensated distance.                                          */
   /*                                                                       */
@@ -2005,11 +2018,13 @@
   /*                                                                       */
   static FT_F26Dot6
   Round_None( EXEC_OP_ FT_F26Dot6  distance,
-                       FT_F26Dot6  compensation )
+                       FT_F26Dot6  compensation,
+                       FT_Int      resolution )
   {
     FT_F26Dot6  val;
 
     FT_UNUSED_EXEC;
+    FT_UNUSED( resolution );
 
 
     if ( distance >= 0 )
@@ -2024,6 +2039,7 @@
       if ( val > 0 )
         val = 0;
     }
+
     return val;
   }
 
@@ -2041,12 +2057,15 @@
   /*                                                                       */
   /*    compensation :: The engine compensation.                           */
   /*                                                                       */
+  /*    resolution   :: The number of grid lines per pixel.                */
+  /*                                                                       */
   /* <Return>                                                              */
   /*    Rounded distance.                                                  */
   /*                                                                       */
   static FT_F26Dot6
   Round_To_Grid( EXEC_OP_ FT_F26Dot6  distance,
-                          FT_F26Dot6  compensation )
+                          FT_F26Dot6  compensation,
+                          FT_Int      resolution )
   {
     FT_F26Dot6  val;
 
@@ -2055,15 +2074,15 @@
 
     if ( distance >= 0 )
     {
-      val = distance + compensation + 32;
+      val = distance + compensation + 32 / resolution;
       if ( distance && val > 0 )
-        val &= ~63;
+        val &= ~( 64 / resolution - 1 );
       else
         val = 0;
     }
     else
     {
-      val = -FT_PIX_ROUND( compensation - distance );
+      val = -FT_PIX_ROUND_GRID( compensation - distance, resolution );
       if ( val > 0 )
         val = 0;
     }
@@ -2085,12 +2104,15 @@
   /*                                                                       */
   /*    compensation :: The engine compensation.                           */
   /*                                                                       */
+  /*    resolution   :: The number of grid lines per pixel.                */
+  /*                                                                       */
   /* <Return>                                                              */
   /*    Rounded distance.                                                  */
   /*                                                                       */
   static FT_F26Dot6
   Round_To_Half_Grid( EXEC_OP_ FT_F26Dot6  distance,
-                               FT_F26Dot6  compensation )
+                               FT_F26Dot6  compensation,
+                               FT_Int      resolution )
   {
     FT_F26Dot6  val;
 
@@ -2099,13 +2121,15 @@
 
     if ( distance >= 0 )
     {
-      val = FT_PIX_FLOOR( distance + compensation ) + 32;
+      val = FT_PIX_FLOOR_GRID( distance + compensation, resolution ) +
+            32 / resolution;
       if ( distance && val < 0 )
         val = 0;
     }
     else
     {
-      val = -( FT_PIX_FLOOR( compensation - distance ) + 32 );
+      val = -( FT_PIX_FLOOR_GRID( compensation - distance, resolution ) +
+               32 / resolution );
       if ( val > 0 )
         val = 0;
     }
@@ -2127,12 +2151,15 @@
   /*                                                                       */
   /*    compensation :: The engine compensation.                           */
   /*                                                                       */
+  /*    resolution   :: The number of grid lines per pixel.                */
+  /*                                                                       */
   /* <Return>                                                              */
   /*    Rounded distance.                                                  */
   /*                                                                       */
   static FT_F26Dot6
   Round_Down_To_Grid( EXEC_OP_ FT_F26Dot6  distance,
-                               FT_F26Dot6  compensation )
+                               FT_F26Dot6  compensation,
+                               FT_Int      resolution )
   {
     FT_F26Dot6  val;
 
@@ -2143,13 +2170,13 @@
     {
       val = distance + compensation;
       if ( distance && val > 0 )
-        val &= ~63;
+        val &= ~( 64 / resolution - 1 );
       else
         val = 0;
     }
     else
     {
-      val = -( ( compensation - distance ) & -64 );
+      val = -( ( compensation - distance ) & -( 64 / resolution ) );
       if ( val > 0 )
         val = 0;
     }
@@ -2171,12 +2198,15 @@
   /*                                                                       */
   /*    compensation :: The engine compensation.                           */
   /*                                                                       */
+  /*    resolution   :: The number of grid lines per pixel.                */
+  /*                                                                       */
   /* <Return>                                                              */
   /*    Rounded distance.                                                  */
   /*                                                                       */
   static FT_F26Dot6
   Round_Up_To_Grid( EXEC_OP_ FT_F26Dot6  distance,
-                             FT_F26Dot6  compensation )
+                             FT_F26Dot6  compensation,
+                             FT_Int      resolution )
   {
     FT_F26Dot6  val;
 
@@ -2185,15 +2215,15 @@
 
     if ( distance >= 0 )
     {
-      val = distance + compensation + 63;
+      val = distance + compensation + ( 64 / resolution - 1 );
       if ( distance && val > 0 )
-        val &= ~63;
+        val &= ~( 64 / resolution - 1 );
       else
         val = 0;
     }
     else
     {
-      val = - FT_PIX_CEIL( compensation - distance );
+      val = -FT_PIX_CEIL_GRID( compensation - distance, resolution );
       if ( val > 0 )
         val = 0;
     }
@@ -2215,12 +2245,15 @@
   /*                                                                       */
   /*    compensation :: The engine compensation.                           */
   /*                                                                       */
+  /*    resolution   :: The number of grid lines per pixel.                */
+  /*                                                                       */
   /* <Return>                                                              */
   /*    Rounded distance.                                                  */
   /*                                                                       */
   static FT_F26Dot6
   Round_To_Double_Grid( EXEC_OP_ FT_F26Dot6  distance,
-                                 FT_F26Dot6  compensation )
+                                 FT_F26Dot6  compensation,
+                                 FT_Int      resolution )
   {
     FT_F26Dot6 val;
 
@@ -2229,15 +2262,15 @@
 
     if ( distance >= 0 )
     {
-      val = distance + compensation + 16;
+      val = distance + compensation + 16 / resolution;
       if ( distance && val > 0 )
-        val &= ~31;
+        val &= ~( 32 / resolution - 1 );
       else
         val = 0;
     }
     else
     {
-      val = -FT_PAD_ROUND( compensation - distance, 32 );
+      val = -FT_PAD_ROUND( compensation - distance, 32 / resolution );
       if ( val > 0 )
         val = 0;
     }
@@ -2259,6 +2292,8 @@
   /*                                                                       */
   /*    compensation :: The engine compensation.                           */
   /*                                                                       */
+  /*    resolution   :: The number of grid lines per pixel.                */
+  /*                                                                       */
   /* <Return>                                                              */
   /*    Rounded distance.                                                  */
   /*                                                                       */
@@ -2270,10 +2305,13 @@
   /*                                                                       */
   static FT_F26Dot6
   Round_Super( EXEC_OP_ FT_F26Dot6  distance,
-                        FT_F26Dot6  compensation )
+                        FT_F26Dot6  compensation,
+                        FT_Int      resolution )
   {
     FT_F26Dot6  val;
 
+    FT_UNUSED( resolution );
+
 
     if ( distance >= 0 )
     {
@@ -2309,6 +2347,8 @@
   /*                                                                       */
   /*    compensation :: The engine compensation.                           */
   /*                                                                       */
+  /*    resolution   :: The number of grid lines per pixel.                */
+  /*                                                                       */
   /* <Return>                                                              */
   /*    Rounded distance.                                                  */
   /*                                                                       */
@@ -2318,10 +2358,13 @@
   /*                                                                       */
   static FT_F26Dot6
   Round_Super_45( EXEC_OP_ FT_F26Dot6  distance,
-                           FT_F26Dot6  compensation )
+                           FT_F26Dot6  compensation,
+                           FT_Int      resolution )
   {
     FT_F26Dot6  val;
 
+    FT_UNUSED( resolution );
+
 
     if ( distance >= 0 )
     {
@@ -2404,13 +2447,19 @@
   /*    Sets Super Round parameters.                                       */
   /*                                                                       */
   /* <Input>                                                               */
-  /*    GridPeriod :: Grid period                                          */
-  /*    selector   :: SROUND opcode                                        */
+  /*    GridPeriod :: The grid period.                                     */
+  /*                                                                       */
+  /*    selector   :: The SROUND opcode.                                   */
+  /*                                                                       */
+  /*    resolution :: The number of grid lines per pixel.                  */
   /*                                                                       */
   static void
   SetSuperRound( EXEC_OP_ FT_F26Dot6  GridPeriod,
-                          FT_Long     selector )
+                          FT_Long     selector,
+                          FT_Int      resolution )
   {
+    FT_UNUSED( resolution );
+
     switch ( (FT_Int)( selector & 0xC0 ) )
     {
       case 0:
@@ -3080,13 +3129,13 @@
 
 
 #define DO_SROUND                                \
-    SET_SuperRound( 0x4000, args[0] );           \
+    SET_SuperRound( 0x4000, args[0], 1 );        \
     CUR.GS.round_state = TT_Round_Super;         \
     CUR.func_round = (TT_Round_Func)Round_Super;
 
 
 #define DO_S45ROUND                                 \
-    SET_SuperRound( 0x2D41, args[0] );              \
+    SET_SuperRound( 0x2D41, args[0], 1 );           \
     CUR.GS.round_state = TT_Round_Super_45;         \
     CUR.func_round = (TT_Round_Func)Round_Super_45;
 
@@ -3257,12 +3306,12 @@
     args[0] = ( args[0] != args[1] );
 
 
-#define DO_ODD                                                  \
-    args[0] = ( ( CUR_Func_round( args[0], 0 ) & 127 ) == 64 );
+#define DO_ODD                                                     \
+    args[0] = ( ( CUR_Func_round( args[0], 0, 1 ) & 127 ) == 64 );
 
 
-#define DO_EVEN                                                \
-    args[0] = ( ( CUR_Func_round( args[0], 0 ) & 127 ) == 0 );
+#define DO_EVEN                                                   \
+    args[0] = ( ( CUR_Func_round( args[0], 0, 1 ) & 127 ) == 0 );
 
 
 #define DO_AND                        \
@@ -3311,6 +3360,34 @@
 #define DO_CEILING                    \
     args[0] = FT_PIX_CEIL( args[0] );
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
+#define DO_RS                                             \
+   {                                                      \
+     FT_ULong  I = (FT_ULong)args[0];                     \
+                                                          \
+                                                          \
+     if ( BOUNDSL( I, CUR.storeSize ) )                   \
+     {                                                    \
+       if ( CUR.pedantic_hinting )                        \
+         ARRAY_BOUND_ERROR;                               \
+       else                                               \
+         args[0] = 0;                                     \
+     }                                                    \
+     else                                                 \
+     {                                                    \
+       /* subpixel hinting - avoid Typeman Dstroke and */ \
+       /* IStroke and Vacuform rounds                  */ \
+                                                          \
+       if ( CUR.compatibility_mode           &&           \
+            ( I == 24 || I == 22 || I == 8 ) )            \
+         args[0] = 0;                                     \
+       else                                               \
+         args[0] = CUR.storage[I];                        \
+     }                                                    \
+   }
+
+#else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
 #define DO_RS                           \
    {                                    \
@@ -3330,6 +3407,8 @@
        args[0] = CUR.storage[I];        \
    }
 
+#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
 
 #define DO_WS                           \
    {                                    \
@@ -3405,15 +3484,17 @@
     CUR.error = TT_Err_Debug_OpCode;
 
 
-#define DO_ROUND                                                   \
-    args[0] = CUR_Func_round(                                      \
-                args[0],                                           \
-                CUR.tt_metrics.compensations[CUR.opcode - 0x68] );
+#define DO_ROUND                                                 \
+    args[0] = CUR_Func_round(                                    \
+                args[0],                                         \
+                CUR.tt_metrics.compensations[CUR.opcode - 0x68], \
+                1 );
 
 
-#define DO_NROUND                                                            \
-    args[0] = ROUND_None( args[0],                                           \
-                          CUR.tt_metrics.compensations[CUR.opcode - 0x6C] );
+#define DO_NROUND                                                          \
+    args[0] = ROUND_None( args[0],                                         \
+                          CUR.tt_metrics.compensations[CUR.opcode - 0x6C], \
+                          1 );
 
 
 #define DO_MAX               \
@@ -4587,6 +4668,24 @@
     TT_DefRecord*  rec;
     TT_DefRecord*  limit;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+#if 0
+    int  opcode_pattern[4][12] = {
+           /* VacuFormRound function */
+           {0x45,0x23,0x46,0x60,0x20},
+           /* inline delta function 1 */
+           {0x4B,0x53,0x23,0x4B,0x51,0x5A,0x58,0x38,0x1B,0x21,0x21,0x59},
+           /* inline delta function 2 */
+           {0x4B,0x54,0x58,0x38,0x1B,0x5A,0x21,0x21,0x59},
+           /* diagonal stroke function */
+           {0x20,0x20,0x40,0x60,0x47,0x40,0x23,0x42},
+         };
+    int  opcode_patterns = 4;
+    int  i;
+    int  opcode_pointer[4] = {0,0,0,0};
+#endif /* 0 */
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
 
     /* some font programs are broken enough to redefine functions! */
     /* We will then parse the current table.                       */
@@ -4620,10 +4719,11 @@
       return;
     }
 
-    rec->range  = CUR.curRange;
-    rec->opc    = (FT_UInt16)n;
-    rec->start  = CUR.IP + 1;
-    rec->active = TRUE;
+    rec->range        = CUR.curRange;
+    rec->opc          = (FT_UInt16)n;
+    rec->start        = CUR.IP + 1;
+    rec->active       = TRUE;
+    rec->inline_delta = FALSE;
 
     if ( n > CUR.maxFunc )
       CUR.maxFunc = (FT_UInt16)n;
@@ -4633,6 +4733,78 @@
 
     while ( SKIP_Code() == SUCCESS )
     {
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+#if 0
+#ifdef SPH_DEBUG_MORE_VERBOSE
+      printf ("Opcode: %d ", CUR.opcode);
+#endif
+
+      for ( i = 0; i < opcode_patterns; i++ )
+      {
+        if ( CUR.opcode == opcode_pattern[i][opcode_pointer[i]] )
+        {
+#ifdef SPH_DEBUG_MORE_VERBOSE
+          printf( "function %d, opcode ptrn: %d"
+                  "  op# %d: %d FOUND \n",
+                  n, i, opcode_pointer[i], CUR.opcode );
+#endif
+          opcode_pointer[i] += 1;
+
+          if ( i == 0 && opcode_pointer[0] == 5 )
+          {
+
+            CUR.inline_delta_funcs[CUR.num_delta_funcs] = n;
+            CUR.num_delta_funcs++;
+#ifdef SPH_DEBUG
+            printf( "Vacuform Round FUNCTION %d detected\n", n);
+#endif
+            /*rec->active = FALSE;*/
+            opcode_pointer[i] = 0;
+          }
+
+          if ( i == 1 && opcode_pointer[1] == 12 )
+          {
+            CUR.inline_delta_funcs[CUR.num_delta_funcs] = n;
+            CUR.num_delta_funcs++;
+#ifdef SPH_DEBUG
+            printf( "inline delta FUNCTION1 %d detected\n",
+                    n, CUR.num_delta_funcs);
+#endif
+            rec->inline_delta = TRUE;
+            opcode_pointer[i] = 0;
+          }
+
+          if ( i == 2 && opcode_pointer[1] == 9 )
+          {
+            CUR.inline_delta_funcs[CUR.num_delta_funcs] = n;
+            CUR.num_delta_funcs++;
+            rec->inline_delta = TRUE;
+#ifdef SPH_DEBUG
+            printf( "inline delta2 FUNCTION2 %d detected\n",
+                    n, CUR.num_delta_funcs);
+#endif
+            opcode_pointer[i] = 0;
+          }
+
+          if ( i == 4 && opcode_pointer[1] == 8 )
+          {
+            CUR.inline_delta_funcs[CUR.num_delta_funcs] = n;
+            CUR.num_delta_funcs++;
+            /*rec->active = FALSE;*/
+#ifdef SPH_DEBUG
+            printf( "diagonal stroke function %d detected\n",
+                    n, CUR.num_delta_funcs);
+#endif
+            opcode_pointer[i] = 0;
+          }
+        }
+
+        else
+          opcode_pointer[i] = 0;
+      }
+#endif /* 0 */
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
       switch ( CUR.opcode )
       {
       case 0x89:    /* IDEF */
@@ -4676,6 +4848,15 @@
 
     CUR.step_ins = FALSE;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    /*
+     *  CUR.ignore_x_mode may be turned off prior to function calls.  This
+     *  ensures it is turned back on.
+     */
+    CUR.ignore_x_mode =  ( CUR.subpixel_hinting || CUR.grayscale_hinting ) &&
+                        !( CUR.sph_tweak_flags & SPH_TWEAK_PIXEL_HINTING );
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     if ( pRec->Cur_Count > 0 )
     {
       CUR.callTop++;
@@ -4709,6 +4890,10 @@
     TT_CallRec*    pCrec;
     TT_DefRecord*  def;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    FT_Bool        oldF;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
 
     /* first of all, check the index */
 
@@ -4746,6 +4931,17 @@
     if ( !def->active )
       goto Fail;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    /* This is test code used to detect inline delta functions */
+    oldF = def->inline_delta;
+    if ( CUR.ignore_x_mode && def->inline_delta )
+      CUR.in_delta_function = TRUE;
+
+#ifdef SPH_DEBUG
+      printf("Entering function %d\n", F);
+#endif
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     /* check the call stack */
     if ( CUR.callTop >= CUR.callSize )
     {
@@ -4767,6 +4963,13 @@
                         def->start );
 
     CUR.step_ins = FALSE;
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    CUR.in_delta_function = oldF;
+
+#ifdef SPH_DEBUG
+      printf("Leaving function %d\n", F);
+#endif
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
     return;
 
   Fail:
@@ -4787,6 +4990,10 @@
     TT_CallRec*    pCrec;
     TT_DefRecord*  def;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    FT_Bool        oldF;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
 
     /* first of all, check the index */
     F = args[1];
@@ -4823,6 +5030,13 @@
     if ( !def->active )
       goto Fail;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    oldF = def->inline_delta;
+    if ( CUR.ignore_x_mode && def->inline_delta )
+      CUR.in_delta_function = TRUE;
+
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     /* check stack */
     if ( CUR.callTop >= CUR.callSize )
     {
@@ -4846,6 +5060,11 @@
 
       CUR.step_ins = FALSE;
     }
+
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    CUR.in_delta_function = oldF;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     return;
 
   Fail:
@@ -5195,6 +5414,12 @@
       }
     }
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    /* Disable Type 2 Vacuform Rounds - e.g. Arial Narrow */
+    if ( CUR.ignore_x_mode && FT_ABS( D ) == 64 )
+      D += 1;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     args[0] = D;
   }
 
@@ -5691,7 +5916,12 @@
 
     if ( CUR.GS.freeVector.x != 0 )
     {
-      CUR.zp2.cur[point].x += dx;
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+      if ( !CUR.ignore_x_mode                                      ||
+          ( CUR.ignore_x_mode                                    &&
+            ( CUR.sph_tweak_flags & SPH_TWEAK_ALLOW_X_MOVE_ZP2 ) ) )
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+        CUR.zp2.cur[point].x += dx;
       if ( touch )
         CUR.zp2.tags[point] |= FT_CURVE_TAG_TOUCH_X;
     }
@@ -5872,6 +6102,9 @@
   {
     FT_F26Dot6  dx, dy;
     FT_UShort   point;
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    FT_Int      B1, B2;
+#endif
 
 
     if ( CUR.top < CUR.GS.loop + 1 )
@@ -5917,7 +6150,79 @@
         }
       }
       else
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+      {
+        /*  If not using ignore_x_mode rendering, allow ZP2 move.          */
+        /*  If inline deltas aren't allowed, skip ZP2 move.                */
+        /*  If using ignore_x_mode rendering, allow ZP2 point move if:     */
+        /*   - freedom vector is y and compatibility_mode is off           */
+        /*   - the glyph is composite and the move is in the Y direction   */
+        /*   - the glyph is specifically set to allow SHPIX moves          */
+        /*   - the move is on a previously Y-touched point                 */
+
+        if ( CUR.ignore_x_mode )
+        {
+          /* save point for later comparison */
+          if ( CUR.GS.freeVector.y != 0 )
+            B1 = CUR.zp2.cur[point].y;
+          else
+            B1 = CUR.zp2.cur[point].x;
+
+          if ( CUR.GS.freeVector.y != 0                               &&
+               ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_INLINE_DELTAS ) )
+            goto Skip;
+
+          if ( CUR.ignore_x_mode                                   &&
+               !CUR.compatibility_mode && CUR.GS.freeVector.y != 0 )
+            MOVE_Zp2_Point( point, dx, dy, TRUE );
+
+          else if ( CUR.ignore_x_mode && CUR.compatibility_mode )
+          {
+            if ( CUR.ignore_x_mode                                         &&
+                ( CUR.sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) )
+            {
+              dx = FT_PIX_ROUND( B1 + dx ) - B1;
+              dy = FT_PIX_ROUND( B1 + dy ) - B1;
+            }
+
+            if ( !( CUR.sph_tweak_flags & SPH_TWEAK_ALWAYS_SKIP_DELTAP ) &&
+                  ( ( CUR.is_composite && CUR.GS.freeVector.y != 0 ) ||
+                    ( CUR.zp2.tags[point] & FT_CURVE_TAG_TOUCH_Y )   ||
+                    ( CUR.sph_tweak_flags & SPH_TWEAK_DO_SHPIX )     )   )
+              MOVE_Zp2_Point( point, dx, dy, TRUE );
+          }
+
+          /* save new point */
+          if ( CUR.GS.freeVector.y != 0 )
+            B2 = CUR.zp2.cur[point].y;
+          else
+            B2 = CUR.zp2.cur[point].x;
+
+          /* reverse any disallowed moves */
+          if ( ( ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES ) &&
+                 CUR.GS.freeVector.y != 0                                  &&
+                 B1 % 64 != 0                                              &&
+                 B2 % 64 != 0                                              &&
+                 B1 != B2                                                  ) ||
+               ( ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_OFFPIXEL_Y_MOVES ) &&
+                 CUR.GS.freeVector.y != 0                                  &&
+                 B1 % 64 == 0                                              &&
+                 B2 % 64 != 0                                              &&
+                 B1 != B2                                                  ) )
+          {
+#ifdef SPH_DEBUG
+            printf( "Reversing ZP2 move\n" );
+#endif
+            MOVE_Zp2_Point( point, -dx, -dy, TRUE );
+          }
+      }
+        else
+          MOVE_Zp2_Point( point, dx, dy, TRUE );
+      }
+  Skip:
+#else
         MOVE_Zp2_Point( point, dx, dy, TRUE );
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
       CUR.GS.loop--;
     }
@@ -5939,8 +6244,19 @@
   {
     FT_UShort   point;
     FT_F26Dot6  distance;
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    FT_Int      gridlines_per_pixel = 1;
 
 
+    if ( CUR.ignore_x_mode )
+    {
+      if ( CUR.GS.freeVector.x != 0 )
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_X;
+      else if ( CUR.GS.freeVector.y != 0 )
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_Y;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     point = (FT_UShort)args[0];
 
     if ( BOUNDS( point,      CUR.zp1.n_points ) ||
@@ -5963,6 +6279,15 @@
     distance = CUR_Func_project( CUR.zp1.cur + point,
                                  CUR.zp0.cur + CUR.GS.rp0 );
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    /* subpixel hinting - make MSIRP respect CVT cut-in; */
+    if ( CUR.ignore_x_mode                                  &&
+         CUR.GS.freeVector.x != 0                           &&
+         FT_ABS( distance - args[1] ) >=
+           CUR.GS.control_value_cutin / gridlines_per_pixel )
+      distance = args[1];
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     CUR_Func_move( &CUR.zp1, point, args[1] - distance );
 
     CUR.GS.rp1 = CUR.GS.rp0;
@@ -5985,8 +6310,22 @@
     FT_UShort   point;
     FT_F26Dot6  cur_dist,
                 distance;
+    FT_Int      gridlines_per_pixel = 1;
 
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.ignore_x_mode )
+    {
+      if ( CUR.GS.freeVector.x != 0                          &&
+           !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_X;
+
+      else if ( CUR.GS.freeVector.y != 0                          &&
+                !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_Y;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     point = (FT_UShort)args[0];
 
     if ( BOUNDS( point, CUR.zp0.n_points ) )
@@ -6000,7 +6339,8 @@
     {
       cur_dist = CUR_fast_project( &CUR.zp0.cur[point] );
       distance = CUR_Func_round( cur_dist,
-                                 CUR.tt_metrics.compensations[0] ) - cur_dist;
+                                 CUR.tt_metrics.compensations[0],
+                                 gridlines_per_pixel ) - cur_dist;
     }
     else
       distance = 0;
@@ -6025,7 +6365,21 @@
     FT_UShort   point;
     FT_F26Dot6  distance,
                 org_dist;
+    FT_Int      gridlines_per_pixel = 1;
+
+
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.ignore_x_mode )
+    {
+      if ( CUR.GS.freeVector.x != 0                          &&
+           !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_X;
 
+      else if ( CUR.GS.freeVector.y != 0                          &&
+                !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_Y;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
     cvtEntry = (FT_ULong)args[1];
     point    = (FT_UShort)args[0];
@@ -6062,21 +6416,34 @@
 
     if ( CUR.GS.gep0 == 0 )   /* If in twilight zone */
     {
-      CUR.zp0.org[point].x = TT_MulFix14( (FT_UInt32)distance,
-                                          CUR.GS.freeVector.x );
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+      /* only adjust legacy fonts x otherwise breaks Calibri italic */
+      if ( CUR.compatibility_mode )
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+        CUR.zp0.org[point].x = TT_MulFix14( (FT_UInt32)distance,
+                                            CUR.GS.freeVector.x );
       CUR.zp0.org[point].y = TT_MulFix14( (FT_UInt32)distance,
                                           CUR.GS.freeVector.y ),
       CUR.zp0.cur[point]   = CUR.zp0.org[point];
     }
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( ( CUR.sph_tweak_flags & SPH_TWEAK_MIAP_HACK ) &&
+         distance > 0                                  &&
+         CUR.GS.freeVector.y != 0                      )
+      distance = 0;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
     org_dist = CUR_fast_project( &CUR.zp0.cur[point] );
 
     if ( ( CUR.opcode & 1 ) != 0 )   /* rounding and control cutin flag */
     {
-      if ( FT_ABS( distance - org_dist ) > CUR.GS.control_value_cutin )
+      if ( FT_ABS( distance - org_dist ) >
+             CUR.GS.control_value_cutin / gridlines_per_pixel )
         distance = org_dist;
 
-      distance = CUR_Func_round( distance, CUR.tt_metrics.compensations[0] );
+      distance = CUR_Func_round( distance,
+                                 CUR.tt_metrics.compensations[0],
+                                 gridlines_per_pixel );
     }
 
     CUR_Func_move( &CUR.zp0, point, distance - org_dist );
@@ -6097,7 +6464,25 @@
   Ins_MDRP( INS_ARG )
   {
     FT_UShort   point;
-    FT_F26Dot6  org_dist, distance;
+    FT_F26Dot6  org_dist, distance, new_distance;
+    FT_Int      minimum_distance_factor = 64;
+    FT_Int      gridlines_per_pixel     = 1;
+
+
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.ignore_x_mode )
+    {
+      if ( CUR.GS.freeVector.x != 0                          &&
+           !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
+      {
+        gridlines_per_pixel     = SPH_OPTION_GRIDLINES_PER_PIXEL_X;
+        minimum_distance_factor = 64 - gridlines_per_pixel / 3;
+      }
+      else if ( CUR.GS.freeVector.y != 0                          &&
+                !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_Y;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
 
     point = (FT_UShort)args[0];
@@ -6163,11 +6548,13 @@
     if ( ( CUR.opcode & 4 ) != 0 )
       distance = CUR_Func_round(
                    org_dist,
-                   CUR.tt_metrics.compensations[CUR.opcode & 3] );
+                   CUR.tt_metrics.compensations[CUR.opcode & 3],
+                   gridlines_per_pixel );
     else
       distance = ROUND_None(
                    org_dist,
-                   CUR.tt_metrics.compensations[CUR.opcode & 3] );
+                   CUR.tt_metrics.compensations[CUR.opcode & 3],
+                   gridlines_per_pixel );
 
     /* minimum distance flag */
 
@@ -6175,13 +6562,17 @@
     {
       if ( org_dist >= 0 )
       {
-        if ( distance < CUR.GS.minimum_distance )
-          distance = CUR.GS.minimum_distance;
+        new_distance = FT_MulDiv( minimum_distance_factor,
+                                  CUR.GS.minimum_distance, 64 );
+        if ( distance < new_distance )
+          distance = new_distance;
       }
       else
       {
-        if ( distance > -CUR.GS.minimum_distance )
-          distance = -CUR.GS.minimum_distance;
+        new_distance = -FT_MulDiv( minimum_distance_factor,
+                                  CUR.GS.minimum_distance, 64 );
+        if ( distance > new_distance )
+          distance = new_distance;
       }
     }
 
@@ -6215,13 +6606,42 @@
 
     FT_F26Dot6  cvt_dist,
                 distance,
+                new_distance,
                 cur_dist,
                 org_dist;
 
+    FT_Int      minimum_distance_factor = 64;
+    FT_Int      gridlines_per_pixel     = 1;
+
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    FT_Int      B1;
+    FT_Int      B2;
+    FT_Bool     reverse_move = FALSE;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
 
     point    = (FT_UShort)args[0];
     cvtEntry = (FT_ULong)( args[1] + 1 );
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.ignore_x_mode )
+    {
+      if ( CUR.GS.freeVector.x != 0                          &&
+           !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
+      {
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_X;
+        /* high value emboldens glyphs at lower ppems (< 14); */
+        /* Courier looks better with 52 --                    */
+        /* MS ClearType Rasterizer supposedly uses 32         */
+        minimum_distance_factor = 64 - gridlines_per_pixel / 3;
+      }
+
+      else if ( CUR.GS.freeVector.y != 0                          &&
+                !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
+        gridlines_per_pixel = SPH_OPTION_GRIDLINES_PER_PIXEL_Y;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     /* XXX: UNDOCUMENTED! cvt[-1] = 0 always */
 
     if ( BOUNDS( point,      CUR.zp1.n_points ) ||
@@ -6237,6 +6657,10 @@
       cvt_dist = 0;
     else
       cvt_dist = CUR_Func_read_cvt( cvtEntry - 1 );
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+      if ( CUR.sph_tweak_flags & SPH_TWEAK_MIRP_CVT_ZERO )
+        cvt_dist = 0;
+#endif
 
     /* single width test */
 
@@ -6274,8 +6698,17 @@
       if ( ( org_dist ^ cvt_dist ) < 0 )
         cvt_dist = -cvt_dist;
     }
-
-    /* control value cutin and round */
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.GS.freeVector.y != 0                                 &&
+         ( CUR.sph_tweak_flags & SPH_TWEAK_TIMES_NEW_ROMAN_HACK ) )
+    {
+      if ( cur_dist < -64 )
+        cvt_dist -= 16;
+      else if ( cur_dist > 64 && cur_dist < 84 )
+        cvt_dist += 32;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+    /* control value cut-in and round */
 
     if ( ( CUR.opcode & 4 ) != 0 )
     {
@@ -6296,18 +6729,21 @@
         /*      `ttinst2.doc', version 1.66, is thus incorrect since  */
         /*      it implies `>=' instead of `>'.                       */
 
-        if ( FT_ABS( cvt_dist - org_dist ) > CUR.GS.control_value_cutin )
+        if ( FT_ABS( cvt_dist - org_dist ) >
+               CUR.GS.control_value_cutin / gridlines_per_pixel )
           cvt_dist = org_dist;
       }
 
       distance = CUR_Func_round(
                    cvt_dist,
-                   CUR.tt_metrics.compensations[CUR.opcode & 3] );
+                   CUR.tt_metrics.compensations[CUR.opcode & 3],
+                   gridlines_per_pixel );
     }
     else
       distance = ROUND_None(
                    cvt_dist,
-                   CUR.tt_metrics.compensations[CUR.opcode & 3] );
+                   CUR.tt_metrics.compensations[CUR.opcode & 3],
+                   gridlines_per_pixel );
 
     /* minimum distance test */
 
@@ -6315,18 +6751,68 @@
     {
       if ( org_dist >= 0 )
       {
-        if ( distance < CUR.GS.minimum_distance )
-          distance = CUR.GS.minimum_distance;
+        new_distance = FT_MulDiv( minimum_distance_factor,
+                                  CUR.GS.minimum_distance, 64 );
+        if ( distance < new_distance )
+          distance = new_distance;
       }
       else
       {
-        if ( distance > -CUR.GS.minimum_distance )
-          distance = -CUR.GS.minimum_distance;
+        new_distance = -FT_MulDiv( minimum_distance_factor,
+                                  CUR.GS.minimum_distance, 64 );
+        if ( distance > new_distance )
+          distance = new_distance;
       }
     }
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    B1 = CUR.zp1.cur[point].y;
+
+    /* Round moves if necessary */
+    if ( CUR.ignore_x_mode                                          &&
+         CUR.GS.freeVector.y != 0                                   &&
+         ( CUR.sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) )
+      distance = FT_PIX_ROUND( B1 + distance - cur_dist ) - B1 + cur_dist;
+
+    if ( CUR.GS.freeVector.y != 0                               &&
+         ( CUR.opcode & 16 ) == 0                               &&
+         ( CUR.opcode & 8 ) == 0                                &&
+         ( CUR.sph_tweak_flags & SPH_TWEAK_COURIER_NEW_2_HACK ) )
+      distance +=64;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     CUR_Func_move( &CUR.zp1, point, distance - cur_dist );
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    B2 = CUR.zp1.cur[point].y;
+
+    /* Reverse move if necessary */
+    if ( CUR.ignore_x_mode )
+    {
+      if ( ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_OFFPIXEL_Y_MOVES ) &&
+           CUR.GS.freeVector.y != 0                                  &&
+           B1 % 64 == 0                                              &&
+           B2 % 64 != 0                                              )
+        reverse_move = TRUE;
+
+      if ( ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES ) &&
+           CUR.GS.freeVector.y != 0                                  &&
+           B2 % 64 != 0                                              &&
+           B1 % 64 != 0                                              )
+        reverse_move = TRUE;
+
+      if ( ( CUR.sph_tweak_flags &
+             SPH_TWEAK_DELTAP_SKIP_EXAGGERATED_VALUES ) &&
+           !reverse_move                                &&
+           abs ( B1 - B2 ) >= 64                        )
+        reverse_move = TRUE;
+    }
+
+    if ( reverse_move )
+      CUR_Func_move( &CUR.zp1, point, -( distance - cur_dist ) );
+
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
   Fail:
     CUR.GS.rp1 = CUR.GS.rp0;
 
@@ -6352,6 +6838,16 @@
     FT_UNUSED_ARG;
 
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.ignore_x_mode                                        &&
+         CUR.iup_called                                           &&
+         ( CUR.sph_tweak_flags & SPH_TWEAK_NO_ALIGNRP_AFTER_IUP ) )
+    {
+      CUR.error = TT_Err_Invalid_Reference;
+      goto Fail;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     if ( CUR.top < CUR.GS.loop ||
          BOUNDS( CUR.GS.rp0, CUR.zp0.n_points ) )
     {
@@ -6846,6 +7342,15 @@
     contour = 0;
     point   = 0;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.ignore_x_mode )
+    {
+      CUR.iup_called = 1;
+      if ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_IUP )
+        return;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     do
     {
       end_point   = CUR.pts.contours[contour] - CUR.pts.first_point;
@@ -6915,6 +7420,9 @@
     FT_UShort  A;
     FT_ULong   C;
     FT_Long    B;
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    FT_UShort  B1, B2;
+#endif
 
 
 #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
@@ -6988,7 +7496,68 @@
             B++;
           B = B * 64 / ( 1L << CUR.GS.delta_shift );
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+          /*
+           *  Allow delta move if
+           *
+           *  - not using ignore_x_mode rendering
+           *  - glyph is specifically set to allow it
+           *  - glyph is composite and freedom vector is not subpixel vector
+           */
+          if ( !CUR.ignore_x_mode                                   ||
+               ( CUR.sph_tweak_flags & SPH_TWEAK_ALWAYS_DO_DELTAP ) ||
+               ( CUR.is_composite && CUR.GS.freeVector.y != 0 )     )
+            CUR_Func_move( &CUR.zp0, A, B );
+
+          /* Otherwise apply subpixel hinting and compatibility mode rules */
+          else if ( CUR.ignore_x_mode )
+          {
+            if ( CUR.GS.freeVector.y != 0 )
+              B1 = CUR.zp0.cur[A].y;
+            else
+              B1 = CUR.zp0.cur[A].x;
+
+            /* Standard Subpixel Hinting:  Allow y move */
+            if ( !CUR.compatibility_mode && CUR.GS.freeVector.y != 0 )
+              CUR_Func_move( &CUR.zp0, A, B );
+
+            /* Compatibility Mode: Allow x or y move if point touched in
+                Y direction */
+            else if ( CUR.compatibility_mode                                  &&
+                      !( CUR.sph_tweak_flags & SPH_TWEAK_ALWAYS_SKIP_DELTAP ) )
+            {
+              /* save the y value of the point now; compare after move */
+              B1 = CUR.zp0.cur[A].y;
+
+              if ( ( CUR.sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) )
+                B = FT_PIX_ROUND( B1 + B ) - B1;
+
+              /*
+              *  Allow delta move if using compatibility_mode, IUP has not
+              *  been called, and point is touched on Y.
+              */
+              if ( !CUR.iup_called                            &&
+                   ( CUR.zp0.tags[A] & FT_CURVE_TAG_TOUCH_Y ) )
+                CUR_Func_move( &CUR.zp0, A, B );
+            }
+
+            B2 = CUR.zp0.cur[A].y;
+
+            /* Reverse this move if it results in a disallowed move */
+            if ( CUR.GS.freeVector.y != 0                     &&
+                 ( ( ( CUR.sph_tweak_flags &
+                        SPH_TWEAK_SKIP_OFFPIXEL_Y_MOVES ) &&
+                        B1 % 64 == 0                      &&
+                        B2 % 64 != 0                      ) ||
+                   ( ( CUR.sph_tweak_flags &
+                        SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES ) &&
+                        B1 % 64 != 0                      &&
+                        B2 % 64 != 0                      ) ) )
+              CUR_Func_move( &CUR.zp0, A, -B );
+          }
+#else
           CUR_Func_move( &CUR.zp0, A, B );
+#endif /* *TT_CONFIG_OPTION_SUBPIXEL_HINTING */
         }
       }
       else
@@ -7118,22 +7687,113 @@
 
     K = 0;
 
-    /* We return MS rasterizer version 1.7 for the font scaler. */
-    if ( ( args[0] & 1 ) != 0 )
-      K = 35;
-
-    /* Has the glyph been rotated? */
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    /********************************/
+    /* RASTERIZER VERSION           */
+    /* Selector Bit:  0             */
+    /* Return Bit(s): 0-7           */
+    /*                              */
+    if ( ( args[0] & 1 ) != 0 && CUR.ignore_x_mode )
+    {
+      K = CUR.rasterizer_version;
+#ifdef SPH_DEBUG_MORE_VERBOSE
+      printf(" SETTING AS %d\n", CUR.rasterizer_version );
+#endif
+    }
+    else
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+      if ( ( args[0] & 1 ) != 0 )
+        K = 35;
+
+    /********************************/
+    /* GLYPH ROTATED                */
+    /* Selector Bit:  1             */
+    /* Return Bit(s): 8             */
+    /*                              */
     if ( ( args[0] & 2 ) != 0 && CUR.tt_metrics.rotated )
       K |= 0x80;
 
-    /* Has the glyph been stretched? */
+    /********************************/
+    /* GLYPH STRETCHED              */
+    /* Selector Bit:  2             */
+    /* Return Bit(s): 9             */
+    /*                              */
     if ( ( args[0] & 4 ) != 0 && CUR.tt_metrics.stretched )
       K |= 1 << 8;
 
-    /* Are we hinting for grayscale? */
+    /********************************/
+    /* HINTING FOR GRAYSCALE        */
+    /* Selector Bit:  5             */
+    /* Return Bit(s): 12            */
+    /*                              */
     if ( ( args[0] & 32 ) != 0 && CUR.grayscale )
       K |= 1 << 12;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.ignore_x_mode && CUR.rasterizer_version >= 35 )
+    {
+      /********************************/
+      /* HINTING FOR GRAYSCALE        */
+      /* Selector Bit:  5             */
+      /* Return Bit(s): 12            */
+      /*                              */
+      if ( ( args[0] & 32 ) != 0 && CUR.grayscale_hinting )
+        K |= 1 << 12;
+
+      /********************************/
+      /* HINTING FOR SUBPIXEL         */
+      /* Selector Bit:  6             */
+      /* Return Bit(s): 13            */
+      /*                              */
+      if ( ( args[0] & 64 ) != 0        &&
+           CUR.subpixel_hinting         &&
+           CUR.rasterizer_version >= 37 )
+      {
+        K |= 1 << 13;
+
+        /* the stuff below is irrelevant if subpixel_hinting is not set */
+
+        /********************************/
+        /* COMPATIBLE WIDTHS ENABLED    */
+        /* Selector Bit:  7             */
+        /* Return Bit(s): 14            */
+        /*                              */
+        /* Functionality still needs to be added */
+        if ( ( args[0] & 128 ) != 0 && CUR.compatible_widths )
+          K |= 1 << 14;
+
+        /********************************/
+        /* SYMMETRICAL SMOOTHING        */
+        /* Selector Bit:  8             */
+        /* Return Bit(s): 15            */
+        /*                              */
+        /* Functionality still needs to be added */
+        if ( ( args[0] & 256 ) != 0 && CUR.symmetrical_smoothing )
+          K |= 1 << 15;
+
+        /********************************/
+        /* HINTING FOR BGR?             */
+        /* Selector Bit:  9             */
+        /* Return Bit(s): 16            */
+        /*                              */
+        /* Functionality still needs to be added */
+        if ( ( args[0] & 512 ) != 0 && CUR.bgr )
+          K |= 1 << 16;
+
+        if ( CUR.rasterizer_version >= 38 )
+        {
+          /********************************/
+          /* SUBPIXEL POSITIONED?         */
+          /* Selector Bit:  10            */
+          /* Return Bit(s): 17            */
+          /*                              */
+          /* Functionality still needs to be added */
+          if ( ( args[0] & 1024 ) != 0 && CUR.subpixel_positioned )
+            K |= 1 << 17;
+        }
+      }
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
     args[0] = K;
   }
 
@@ -7509,6 +8169,15 @@
     cur = *exc;
 #endif
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    if ( CUR.ignore_x_mode )
+    {
+      /* ensure some variables are set for this run */
+      CUR.iup_called        = FALSE;
+      CUR.in_delta_function = FALSE;
+    }
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     /* set CVT functions */
     CUR.tt_metrics.ratio = 0;
     if ( CUR.metrics.x_ppem != CUR.metrics.y_ppem )
@@ -7780,7 +8449,13 @@
           break;
 
         case 0x2B:  /* CALL */
-          Ins_CALL( EXEC_ARG_ args );
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+          if ( !CUR.ignore_x_mode                                         ||
+               !CUR.iup_called                                            ||
+               ( CUR.iup_called                                         &&
+                 !( CUR.sph_tweak_flags & SPH_TWEAK_NO_CALL_AFTER_IUP ) ) )
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+            Ins_CALL( EXEC_ARG_ args );
           break;
 
         case 0x2C:  /* FDEF */
@@ -7796,10 +8471,13 @@
           Ins_MDAP( EXEC_ARG_ args );
           break;
 
-
         case 0x30:  /* IUP */
         case 0x31:  /* IUP */
-          Ins_IUP( EXEC_ARG_ args );
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+          if ( CUR.ignore_x_mode )
+            CUR.iup_called = TRUE;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+            Ins_IUP( EXEC_ARG_ args );
           break;
 
         case 0x32:  /* SHP */
@@ -7958,7 +8636,13 @@
           break;
 
         case 0x5D:  /* DELTAP1 */
-          Ins_DELTAP( EXEC_ARG_ args );
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+          if ( !CUR.ignore_x_mode                                           ||
+               !CUR.iup_called                                              ||
+               ( CUR.iup_called                                           &&
+                 !( CUR.sph_tweak_flags & SPH_TWEAK_NO_DELTAP_AFTER_IUP ) ) )
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+            Ins_DELTAP( EXEC_ARG_ args );
           break;
 
         case 0x5E:  /* SDB */
diff --git a/src/truetype/ttinterp.h b/src/truetype/ttinterp.h
index 6d0fc03..adaab23 100644
--- a/src/truetype/ttinterp.h
+++ b/src/truetype/ttinterp.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    TrueType bytecode interpreter (specification).                       */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2010 by       */
+/*  Copyright 1996-2007, 2010, 2012 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -68,7 +68,8 @@ FT_BEGIN_HEADER
   /* Rounding function */
   typedef FT_F26Dot6
   (*TT_Round_Func)( EXEC_OP_ FT_F26Dot6  distance,
-                             FT_F26Dot6  compensation );
+                             FT_F26Dot6  compensation,
+                             FT_Int      resolution );
 
   /* Point displacement along the freedom vector routine */
   typedef void
@@ -107,6 +108,48 @@ FT_BEGIN_HEADER
   } TT_CallRec, *TT_CallStack;
 
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* These structures define rules used to tweak subpixel hinting for      */
+  /* various fonts.  "", 0, "", NULL value indicates to match any value.   */
+  /*                                                                       */
+
+#define MAX_NAME_SIZE      32
+#define MAX_CLASS_MEMBERS  100
+
+  typedef struct  SPH_TweakRule_
+  {
+    const char      family[MAX_NAME_SIZE];
+    const FT_UInt   ppem;
+    const char      style[MAX_NAME_SIZE];
+    const FT_ULong  glyph;
+
+  } SPH_TweakRule;
+
+
+  typedef struct  SPH_ScaleRule_
+  {
+    const char      family[MAX_NAME_SIZE];
+    const FT_UInt   ppem;
+    const char      style[MAX_NAME_SIZE];
+    const FT_ULong  glyph;
+    const FT_ULong  scale;
+
+  } SPH_ScaleRule;
+
+
+  typedef struct  Font_Class_
+  {
+    const char  name[MAX_NAME_SIZE];
+    const char  member[MAX_CLASS_MEMBERS][MAX_NAME_SIZE];
+
+  } Font_Class;
+
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
+
   /*************************************************************************/
   /*                                                                       */
   /* The main structure for the interpreter which collects all necessary   */
@@ -218,6 +261,41 @@ FT_BEGIN_HEADER
 
     FT_Bool            grayscale;      /* are we hinting for grayscale? */
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    TT_Round_Func      func_round_sphn;   /* subpixel rounding function */
+
+    FT_Bool            grayscale_hinting; /* Using grayscale hinting?      */
+    FT_Bool            subpixel_hinting;  /* Using subpixel hinting?       */
+    FT_Bool            native_hinting;    /* Using native hinting?         */
+    FT_Bool            ignore_x_mode;     /* Standard rendering mode for   */
+                                          /* subpixel hinting.  On if gray */
+                                          /* or subpixel hinting is on )   */
+    FT_Bool            compatibility_mode;/* Additional exceptions to      */
+                                          /* native TT rules for legacy    */
+                                          /* fonts.  Implies               */
+                                          /* ignore_x_mode.                */
+
+    /* The following 4 aren't fully implemented but here for MS rasterizer */
+    /* compatibility.                                                      */
+    FT_Bool            compatible_widths;     /* compatible widths?        */
+    FT_Bool            symmetrical_smoothing; /* symmetrical_smoothing?    */
+    FT_Bool            bgr;                   /* bgr instead of rgb?       */
+    FT_Bool            subpixel_positioned;   /* subpixel positioned       */
+                                              /* (DirectWrite ClearType)?  */
+
+    FT_Int             rasterizer_version;    /* MS rasterizer version */
+
+    FT_Bool            iup_called;            /* IUP called for glyph?  */
+    FT_Bool            in_delta_function;     /* inside an inline delta */
+                                              /* function?              */
+
+    FT_ULong           sph_tweak_flags;       /* flags to control */
+                                              /* hint tweaks      */
+
+    FT_Int             num_delta_funcs;
+    FT_ULong           inline_delta_funcs[5];
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
   } TT_ExecContextRec;
 
 
diff --git a/src/truetype/ttobjs.h b/src/truetype/ttobjs.h
index 47e4129..5a58bd2 100644
--- a/src/truetype/ttobjs.h
+++ b/src/truetype/ttobjs.h
@@ -173,11 +173,12 @@ FT_BEGIN_HEADER
   /*                                                                       */
   typedef struct  TT_DefRecord_
   {
-    FT_Int   range;      /* in which code range is it located? */
-    FT_Long  start;      /* where does it start?               */
-    FT_Long  end;        /* where does it end?                 */
-    FT_UInt  opc;        /* function #, or instruction code    */
-    FT_Bool  active;     /* is it active?                      */
+    FT_Int   range;        /* in which code range is it located?     */
+    FT_Long  start;        /* where does it start?                   */
+    FT_Long  end;          /* where does it end?                     */
+    FT_UInt  opc;          /* function #, or instruction code        */
+    FT_Bool  active;       /* is it active?                          */
+    FT_Bool  inline_delta; /* is function that defines inline delta? */
 
   } TT_DefRecord, *TT_DefArray;
 
@@ -190,7 +191,7 @@ FT_BEGIN_HEADER
   {
     FT_Fixed    xx, xy;     /* transformation matrix coefficients */
     FT_Fixed    yx, yy;
-    FT_F26Dot6  ox, oy;     /* offsets        */
+    FT_F26Dot6  ox, oy;     /* offsets                            */
 
   } TT_Transform;
 
diff --git a/src/truetype/ttsubpix.c b/src/truetype/ttsubpix.c
new file mode 100644
index 0000000..59a19a4
--- /dev/null
+++ b/src/truetype/ttsubpix.c
@@ -0,0 +1,280 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ttsubpix.c                                                             */
+/*                                                                         */
+/*    TrueType Subpixel Hinting.                                           */
+/*                                                                         */
+/*  Copyright 2010-2012 by                                                 */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+#include <ft2build.h>
+#include FT_INTERNAL_DEBUG_H
+#include FT_INTERNAL_CALC_H
+#include FT_INTERNAL_STREAM_H
+#include FT_INTERNAL_SFNT_H
+#include FT_TRUETYPE_TAGS_H
+#include FT_OUTLINE_H
+
+#include "ttsubpix.h"
+
+
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
+  FT_LOCAL_DEF( FT_Bool )
+  is_member_of_family_class( const FT_String*  detected_font_name,
+                             const FT_String*  rule_font_name )
+  {
+    FT_UInt  i, j;
+
+
+    /* Does font name match rule family? */
+    if ( strcmp( detected_font_name, rule_font_name ) == 0 )
+      return TRUE;
+
+    /* Is font name a wildcard ""? */
+    if ( strcmp( rule_font_name, "" ) == 0 )
+      return TRUE;
+
+    /* Is font name contained in a class list? */
+    for ( i = 0; i < FAMILY_CLASS_RULES_SIZE; i++ )
+    {
+      if ( strcmp( FAMILY_CLASS_Rules[i].name, rule_font_name ) == 0 )
+      {
+        for ( j = 0; j < MAX_CLASS_MEMBERS; j++ )
+        {
+          if ( strcmp( FAMILY_CLASS_Rules[i].member[j], "" ) == 0 )
+            continue;
+          if ( strcmp( FAMILY_CLASS_Rules[i].member[j],
+                       detected_font_name ) == 0 )
+            return TRUE;
+        }
+      }
+    }
+
+    return FALSE;
+  }
+
+
+  FT_LOCAL_DEF( FT_Bool )
+  is_member_of_style_class( const FT_String*  detected_font_style,
+                            const FT_String*  rule_font_style )
+  {
+    FT_UInt  i, j;
+
+
+    /* Does font style match rule style? */
+    if ( strcmp( detected_font_style, rule_font_style ) == 0 )
+      return TRUE;
+
+    /* Is font style a wildcard ""? */
+    if ( strcmp( rule_font_style, "" ) == 0 )
+      return TRUE;
+
+    /* Is font style contained in a class list? */
+    for ( i = 0; i < STYLE_CLASS_RULES_SIZE; i++ )
+    {
+      if ( strcmp( STYLE_CLASS_Rules[i].name, rule_font_style ) == 0 )
+      {
+        for ( j = 0; j < MAX_CLASS_MEMBERS; j++ )
+        {
+          if ( strcmp( STYLE_CLASS_Rules[i].member[j], "" ) == 0 )
+            continue;
+          if ( strcmp( STYLE_CLASS_Rules[i].member[j],
+                       detected_font_style ) == 0 )
+            return TRUE;
+        }
+      }
+    }
+
+    return FALSE;
+  }
+
+
+  FT_LOCAL_DEF( FT_Bool )
+  sph_test_tweak( TT_Face         face,
+                  FT_String*      family,
+                  FT_UInt         ppem,
+                  FT_String*      style,
+                  FT_UInt         glyph_index,
+                  SPH_TweakRule*  rule,
+                  FT_UInt         num_rules )
+  {
+    FT_UInt  i;
+
+
+    /* rule checks may be able to be optimized further */
+    for ( i = 0; i < num_rules; i++ )
+    {
+      if ( family                                                   &&
+           ( is_member_of_family_class ( family, rule[i].family ) ) )
+        if ( rule[i].ppem == 0    ||
+             rule[i].ppem == ppem )
+          if ( style                                             &&
+               is_member_of_style_class ( style, rule[i].style ) )
+            if ( rule[i].glyph == 0                                ||
+                 FT_Get_Char_Index( (FT_Face)face,
+                                    rule[i].glyph ) == glyph_index )
+        return TRUE;
+    }
+
+    return FALSE;
+  }
+
+
+  FT_LOCAL_DEF( FT_UInt )
+  scale_test_tweak( TT_Face         face,
+                    FT_String*      family,
+                    FT_UInt         ppem,
+                    FT_String*      style,
+                    FT_UInt         glyph_index,
+                    SPH_ScaleRule*  rule,
+                    FT_UInt         num_rules )
+  {
+    FT_UInt  i;
+
+
+    /* rule checks may be able to be optimized further */
+    for ( i = 0; i < num_rules; i++ )
+    {
+      if ( family                                                   &&
+           ( is_member_of_family_class ( family, rule[i].family ) ) )
+        if ( rule[i].ppem == 0    ||
+             rule[i].ppem == ppem )
+          if ( style                                            &&
+               is_member_of_style_class( style, rule[i].style ) )
+            if ( rule[i].glyph == 0                                ||
+                 FT_Get_Char_Index( (FT_Face)face,
+                                    rule[i].glyph ) == glyph_index )
+        return rule[i].scale;
+    }
+
+    return 1000;
+  }
+
+
+#define TWEAK_RULES( x )                                       \
+  if ( sph_test_tweak( face, family, ppem, style, glyph_index, \
+                       x##_Rules, x##_RULES_SIZE ) )           \
+    loader->exec->sph_tweak_flags |= SPH_TWEAK_##x;
+
+#define TWEAK_RULES_EXCEPTIONS( x )                                        \
+  if ( sph_test_tweak( face, family, ppem, style, glyph_index,             \
+                       x##_Rules_Exceptions, x##_RULES_EXCEPTIONS_SIZE ) ) \
+    loader->exec->sph_tweak_flags &= ~SPH_TWEAK_##x;
+
+
+  FT_LOCAL_DEF( void )
+  sph_set_tweaks( TT_Loader  loader,
+                  FT_UInt    glyph_index )
+  {
+    TT_Face     face   = (TT_Face)loader->face;
+    FT_String*  family = face->root.family_name;
+    int         ppem   = loader->size->metrics.x_ppem;
+    FT_String*  style  = face->root.style_name;
+
+
+    /* don't apply rules if style isn't set */
+    if ( !face->root.style_name )
+      return;
+
+#ifdef SPH_DEBUG_MORE_VERBOSE
+    printf( "%s,%d,%s,%c=%d ",
+            family, ppem, style, glyph_index, glyph_index );
+#endif
+
+    TWEAK_RULES( PIXEL_HINTING );
+
+    if ( loader->exec->sph_tweak_flags & SPH_TWEAK_PIXEL_HINTING )
+    {
+      loader->exec->ignore_x_mode = FALSE;
+      return;
+    }
+
+    TWEAK_RULES( ALLOW_X_DMOVE );
+    TWEAK_RULES( ALLOW_X_DMOVEX );
+    TWEAK_RULES( ALLOW_X_MOVE_ZP2 );
+    TWEAK_RULES( ALWAYS_DO_DELTAP );
+    TWEAK_RULES( ALWAYS_SKIP_DELTAP );
+    TWEAK_RULES( DEEMBOLDEN );
+    TWEAK_RULES( DELTAP_SKIP_EXAGGERATED_VALUES );
+    TWEAK_RULES( DO_SHPIX );
+    TWEAK_RULES( EMBOLDEN );
+    TWEAK_RULES( MIAP_HACK );
+    TWEAK_RULES( NORMAL_ROUND );
+    TWEAK_RULES( NO_ALIGNRP_AFTER_IUP );
+    TWEAK_RULES( NO_CALL_AFTER_IUP );
+    TWEAK_RULES( NO_DELTAP_AFTER_IUP );
+    TWEAK_RULES( RASTERIZER_35 );
+    TWEAK_RULES( SKIP_INLINE_DELTAS );
+    TWEAK_RULES( SKIP_IUP );
+    TWEAK_RULES( MIRP_CVT_ZERO );
+
+    TWEAK_RULES( SKIP_OFFPIXEL_Y_MOVES );
+    TWEAK_RULES_EXCEPTIONS( SKIP_OFFPIXEL_Y_MOVES );
+
+    TWEAK_RULES( SKIP_NONPIXEL_Y_MOVES );
+    TWEAK_RULES_EXCEPTIONS( SKIP_NONPIXEL_Y_MOVES );
+
+    TWEAK_RULES( ROUND_NONPIXEL_Y_MOVES );
+    TWEAK_RULES_EXCEPTIONS( ROUND_NONPIXEL_Y_MOVES );
+
+    if ( loader->exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 )
+    {
+      if ( loader->exec->rasterizer_version != 35 )
+      {
+        loader->exec->rasterizer_version = 35;
+        /* must re-execute fpgm */
+        loader->exec->size->cvt_ready = FALSE;
+        tt_size_ready_bytecode(
+          loader->exec->size,
+          FT_BOOL( loader->load_flags & FT_LOAD_PEDANTIC ) );
+      }
+    }
+    else
+    {
+      if ( loader->exec->rasterizer_version == 35 )
+      {
+        loader->exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION;
+        /* must re-execute fpgm */
+        loader->exec->size->cvt_ready = FALSE;
+        tt_size_ready_bytecode(
+          loader->exec->size,
+          FT_BOOL( loader->load_flags & FT_LOAD_PEDANTIC ) );
+      }
+    }
+
+    if ( IS_HINTED( loader->load_flags ) )
+    {
+      TWEAK_RULES( TIMES_NEW_ROMAN_HACK );
+      TWEAK_RULES( COURIER_NEW_2_HACK );
+    }
+
+    if ( sph_test_tweak( face, family, ppem, style, glyph_index,
+           COMPATIBILITY_MODE_Rules, COMPATIBILITY_MODE_RULES_SIZE ) )
+    {
+      loader->exec->compatibility_mode |= TRUE;
+      loader->exec->ignore_x_mode      |= TRUE;
+    }
+    else
+      loader->exec->compatibility_mode &= FALSE;
+
+    if ( IS_HINTED( loader->load_flags ) )
+    {
+      if ( sph_test_tweak( face, family, ppem, style, glyph_index,
+             COMPATIBLE_WIDTHS_Rules, COMPATIBLE_WIDTHS_RULES_SIZE ) )
+        loader->exec->compatible_widths |= TRUE;
+    }
+  }
+
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
+
+/* END */
diff --git a/src/truetype/ttsubpix.h b/src/truetype/ttsubpix.h
new file mode 100644
index 0000000..7e9d501
--- /dev/null
+++ b/src/truetype/ttsubpix.h
@@ -0,0 +1,897 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ttsubpix.h                                                             */
+/*                                                                         */
+/*    TrueType Subpixel Hinting.                                           */
+/*                                                                         */
+/*  Copyright 2010-2012 by                                                 */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+#ifndef __TTSUBPIX_H__
+#define __TTSUBPIX_H__
+
+#include <ft2build.h>
+#include "ttobjs.h"
+#include "ttinterp.h"
+
+
+FT_BEGIN_HEADER
+
+
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* Tweak flags that are set for each glyph by the below rules.           */
+  /*                                                                       */
+  /*                                                                       */
+#define SPH_TWEAK_ALLOW_X_DMOVE                   0x0000001
+#define SPH_TWEAK_ALLOW_X_DMOVEX                  0x0000002
+#define SPH_TWEAK_ALLOW_X_MOVE_ZP2                0x0000004
+#define SPH_TWEAK_ALWAYS_DO_DELTAP                0x0000008
+#define SPH_TWEAK_ALWAYS_SKIP_DELTAP              0x0000010
+#define SPH_TWEAK_COURIER_NEW_2_HACK              0x0000020
+#define SPH_TWEAK_DEEMBOLDEN                      0x0000040
+#define SPH_TWEAK_DELTAP_SKIP_EXAGGERATED_VALUES  0x0000080
+#define SPH_TWEAK_DO_SHPIX                        0x0000100
+#define SPH_TWEAK_EMBOLDEN                        0x0000200
+#define SPH_TWEAK_MIAP_HACK                       0x0000400
+#define SPH_TWEAK_NORMAL_ROUND                    0x0000800
+#define SPH_TWEAK_NO_ALIGNRP_AFTER_IUP            0x0001000
+#define SPH_TWEAK_NO_CALL_AFTER_IUP               0x0002000
+#define SPH_TWEAK_NO_DELTAP_AFTER_IUP             0x0004000
+#define SPH_TWEAK_PIXEL_HINTING                   0x0008000
+#define SPH_TWEAK_RASTERIZER_35                   0x0010000
+#define SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES          0x0020000
+#define SPH_TWEAK_SKIP_INLINE_DELTAS              0x0040000
+#define SPH_TWEAK_SKIP_IUP                        0x0080000
+#define SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES           0x0100000
+#define SPH_TWEAK_SKIP_OFFPIXEL_Y_MOVES           0x0200000
+#define SPH_TWEAK_TIMES_NEW_ROMAN_HACK            0x0400000
+#define SPH_TWEAK_MIRP_CVT_ZERO                   0x0800000
+
+
+  FT_LOCAL( FT_Bool )
+  sph_test_tweak( TT_Face         face,
+                  FT_String*      family,
+                  FT_UInt         ppem,
+                  FT_String*      style,
+                  FT_UInt         glyph_index,
+                  SPH_TweakRule*  rule,
+                  FT_UInt         num_rules );
+
+  FT_LOCAL_DEF( FT_UInt )
+  scale_test_tweak( TT_Face         face,
+                    FT_String*      family,
+                    FT_UInt         ppem,
+                    FT_String*      style,
+                    FT_UInt         glyph_index,
+                    SPH_ScaleRule*  rule,
+                    FT_UInt         num_rules );
+
+  FT_LOCAL( void )
+  sph_set_tweaks( TT_Loader  loader,
+                  FT_UInt    glyph_index );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* These rules affect how the TT Interpreter does hinting, with the      */
+  /* goal of doing subpixel hinting by (in general) ignoring x moves.      */
+  /* Some of these rules are fixes that go above and beyond the            */
+  /* stated techniques in the MS whitepaper on Cleartype, due to           */
+  /* artifacts in many glyphs.  So, these rules make some glyphs render    */
+  /* better than they do in the MS rasterizer.                             */
+  /*                                                                       */
+  /* "" string or 0 int/char indicates to apply to all glyphs.             */
+  /* "-" used as dummy placeholders, but any non-matching string works.    */
+  /*                                                                       */
+  /* Some of this could arguably be implemented in fontconfig, however:    */
+  /*                                                                       */
+  /*  - Fontconfig can't set things on a glyph-by-glyph basis.             */
+  /*  - The tweaks that happen here are very low-level, from an average    */
+  /*    user's point of view and are best implemented in the hinter.       */
+  /*                                                                       */
+  /* The goal is to make the subpixel hinting techniques as generalized    */
+  /* as possible across all fonts to prevent the need for extra rules such */
+  /* as these.                                                             */
+  /*                                                                       */
+  /* The rule structure is designed so that entirely new rules can easily  */
+  /* be added when a new compatibility feature is discovered.              */
+  /*                                                                       */
+  /* The rule structures could also use some enhancement to handle ranges. */
+  /*                                                                       */
+  /*     ****************** WORK IN PROGRESS *******************           */
+  /*                                                                       */
+
+  /* These macros are defined absent a method for setting them */
+#define SPH_OPTION_BITMAP_WIDTHS           FALSE
+#define SPH_OPTION_SET_SUBPIXEL            TRUE
+#define SPH_OPTION_SET_GRAYSCALE           FALSE
+#define SPH_OPTION_SET_COMPATIBLE_WIDTHS   FALSE
+#define SPH_OPTION_SET_RASTERIZER_VERSION  38
+#define SPH_OPTION_GRIDLINES_PER_PIXEL_X   64
+#define SPH_OPTION_GRIDLINES_PER_PIXEL_Y   1
+
+
+  /* Define this to force natural (i.e. not bitmap-compatible) widths.     */
+  /* The default leans strongly towards natural widths except for a few    */
+  /* legacy fonts where a selective combination produces nicer results.    */
+/* #define FORCE_NATURAL_WIDTHS   */
+
+
+  /* These are `classes' of fonts that can be grouped together and used in */
+  /* rules below.  A blank entry "" is required at the end of these!       */
+#define FAMILY_CLASS_RULES_SIZE  7
+
+  Font_Class FAMILY_CLASS_Rules
+               [FAMILY_CLASS_RULES_SIZE] =
+  {
+    { "MS Legacy Fonts",
+      { "Aharoni",
+        "Andale Mono",
+        "Andalus",
+        "Angsana New",
+        "AngsanaUPC",
+        "Arabic Transparent",
+        "Arial Black",
+        "Arial Narrow",
+        "Arial Unicode MS",
+        "Arial",
+        "Batang",
+        "Browallia New",
+        "BrowalliaUPC",
+        "Comic Sans MS",
+        "Cordia New",
+        "CordiaUPC",
+        "Courier New",
+        "DFKai-SB",
+        "David Transparent",
+        "David",
+        "DilleniaUPC",
+        "Estrangelo Edessa",
+        "EucrosiaUPC",
+        "FangSong_GB2312",
+        "Fixed Miriam Transparent",
+        "FrankRuehl",
+        "Franklin Gothic Medium",
+        "FreesiaUPC",
+        "Garamond",
+        "Gautami",
+        "Georgia",
+        "Gulim",
+        "Impact",
+        "IrisUPC",
+        "JasmineUPC",
+        "KaiTi_GB2312",
+        "KodchiangUPC",
+        "Latha",
+        "Levenim MT",
+        "LilyUPC",
+        "Lucida Console",
+        "Lucida Sans Unicode",
+        "MS Gothic",
+        "MS Mincho",
+        "MV Boli",
+        "Mangal",
+        "Marlett",
+        "Microsoft Sans Serif",
+        "Mingliu",
+        "Miriam Fixed",
+        "Miriam Transparent",
+        "Miriam",
+        "Narkisim",
+        "Palatino Linotype",
+        "Raavi",
+        "Rod Transparent",
+        "Rod",
+        "Shruti",
+        "SimHei",
+        "Simplified Arabic Fixed",
+        "Simplified Arabic",
+        "Simsun",
+        "Sylfaen",
+        "Symbol",
+        "Tahoma",
+        "Times New Roman",
+        "Traditional Arabic",
+        "Trebuchet MS",
+        "Tunga",
+        "Verdana",
+        "Webdings",
+        "Wingdings",
+        "",
+      },
+    },
+    { "Core MS Legacy Fonts",
+      { "Arial Black",
+        "Arial Narrow",
+        "Arial Unicode MS",
+        "Arial",
+        "Comic Sans MS",
+        "Courier New",
+        "Garamond",
+        "Georgia",
+        "Impact",
+        "Lucida Console",
+        "Lucida Sans Unicode",
+        "Microsoft Sans Serif",
+        "Palatino Linotype",
+        "Tahoma",
+        "Times New Roman",
+        "Trebuchet MS",
+        "Verdana",
+        "",
+      },
+    },
+    { "Apple Legacy Fonts",
+      { "Geneva",
+        "Times",
+        "Monaco",
+        "Century",
+        "Chalkboard",
+        "Lobster",
+        "Century Gothic",
+        "Optima",
+        "Lucida Grande",
+        "Gill Sans",
+        "Baskerville",
+        "Helvetica",
+        "Helvetica Neue",
+        "",
+      },
+    },
+    { "Legacy Sans Fonts",
+      { "Andale Mono",
+        "Arial Unicode MS",
+        "Arial",
+        "Century Gothic",
+        "Comic Sans MS",
+        "Franklin Gothic Medium",
+        "Geneva",
+        "Lucida Console",
+        "Lucida Grande",
+        "Lucida Sans Unicode",
+        "Microsoft Sans Serif",
+        "Monaco",
+        "Tahoma",
+        "Trebuchet MS",
+        "Verdana",
+        "",
+      },
+    },
+
+    { "Misc Legacy Fonts",
+      { "Dark Courier", "", }, },
+    { "Verdana Clones",
+      { "DejaVu Sans",
+        "Bitstream Vera Sans", "", }, },
+    { "Verdana and Clones",
+      { "DejaVu Sans",
+        "Bitstream Vera Sans",
+        "Verdana", "", }, },
+  };
+
+
+  /* Define `classes' of styles that can be grouped together and used in   */
+  /* rules below.  A blank entry "" is required at the end of these!       */
+#define STYLE_CLASS_RULES_SIZE  5
+
+  Font_Class STYLE_CLASS_Rules
+               [STYLE_CLASS_RULES_SIZE] =
+  {
+    { "Regular Class",
+      { "Regular",
+        "Book",
+        "Medium",
+        "Roman",
+        "Normal",
+        "",
+      },
+    },
+    { "Regular/Italic Class",
+      { "Regular",
+        "Book",
+        "Medium",
+        "Italic",
+        "Oblique",
+        "Roman",
+        "Normal",
+        "",
+      },
+    },
+    { "Bold/BoldItalic Class",
+      { "Bold",
+        "Bold Italic",
+        "Black",
+        "",
+      },
+    },
+    { "Bold/Italic/BoldItalic Class",
+      { "Bold",
+        "Bold Italic",
+        "Black",
+        "Italic",
+        "Oblique",
+        "",
+      },
+    },
+    { "Regular/Bold Class",
+      { "Regular",
+        "Book",
+        "Medium",
+        "Normal",
+        "Roman",
+        "Bold",
+        "Black",
+        "",
+      },
+    },
+  };
+
+
+  /* Special fixes for known legacy fonts;                                 */
+  /* this is the primary workhorse rule for legacy fonts                   */
+#define COMPATIBILITY_MODE_RULES_SIZE  4
+
+  SPH_TweakRule  COMPATIBILITY_MODE_Rules
+                   [COMPATIBILITY_MODE_RULES_SIZE] =
+  {
+    { "MS Legacy Fonts", 0, "", 0 },
+    { "Apple Legacy Fonts", 0, "", 0 },
+    { "Misc Legacy Fonts", 0, "", 0 },
+    { "Verdana Clones", 0, "", 0 },
+  };
+
+
+  /* Don't do subpixel (ignore_x_mode) hinting; do normal hinting.         */
+#define PIXEL_HINTING_RULES_SIZE  4
+
+  SPH_TweakRule  PIXEL_HINTING_Rules
+                   [PIXEL_HINTING_RULES_SIZE] =
+  {
+    /* these characters are almost always safe */
+    { "", 0, "", '<' },
+    { "", 0, "", '>' },
+    /* fixes the vanishing stem */
+    { "Times New Roman", 0, "Bold", 'A' },
+    { "Times New Roman", 0, "Bold", 'V' },
+  };
+
+
+  /* According to Greg Hitchcock and the MS whitepaper, this should work   */
+  /* on all legacy MS fonts, but creates artifacts with some.  Only using  */
+  /* where absolutely necessary.                                           */
+#define SKIP_INLINE_DELTAS_RULES_SIZE  1
+
+  SPH_TweakRule  SKIP_INLINE_DELTAS_Rules
+                   [SKIP_INLINE_DELTAS_RULES_SIZE] =
+  {
+    { "-", 0, "", 0 },
+  };
+
+
+  /* Subpixel hinting ignores SHPIX rules on X.  Force SHPIX for these.    */
+#define DO_SHPIX_RULES_SIZE  1
+
+  SPH_TweakRule  DO_SHPIX_Rules
+                   [DO_SHPIX_RULES_SIZE] =
+  {
+    { "-", 0, "", 0 },
+  };
+
+
+  /* Skip Y moves that start with a point that is not on a Y pixel         */
+  /* boundary and don't move that point to a Y pixel boundary.             */
+#define SKIP_NONPIXEL_Y_MOVES_RULES_SIZE  9
+
+  SPH_TweakRule  SKIP_NONPIXEL_Y_MOVES_Rules
+                   [SKIP_NONPIXEL_Y_MOVES_RULES_SIZE] =
+  {
+    /* fix vwxyz thinness*/
+    { "Consolas", 0, "Regular", 0 },
+    /* fix tiny gap at top of m */
+    { "Arial", 0, "Regular", 'm' },
+    /* Fix thin middle stems */
+    { "Core MS Legacy Fonts", 0, "Regular/Bold Class", 'N' },
+    { "Lucida Grande", 0, "", 'N' },
+    { "Lucida Grande", 0, "Bold", 'y' },
+    /* Cyrillic small letter I */
+    { "Legacy Sans Fonts", 0, "", 0x438 },
+    { "Verdana Clones", 0, "",'N' },
+    { "Ubuntu", 0, "Regular Class", 'N' },
+    /* Fix misshapen x */
+    { "Verdana", 0, "Bold", 'x' },
+  };
+
+
+#define SKIP_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE  5
+
+  SPH_TweakRule  SKIP_NONPIXEL_Y_MOVES_Rules_Exceptions
+                   [SKIP_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE] =
+  {
+    { "Tahoma", 0, "", 'N' },
+    { "Comic Sans MS", 0, "", 'N' },
+    { "Verdana", 0, "Regular/Bold Class", 'N' },
+    { "Verdana", 11, "Bold", 'x' },
+    /* Cyrillic small letter I */
+    { "Arial", 0, "", 0x438 },
+  };
+
+
+  /* Skip Y moves that move a point off a Y pixel boundary.                */
+  /* This fixes Tahoma, Trebuchet oddities and some issues with `$'.       */
+#define SKIP_OFFPIXEL_Y_MOVES_RULES_SIZE  5
+
+  SPH_TweakRule  SKIP_OFFPIXEL_Y_MOVES_Rules
+                   [SKIP_OFFPIXEL_Y_MOVES_RULES_SIZE] =
+  {
+    { "MS Legacy Fonts", 0, "", 0 },
+    { "Apple Legacy Fonts", 0, "", 0 },
+    { "Misc Legacy Fonts", 0, "", 0 },
+    { "Ubuntu", 0, "Regular Class", 0 },
+    { "Verdana Clones", 0, "", 0 },
+  };
+
+
+#define SKIP_OFFPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE  1
+
+  SPH_TweakRule  SKIP_OFFPIXEL_Y_MOVES_Rules_Exceptions
+                   [SKIP_OFFPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE] =
+  {
+    { "-", 0, "", 0 },
+  };
+
+
+  /* Round moves that don't move a point to a Y pixel boundary.            */
+#define ROUND_NONPIXEL_Y_MOVES_RULES_SIZE  3
+
+  SPH_TweakRule  ROUND_NONPIXEL_Y_MOVES_Rules
+                   [ROUND_NONPIXEL_Y_MOVES_RULES_SIZE] =
+  {
+    /* Droid font instructions don't snap Y to pixels */
+    { "Droid Sans", 0, "Regular/Italic Class", 0 },
+    { "Droid Sans Mono", 0, "", 0 },
+    { "Ubuntu", 0, "", 0 },
+  };
+
+
+#define ROUND_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE  3
+
+  SPH_TweakRule  ROUND_NONPIXEL_Y_MOVES_Rules_Exceptions
+                   [ROUND_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE] =
+  {
+    { "Droid Sans", 12, "Bold", 0 },
+    { "Droid Sans", 13, "Bold", 0 },
+    { "Droid Sans", 16, "Bold", 0 },
+  };
+
+
+  /* Allow a Direct_Move_X along X freedom vector if matched.              */
+#define ALLOW_X_DMOVEX_RULES_SIZE  2
+
+  SPH_TweakRule  ALLOW_X_DMOVEX_Rules
+                   [ALLOW_X_DMOVEX_RULES_SIZE] =
+  {
+    /* Creates a more consistent appearance for these */
+    { "Arial", 13, "Regular", 'e' },
+    { "Arial", 13, "Regular", 'o' },
+  };
+
+
+  /* Allow a Direct_Move along X freedom vector if matched.                */
+#define ALLOW_X_DMOVE_RULES_SIZE  3
+
+  SPH_TweakRule  ALLOW_X_DMOVE_Rules
+                   [ALLOW_X_DMOVE_RULES_SIZE] =
+  {
+    /* Creates a more consistent appearance for these */
+    { "Arial", 13, "Regular", 'e' },
+    { "Arial", 13, "Regular", 'o' },
+    /* Fixes vanishing diagonal in 4 */
+    { "Verdana", 0, "Regular", '4' },
+  };
+
+
+  /* Allow a ZP2 move along freedom vector if matched;                     */
+  /* This is called from SHP, SHPIX, SHC, SHZ.                             */
+#define ALLOW_X_MOVE_ZP2_RULES_SIZE  1
+
+  SPH_TweakRule  ALLOW_X_MOVE_ZP2_Rules
+                   [ALLOW_X_MOVE_ZP2_RULES_SIZE] =
+  {
+    { "-", 0, "", 0 },
+  };
+
+
+  /* Return MS rasterizer version 35 if matched.                           */
+#define RASTERIZER_35_RULES_SIZE  8
+
+  SPH_TweakRule  RASTERIZER_35_Rules
+                   [RASTERIZER_35_RULES_SIZE] =
+  {
+    /* This seems to be the only way to make these look good */
+    { "Times New Roman", 0, "Regular", 'i' },
+    { "Times New Roman", 0, "Regular", 'j' },
+    { "Times New Roman", 0, "Regular", 'm' },
+    { "Times New Roman", 0, "Regular", 'r' },
+    { "Times New Roman", 0, "Regular", 'a' },
+    { "Times New Roman", 0, "Regular", 'n' },
+    { "Times New Roman", 0, "Regular", 'p' },
+    { "Times", 0, "", 0 },
+  };
+
+
+  /* Don't round to the subpixel grid.  Round to pixel grid.               */
+#define NORMAL_ROUND_RULES_SIZE  2
+
+  SPH_TweakRule  NORMAL_ROUND_Rules
+                   [NORMAL_ROUND_RULES_SIZE] =
+  {
+    /* Fix point "explosions" */
+    { "Courier New", 0, "", 0 },
+    { "Verdana", 10, "Regular", '4' },
+  };
+
+
+  /* Skip IUP instructions if matched.                                     */
+#define SKIP_IUP_RULES_SIZE  1
+
+  SPH_TweakRule  SKIP_IUP_Rules
+                   [SKIP_IUP_RULES_SIZE] =
+                 {
+                   { "Arial", 13, "Regular", 'a' },
+                 };
+
+
+  /* Skip MIAP Twilight hack if matched.                                   */
+#define MIAP_HACK_RULES_SIZE  1
+
+  SPH_TweakRule  MIAP_HACK_Rules
+                   [MIAP_HACK_RULES_SIZE] =
+  {
+    { "Geneva", 12, "", 0 },
+  };
+
+
+  /* Skip DELTAP instructions if matched.                                  */
+#define ALWAYS_SKIP_DELTAP_RULES_SIZE  13
+
+  SPH_TweakRule  ALWAYS_SKIP_DELTAP_Rules
+                   [ALWAYS_SKIP_DELTAP_RULES_SIZE] =
+  {
+    { "Georgia", 0, "Regular", 'k' },
+    /* fixes problems with W M w */
+    { "Trebuchet MS", 0, "Italic", 0 },
+    { "Trebuchet MS", 14, "Regular", 'e' },
+    { "Arial", 11, "Regular", 's' },
+    { "Verdana", 10, "Regular", 0 },
+    { "Verdana", 9, "Regular", 0 },
+    /* Cyrillic small letter short I */
+    { "Legacy Sans Fonts", 0, "", 0x439 },
+    { "Arial", 10, "Regular", '6' },
+    { "Arial", 0, "Bold/BoldItalic Class", 'a' },
+    /* Make horizontal stems consistent with the rest */
+    { "Arial", 24, "Bold", 's' },
+    { "Arial", 25, "Bold", 's' },
+    { "Arial", 24, "Bold", 'a' },
+    { "Arial", 25, "Bold", 'a' },
+  };
+
+
+  /* Always do DELTAP instructions if matched.                             */
+#define ALWAYS_DO_DELTAP_RULES_SIZE  2
+
+  SPH_TweakRule  ALWAYS_DO_DELTAP_Rules
+                   [ALWAYS_DO_DELTAP_RULES_SIZE] =
+  {
+    { "Verdana Clones", 17, "Regular Class", 'K' },
+    { "Verdana Clones", 17, "Regular Class", 'k' },
+  };
+
+
+  /* Do an extra RTG instruction in DELTAP if matched.                     */
+#define DELTAP_RTG_RULES_SIZE  1
+
+  SPH_TweakRule  DELTAP_RTG_Rules
+                   [DELTAP_RTG_RULES_SIZE] =
+  {
+    { "-", 0, "", 0 },
+  };
+
+
+  /* Force CVT distance to zero in MIRP.                                   */
+#define MIRP_CVT_ZERO_RULES_SIZE  1
+
+  SPH_TweakRule  MIRP_CVT_ZERO_Rules
+                   [MIRP_CVT_ZERO_RULES_SIZE] =
+  {
+    { "Verdana", 0, "Regular", 0 },
+  };
+
+
+  /* Skip moves that meet or exceed 1 pixel.                               */
+#define DELTAP_SKIP_EXAGGERATED_VALUES_RULES_SIZE  2
+
+  SPH_TweakRule  DELTAP_SKIP_EXAGGERATED_VALUES_Rules
+                   [DELTAP_SKIP_EXAGGERATED_VALUES_RULES_SIZE] =
+  {
+    /* Fix vanishing stems */
+    { "Ubuntu", 0, "Regular", 'M' },
+    /* Fix X at larger ppems */
+    { "Segoe UI", 0, "Light", 0 },
+  };
+
+
+  /* Don't allow ALIGNRP after IUP.                                        */
+#define NO_ALIGNRP_AFTER_IUP_RULES_SIZE  4
+
+  SPH_TweakRule  NO_ALIGNRP_AFTER_IUP_Rules
+                   [NO_ALIGNRP_AFTER_IUP_RULES_SIZE] =
+  {
+    /* Prevent creation of dents in outline */
+    { "Courier New", 0, "Bold", 'C' },
+    { "Courier New", 0, "Bold", 'D' },
+    { "Courier New", 0, "Bold", 'Q' },
+    { "Courier New", 0, "Bold", '0' },
+  };
+
+
+  /* Don't allow DELTAP after IUP.                                         */
+#define NO_DELTAP_AFTER_IUP_RULES_SIZE  2
+
+  SPH_TweakRule  NO_DELTAP_AFTER_IUP_Rules
+                   [NO_DELTAP_AFTER_IUP_RULES_SIZE] =
+  {
+    { "Arial", 0, "Bold", 'N' },
+    { "Verdana", 0, "Regular", '4' },
+  };
+
+
+  /* Don't allow CALL after IUP.                                           */
+#define NO_CALL_AFTER_IUP_RULES_SIZE  4
+
+  SPH_TweakRule  NO_CALL_AFTER_IUP_Rules
+                   [NO_CALL_AFTER_IUP_RULES_SIZE] =
+  {
+    /* Prevent creation of dents in outline */
+    { "Courier New", 0, "Bold", 'O' },
+    { "Courier New", 0, "Bold", 'Q' },
+    { "Courier New", 0, "Bold", 'k' },
+    { "Courier New", 0, "Bold Italic", 'M' },
+  };
+
+
+  /* De-embolden these glyphs slightly.                                    */
+#define DEEMBOLDEN_RULES_SIZE  9
+
+  SPH_TweakRule  DEEMBOLDEN_Rules
+                   [DEEMBOLDEN_RULES_SIZE] =
+  {
+    { "Courier New", 0, "Bold", 'A' },
+    { "Courier New", 0, "Bold", 'W' },
+    { "Courier New", 0, "Bold", 'w' },
+    { "Courier New", 0, "Bold", 'M' },
+    { "Courier New", 0, "Bold", 'X' },
+    { "Courier New", 0, "Bold", 'K' },
+    { "Courier New", 0, "Bold", 'x' },
+    { "Courier New", 0, "Bold", 'z' },
+    { "Courier New", 0, "Bold", 'v' },
+  };
+
+
+  /* Embolden these glyphs slightly.                                       */
+#define EMBOLDEN_RULES_SIZE  5
+
+  SPH_TweakRule  EMBOLDEN_Rules
+                   [EMBOLDEN_RULES_SIZE] =
+  {
+    { "Courier New", 12, "Italic", 'z' },
+    { "Courier New", 11, "Italic", 'z' },
+    { "Courier New", 10, "Italic", 'z' },
+    { "Courier New", 0, "Regular", 0 },
+    { "Courier New", 0, "Italic", 0 },
+  };
+
+
+  /* Do an extra RDTG instruction in DELTAP if matched.                    */
+#define DELTAP_RDTG_RULES_SIZE  1
+
+  SPH_TweakRule  DELTAP_RDTG_Rules
+                   [DELTAP_RDTG_RULES_SIZE] =
+  {
+    { "-", 0, "", 0 },
+  };
+
+
+  /* This is a CVT hack that makes thick horizontal stems on 2, 5, 7       */
+  /* similar to Windows XP.                                                */
+#define TIMES_NEW_ROMAN_HACK_RULES_SIZE  12
+
+  SPH_TweakRule  TIMES_NEW_ROMAN_HACK_Rules
+                   [TIMES_NEW_ROMAN_HACK_RULES_SIZE] =
+  {
+    { "Times New Roman", 16, "Italic", '2' },
+    { "Times New Roman", 16, "Italic", '5' },
+    { "Times New Roman", 16, "Italic", '7' },
+    { "Times New Roman", 16, "Regular", '2' },
+    { "Times New Roman", 16, "Regular", '5' },
+    { "Times New Roman", 16, "Regular", '7' },
+    { "Times New Roman", 17, "Italic", '2' },
+    { "Times New Roman", 17, "Italic", '5' },
+    { "Times New Roman", 17, "Italic", '7' },
+    { "Times New Roman", 17, "Regular", '2' },
+    { "Times New Roman", 17, "Regular", '5' },
+    { "Times New Roman", 17, "Regular", '7' },
+  };
+
+
+  /* This fudges distance on 2 to get rid of the vanishing stem issue.     */
+  /* A real solution to this is certainly welcome.                         */
+#define COURIER_NEW_2_HACK_RULES_SIZE  15
+
+  SPH_TweakRule  COURIER_NEW_2_HACK_Rules
+                   [COURIER_NEW_2_HACK_RULES_SIZE] =
+  {
+    { "Courier New", 10, "Regular", '2' },
+    { "Courier New", 11, "Regular", '2' },
+    { "Courier New", 12, "Regular", '2' },
+    { "Courier New", 13, "Regular", '2' },
+    { "Courier New", 14, "Regular", '2' },
+    { "Courier New", 15, "Regular", '2' },
+    { "Courier New", 16, "Regular", '2' },
+    { "Courier New", 17, "Regular", '2' },
+    { "Courier New", 18, "Regular", '2' },
+    { "Courier New", 19, "Regular", '2' },
+    { "Courier New", 20, "Regular", '2' },
+    { "Courier New", 21, "Regular", '2' },
+    { "Courier New", 22, "Regular", '2' },
+    { "Courier New", 23, "Regular", '2' },
+    { "Courier New", 24, "Regular", '2' },
+  };
+
+
+#ifndef FORCE_NATURAL_WIDTHS
+
+  /* Use compatible widths with these glyphs.  Compatible widths is always */
+  /* on when doing B/W TrueType instructing, but is used selectively here, */
+  /* typically on glyphs with 3 or more vertical stems.                    */
+#define COMPATIBLE_WIDTHS_RULES_SIZE  36
+
+  SPH_TweakRule  COMPATIBLE_WIDTHS_Rules
+                   [COMPATIBLE_WIDTHS_RULES_SIZE] =
+  {
+    { "Arial Unicode MS", 12, "Regular Class", 'm' },
+    { "Arial Unicode MS", 14, "Regular Class", 'm' },
+    /* Cyrillic small letter sha */
+    { "Arial", 10, "Regular Class", 0x448 },
+    { "Arial", 11, "Regular Class", 'm' },
+    { "Arial", 12, "Regular Class", 'm' },
+    /* Cyrillic small letter sha */
+    { "Arial", 12, "Regular Class", 0x448 },
+    { "Arial", 13, "Regular Class", 0x448 },
+    { "Arial", 14, "Regular Class", 'm' },
+    /* Cyrillic small letter sha */
+    { "Arial", 14, "Regular Class", 0x448 },
+    { "Arial", 15, "Regular Class", 0x448 },
+    { "Arial", 17, "Regular Class", 'm' },
+    { "DejaVu Sans", 15, "Regular Class", 0 },
+    { "Microsoft Sans Serif", 11, "Regular Class", 0 },
+    { "Microsoft Sans Serif", 12, "Regular Class", 0 },
+    { "Segoe UI", 11, "Regular Class", 0 },
+    { "Segoe UI", 12, "Regular Class", 'm' },
+    { "Segoe UI", 14, "Regular Class", 'm' },
+    { "Tahoma", 11, "Regular Class", 0 },
+    { "Times New Roman", 16, "Regular Class", 'c' },
+    { "Times New Roman", 16, "Regular Class", 'm' },
+    { "Times New Roman", 16, "Regular Class", 'o' },
+    { "Times New Roman", 16, "Regular Class", 'w' },
+    { "Trebuchet MS", 12, "Regular Class", 0 },
+    { "Trebuchet MS", 14, "Regular Class", 0 },
+    { "Trebuchet MS", 15, "Regular Class", 0 },
+    { "Ubuntu", 12, "Regular Class", 'm' },
+    /* Cyrillic small letter sha */
+    { "Verdana", 10, "Regular Class", 0x448 },
+    { "Verdana", 11, "Regular Class", 0x448 },
+    { "Verdana and Clones", 12, "Regular Class", 'm' },
+    { "Verdana and Clones", 12, "Regular Class", 'l' },
+    { "Verdana and Clones", 12, "Regular Class", 'i' },
+    { "Verdana and Clones", 12, "Regular Class", 'j' },
+    { "Verdana and Clones", 13, "Regular Class", 'l' },
+    { "Verdana and Clones", 13, "Regular Class", 'i' },
+    { "Verdana and Clones", 13, "Regular Class", 'j' },
+    { "Verdana and Clones", 14, "Regular Class", 'm' },
+  };
+
+
+  /* Scaling slightly in the x-direction prior to hinting results in       */
+  /* more visually pleasing glyphs in certain cases.                       */
+  /* This sometimes needs to be coordinated with compatible width rules.   */
+  /* A value of 1000 corresponds to a scaled value of 1.0.                 */
+#define X_SCALING_RULES_SIZE  40
+
+  SPH_ScaleRule  X_SCALING_Rules
+                   [X_SCALING_RULES_SIZE] =
+  {
+    { "DejaVu Sans", 12, "Regular Class", 'm', 950 },
+    { "Verdana and Clones", 12, "Regular Class", 'a', 1000 },
+    { "Arial", 11, "Regular Class", 'm', 975 },
+    { "Arial", 12, "Regular Class", 'm', 1050 },
+    /* Cyrillic small letter el */
+    { "Arial", 13, "Regular Class", 0x43B, 950 },
+    { "Arial", 14, "Regular Class", 'm', 950 },
+    /* Cyrillic small letter el */
+    { "Arial", 15, "Regular Class", 0x43B, 925 },
+    { "Bitstream Vera Sans", 10, "Regular/Italic Class", 0, 1100 },
+    { "Bitstream Vera Sans", 12, "Regular/Italic Class", 0, 1050 },
+    { "Bitstream Vera Sans", 16, "Regular Class", 0, 1050 },
+    { "Bitstream Vera Sans", 9, "Regular/Italic Class", 0, 1050 },
+    { "DejaVu Sans", 12, "Regular Class", 'l', 975 },
+    { "DejaVu Sans", 12, "Regular Class", 'i', 975 },
+    { "DejaVu Sans", 12, "Regular Class", 'j', 975 },
+    { "DejaVu Sans", 13, "Regular Class", 'l', 950 },
+    { "DejaVu Sans", 13, "Regular Class", 'i', 950 },
+    { "DejaVu Sans", 13, "Regular Class", 'j', 950 },
+    { "DejaVu Sans", 10, "Regular/Italic Class", 0, 1100 },
+    { "DejaVu Sans", 12, "Regular/Italic Class", 0, 1050 },
+    { "Georgia", 10, "", 0, 1050 },
+    { "Georgia", 11, "", 0, 1100 },
+    { "Georgia", 12, "", 0, 1025 },
+    { "Georgia", 13, "", 0, 1050 },
+    { "Georgia", 16, "", 0, 1050 },
+    { "Georgia", 17, "", 0, 1030 },
+    { "Liberation Sans", 12, "Regular Class", 'm', 1100 },
+    { "Lucida Grande", 11, "Regular Class", 'm', 1100 },
+    { "Microsoft Sans Serif", 11, "Regular Class", 'm', 950 },
+    { "Microsoft Sans Serif", 12, "Regular Class", 'm', 1050 },
+    { "Segoe UI", 12, "Regular Class", 'H', 1050 },
+    { "Segoe UI", 12, "Regular Class", 'm', 1050 },
+    { "Segoe UI", 14, "Regular Class", 'm', 1050 },
+    { "Tahoma", 11, "Regular Class", 'm', 975 },
+    { "Verdana", 10, "Regular/Italic Class", 0, 1100 },
+    { "Verdana", 12, "Regular Class", 'm', 975 },
+    { "Verdana", 12, "Regular/Italic Class", 0, 1050 },
+    { "Verdana", 16, "Regular Class", 0, 1050 },
+    { "Verdana", 9, "Regular/Italic Class", 0, 1050 },
+    { "Times New Roman", 16, "Regular Class", 'm', 950 },
+    { "Trebuchet MS", 12, "Regular Class", 'm', 950 },
+  };
+
+#else
+
+#define COMPATIBLE_WIDTHS_RULES_SIZE  1
+
+  SPH_TweakRule  COMPATIBLE_WIDTHS_Rules
+                   [COMPATIBLE_WIDTHS_RULES_SIZE] =
+  {
+    { "-", 0, "", 0 },
+  };
+
+
+#define X_SCALING_RULES_SIZE  1
+
+  SPH_ScaleRule  X_SCALING_Rules
+                   [X_SCALING_RULES_SIZE] =
+  {
+    { "-", 0, "", 0, 1000 },
+  };
+
+#endif /* FORCE_NATURAL_WIDTHS */
+
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
+
+FT_END_HEADER
+
+#endif /* __TTSUBPIX_H__ */
+
+/* END */