Commit 63bfa832576572c19ecd3ee03da26759d782474c

Infinality 2013-05-20T07:38:21

[truetype] Simplify and improve subpixel function detection. Some small enhancements have allowed the removal of many macros and the simplification of existing rules in `ttsubpix.c'. * src/truetype/ttsubpix.h (SPH_TWEAK_ALLOW_X_DMOVEX, SPH_TWEAK_ALLOW_X_MOVE_ZP2, SPH_TWEAK_DELTAP_SKIP_EXAGGERATED_VALUES, SPH_TWEAK_SKIP_INLINE_DELTAS, SPH_TWEAK_MIRP_CVT_ZERO): Removed. (SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES_DELTAP): New rule macro. * src/truetype/ttsubpix.c: Updated affected rules. * src/truetype/ttinterp.c (Direct_Move_X): Updated. (INS_FDEF): Add additional function detection. (INS_ENDF): Set runtime flag. (Ins_CALL): Skip the call under certain conditions. Remove bad code. (Ins_LOOPCALL): Skip the call under certain conditions. Remove bad code. (Move_Zp2_Point): Updated. (Ins_SHPIX): Updated. Skip the move under some situations. (Ins_MIAP): Improve conditions. (Ins_MIRP): Updated. (Ins_DELTAP): Skip move under certain conditions. Simplify conditions. (TT_RunIns): Updated. Add code to handle new function detection. Trace messages.

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
diff --git a/ChangeLog b/ChangeLog
index dcf35f5..310703b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2013-05-20  Infinality  <infinality@infinality.net>
+
+	[truetype] Simplify and improve subpixel function detection.
+
+	Some small enhancements have allowed the removal of many macros and
+	the simplification of existing rules in `ttsubpix.c'.
+
+	* src/truetype/ttsubpix.h (SPH_TWEAK_ALLOW_X_DMOVEX,
+	SPH_TWEAK_ALLOW_X_MOVE_ZP2,
+	SPH_TWEAK_DELTAP_SKIP_EXAGGERATED_VALUES,
+	SPH_TWEAK_SKIP_INLINE_DELTAS, SPH_TWEAK_MIRP_CVT_ZERO): Removed.
+	(SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES_DELTAP): New rule macro.
+
+	* src/truetype/ttsubpix.c: Updated affected rules.
+
+	* src/truetype/ttinterp.c (Direct_Move_X): Updated.
+	(INS_FDEF): Add additional function detection.
+	(INS_ENDF): Set runtime flag.
+	(Ins_CALL): Skip the call under certain conditions.
+	Remove bad code.
+	(Ins_LOOPCALL): Skip the call under certain conditions.
+	Remove bad code.
+	(Move_Zp2_Point): Updated.
+	(Ins_SHPIX): Updated.
+	Skip the move under some situations.
+	(Ins_MIAP): Improve conditions.
+	(Ins_MIRP): Updated.
+	(Ins_DELTAP): Skip move under certain conditions.
+	Simplify conditions.
+	(TT_RunIns): Updated.
+	Add code to handle new function detection.
+	Trace messages.
+
 2013-05-17  Werner Lemberg  <wl@gnu.org>
 
 	Update more FT_Err_XXX macros using FT_ERR and FT_THROW;
diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c
index 2e9cf64..437db22 100644
--- a/src/truetype/ttinterp.c
+++ b/src/truetype/ttinterp.c
@@ -1849,9 +1849,8 @@
     FT_UNUSED_EXEC;
 
 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-    if ( !SUBPIXEL_HINTING                                      ||
-         ( !CUR.ignore_x_mode                                 ||
-           ( CUR.sph_tweak_flags & SPH_TWEAK_ALLOW_X_DMOVEX ) ) )
+    if ( !SUBPIXEL_HINTING  ||
+         !CUR.ignore_x_mode )
 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
       zone->cur[point].x += distance;
 
@@ -4474,7 +4473,7 @@
 
 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
     /* arguments to opcodes are skipped by `SKIP_Code' */
-    FT_Byte    opcode_pattern[7][12] = {
+    FT_Byte    opcode_pattern[9][12] = {
                  /* #0 inline delta function 1 */
                  {
                    0x4B, /* PPEM    */
@@ -4552,10 +4551,23 @@
                    0x43, /* RS      */
                    0x58  /* IF      */
                  },
+                 /* #7 TypeMan Talk DiagEndCtrl function */
+                 {
+                   0x01, /* SVTCA_x */
+                   0x20, /* DUP     */
+                   0xB0, /* PUSHB_1 */
+                         /*   3     */
+                   0x25, /* CINDEX  */
+                 },
+                 /* #8 TypeMan Talk Align */
+                 {
+                   0x06, /* SPVTL   */
+                   0x7D, /* RDTG    */
+                 },
                };
-    FT_UShort  opcode_patterns   = 7;
-    FT_UShort  opcode_pointer[7] = {  0, 0, 0, 0, 0, 0, 0 };
-    FT_UShort  opcode_size[7]    = { 12, 8, 8, 6, 7, 4, 5 };
+    FT_UShort  opcode_patterns   = 9;
+    FT_UShort  opcode_pointer[9] = {  0, 0, 0, 0, 0, 0, 0, 0, 0 };
+    FT_UShort  opcode_size[9]    = { 12, 8, 8, 6, 7, 4, 5, 4, 2 };
     FT_UShort  i;
 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
@@ -4697,6 +4709,18 @@
                   CUR.face->sph_found_func_flags |= SPH_FDEF_SPACING_2;
                 }
                 break;
+
+               case 7:
+                 rec->sph_fdef_flags            |= SPH_FDEF_TYPEMAN_DIAGENDCTRL;
+                 CUR.face->sph_found_func_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL;
+                 break;
+
+               case 8:
+#if 0
+                 rec->sph_fdef_flags            |= SPH_FDEF_TYPEMAN_DIAGENDCTRL;
+                 CUR.face->sph_found_func_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL;
+#endif
+                 break;
               }
               opcode_pointer[i] = 0;
             }
@@ -4743,6 +4767,10 @@
     FT_UNUSED_ARG;
 
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    CUR.sph_in_func_flags = 0x0000;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
     if ( CUR.callTop <= 0 )     /* We encountered an ENDF without a call */
     {
       CUR.error = FT_THROW( ENDF_In_Exec_Stream );
@@ -4828,7 +4856,14 @@
       goto Fail;
 
 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-    CUR.sph_in_func_flags &= def->sph_fdef_flags;
+    if ( SUBPIXEL_HINTING                                              &&
+         CUR.ignore_x_mode                                             &&
+         ( ( CUR.iup_called                                        &&
+             ( CUR.sph_tweak_flags & SPH_TWEAK_NO_CALL_AFTER_IUP ) ) ||
+           ( def->sph_fdef_flags & SPH_FDEF_VACUFORM_ROUND_1 )       ) )
+      goto Fail;
+    else
+      CUR.sph_in_func_flags = def->sph_fdef_flags;
 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
     /* check the call stack */
@@ -4853,10 +4888,6 @@
 
     CUR.step_ins = FALSE;
 
-#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-    CUR.sph_in_func_flags &= !def->sph_fdef_flags;
-#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
-
     return;
 
   Fail:
@@ -4914,7 +4945,12 @@
       goto Fail;
 
 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-    CUR.sph_in_func_flags &= def->sph_fdef_flags;
+    if ( SUBPIXEL_HINTING                                    &&
+         CUR.ignore_x_mode                                   &&
+         ( def->sph_fdef_flags & SPH_FDEF_VACUFORM_ROUND_1 ) )
+      goto Fail;
+    else
+      CUR.sph_in_func_flags = def->sph_fdef_flags;
 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
     /* check stack */
@@ -4941,10 +4977,6 @@
       CUR.step_ins = FALSE;
     }
 
-#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-    CUR.sph_in_func_flags &= !def->sph_fdef_flags;
-#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
-
     return;
 
   Fail:
@@ -5794,10 +5826,8 @@
     if ( CUR.GS.freeVector.x != 0 )
     {
 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-      if ( !SUBPIXEL_HINTING                                            ||
-           ( !CUR.ignore_x_mode                                       ||
-             ( CUR.ignore_x_mode                                    &&
-               ( CUR.sph_tweak_flags & SPH_TWEAK_ALLOW_X_MOVE_ZP2 ) ) ) )
+      if ( !SUBPIXEL_HINTING  ||
+           !CUR.ignore_x_mode )
 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
         CUR.zp2.cur[point].x += dx;
 
@@ -6048,14 +6078,17 @@
           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.face->sph_compatibility_mode &&
                CUR.GS.freeVector.y != 0          )
             MOVE_Zp2_Point( point, dx, dy, TRUE );
 
+          else if ( CUR.sph_in_func_flags & SPH_FDEF_TYPEMAN_DIAGENDCTRL )
+          {
+            MOVE_Zp2_Point( point, dx, dy, TRUE );
+            /* don't allow reversals */
+            goto Skip;
+          }
+
           else if ( CUR.face->sph_compatibility_mode )
           {
             if ( CUR.sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES )
@@ -6064,6 +6097,12 @@
               dy = FT_PIX_ROUND( B1 + dy ) - B1;
             }
 
+            /* skip post-iup deltas */
+            if ( CUR.iup_called                                          &&
+                 ( ( CUR.sph_in_func_flags & SPH_FDEF_INLINE_DELTA_1 ) ||
+                   ( CUR.sph_in_func_flags & SPH_FDEF_INLINE_DELTA_2 ) ) )
+              goto Skip;
+
             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 )   ||
@@ -6253,6 +6292,7 @@
     if ( SUBPIXEL_HINTING                                  &&
          CUR.ignore_x_mode                                 &&
          CUR.GS.freeVector.x != 0                          &&
+         CUR.GS.freeVector.y == 0                          &&
          !( CUR.sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) )
       control_value_cutin = 0;
 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
@@ -6527,13 +6567,6 @@
     else
       cvt_dist = CUR_Func_read_cvt( cvtEntry - 1 );
 
-#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-    if ( SUBPIXEL_HINTING                                  &&
-         CUR.ignore_x_mode                                 &&
-         ( CUR.sph_tweak_flags & SPH_TWEAK_MIRP_CVT_ZERO ) )
-      cvt_dist = 0;
-#endif
-
     /* single width test */
 
     if ( FT_ABS( cvt_dist - CUR.GS.single_width_value ) <
@@ -6689,12 +6722,6 @@
              ( B2 & 63 ) != 0                                          &&
              ( B1 & 63 ) != 0                                          )
           reverse_move = TRUE;
-
-        if ( ( CUR.sph_tweak_flags                      &
-               SPH_TWEAK_DELTAP_SKIP_EXAGGERATED_VALUES ) &&
-             !reverse_move                                &&
-             FT_ABS( B1 - B2 ) >= 64                      )
-          reverse_move = TRUE;
       }
 
       if ( reverse_move )
@@ -7264,7 +7291,7 @@
     if ( SUBPIXEL_HINTING  &&
          CUR.ignore_x_mode )
     {
-      CUR.iup_called = 1;
+      CUR.iup_called = TRUE;
       if ( CUR.sph_tweak_flags & SPH_TWEAK_SKIP_IUP )
         return;
     }
@@ -7341,7 +7368,14 @@
     FT_Long    B;
 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
     FT_UShort  B1, B2;
-#endif
+
+
+    if ( SUBPIXEL_HINTING                                        &&
+         CUR.ignore_x_mode                                       &&
+         CUR.iup_called                                          &&
+         ( CUR.sph_tweak_flags & SPH_TWEAK_NO_DELTAP_AFTER_IUP ) )
+      goto Fail;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
 
 
 #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
@@ -7445,7 +7479,7 @@
               /* Standard Subpixel Hinting: Allow y move.       */
               /* This messes up dejavu and may not be needed... */
               if ( !CUR.face->sph_compatibility_mode &&
-                   CUR.GS.freeVector.y != 0           )
+                   CUR.GS.freeVector.y != 0          )
                 CUR_Func_move( &CUR.zp0, A, B );
               else
 #endif /* 0 */
@@ -7471,14 +7505,14 @@
               B2 = CUR.zp0.cur[A].y;
 
               /* Reverse this move if it results in a disallowed move */
-              if ( CUR.GS.freeVector.y != 0                    &&
-                   ( ( CUR.face->sph_compatibility_mode    &&
-                       ( B1 & 63 ) == 0                    &&
-                       ( B2 & 63 ) != 0                    ) ||
-                     ( ( CUR.sph_tweak_flags             &
-                         SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES ) &&
-                       ( B1 & 63 ) != 0                    &&
-                       ( B2 & 63 ) != 0                    ) ) )
+              if ( CUR.GS.freeVector.y != 0                           &&
+                   ( ( CUR.face->sph_compatibility_mode           &&
+                       ( B1 & 63 ) == 0                           &&
+                       ( B2 & 63 ) != 0                           ) ||
+                     ( ( CUR.sph_tweak_flags                    &
+                         SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES_DELTAP ) &&
+                       ( B1 & 63 ) != 0                           &&
+                       ( B2 & 63 ) != 0                           ) ) )
                 CUR_Func_move( &CUR.zp0, A, -B );
             }
           }
@@ -8098,6 +8132,20 @@
   {
     FT_Long  ins_counter = 0;  /* executed instructions counter */
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+    FT_Byte    opcode_pattern[1][2] = {
+                  /* #8 TypeMan Talk Align */
+                  {
+                    0x06, /* SPVTL   */
+                    0x7D, /* RDTG    */
+                  },
+                };
+    FT_UShort  opcode_patterns   = 1;
+    FT_UShort  opcode_pointer[1] = { 0 };
+    FT_UShort  opcode_size[1]    = { 1 };
+    FT_UShort  i;
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
 
 #ifdef TT_CONFIG_OPTION_STATIC_RASTER
     cur = *exc;
@@ -8153,9 +8201,6 @@
       /* One can also interpret it as the index of the last argument.    */
       if ( CUR.args < 0 )
       {
-        FT_UShort  i;
-
-
         if ( CUR.pedantic_hinting )
         {
           CUR.error = FT_THROW( Too_Few_Arguments );
@@ -8182,6 +8227,39 @@
       CUR.step_ins = TRUE;
       CUR.error    = FT_Err_Ok;
 
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
+      if ( SUBPIXEL_HINTING )
+      {
+        for ( i = 0; i < opcode_patterns; i++ )
+        {
+          if ( opcode_pointer[i] < opcode_size[i]                 &&
+               CUR.opcode == opcode_pattern[i][opcode_pointer[i]] )
+          {
+            opcode_pointer[i] += 1;
+
+            if ( opcode_pointer[i] == opcode_size[i] )
+            {
+              FT_TRACE7(( "sph: opcode ptrn: %d, %s %s\n",
+                          i,
+                          CUR.face->root.family_name,
+                          CUR.face->root.style_name ));
+
+              switch ( i )
+              {
+              case 0:
+                break;
+              }
+              opcode_pointer[i] = 0;
+            }
+          }
+          else
+            opcode_pointer[i] = 0;
+        }
+      }
+
+#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
 #ifdef TT_CONFIG_OPTION_INTERPRETER_SWITCH
 
       {
@@ -8378,15 +8456,7 @@
           break;
 
         case 0x2B:  /* CALL */
-#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-          if ( !SUBPIXEL_HINTING                        ||
-               ( !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 );
+          Ins_CALL( EXEC_ARG_ args );
           break;
 
         case 0x2C:  /* FDEF */
@@ -8404,12 +8474,6 @@
 
         case 0x30:  /* IUP */
         case 0x31:  /* IUP */
-#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-          if ( SUBPIXEL_HINTING  &&
-               CUR.ignore_x_mode )
-            CUR.iup_called = TRUE;
-#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
-
           Ins_IUP( EXEC_ARG_ args );
           break;
 
@@ -8569,15 +8633,7 @@
           break;
 
         case 0x5D:  /* DELTAP1 */
-#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
-          if ( !SUBPIXEL_HINTING                          ||
-               ( !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 );
+          Ins_DELTAP( EXEC_ARG_ args );
           break;
 
         case 0x5E:  /* SDB */
diff --git a/src/truetype/ttsubpix.c b/src/truetype/ttsubpix.c
index af57b9c..8310b33 100644
--- a/src/truetype/ttsubpix.c
+++ b/src/truetype/ttsubpix.c
@@ -287,25 +287,14 @@
 
 
   /* Don't do subpixel (ignore_x_mode) hinting; do normal hinting.         */
-#define PIXEL_HINTING_RULES_SIZE  1
+#define PIXEL_HINTING_RULES_SIZE  2
 
   const SPH_TweakRule  PIXEL_HINTING_Rules
                        [PIXEL_HINTING_RULES_SIZE] =
   {
     /* these characters are almost always safe */
-    { "-", 0, "", 0 },
-  };
-
-
-  /* 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
-
-  const SPH_TweakRule  SKIP_INLINE_DELTAS_Rules
-                       [SKIP_INLINE_DELTAS_RULES_SIZE] =
-  {
-    { "-", 0, "", 0 },
+    { "Courier New", 12, "Italic", 'z' },
+    { "Courier New", 11, "Italic", 'z' },
   };
 
 
@@ -321,42 +310,41 @@
 
   /* 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
+#define SKIP_NONPIXEL_Y_MOVES_RULES_SIZE  5
 
   const 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' },
+    { "Consolas", 0, "", 0 }, { "-", 0, "N", 0 },
     /* Fix thin middle stems */
-    { "Core MS Legacy Fonts", 0, "Regular/Bold Class", 'N' },
-    { "Lucida Grande", 0, "", 'N' },
-    { "Lucida Grande", 0, "Bold", 'y' },
+    { "-Core MS Legacy Fonts", 0, "Regular/Bold Class", 0 },
     /* Cyrillic small letter I */
-    { "Legacy Sans Fonts", 0, "", 0x438 },
-    { "Verdana Clones", 0, "",'N' },
-    /* Fix misshapen x */
-    { "Verdana", 0, "Bold", 'x' },
-    /* Fix misshapen s */
-    { "Tahoma", 0, "", 's' },
+    { "Legacy Sans Fonts", 0, "", 0 },
+    /* Fix artifacts with some Regular & Bold */
+    { "Verdana Clones", 0, "", 0 },
   };
 
 
-#define SKIP_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE  7
+#define SKIP_NONPIXEL_Y_MOVES_RULES_EXCEPTIONS_SIZE  1
 
   const 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 },
-    { "Arial", 11, "Bold", 'N' },
-    { "Trebuchet MS", 0, "Bold", 0 },
+    { "-", 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_DELTAP_RULES_SIZE  2
+
+  const SPH_TweakRule  SKIP_NONPIXEL_Y_MOVES_DELTAP_Rules
+                       [SKIP_NONPIXEL_Y_MOVES_DELTAP_RULES_SIZE] =
+  {
+    /* Maintain thickness of diagonal in 'N' */
+    { "Times New Roman", 0, "Regular/Bold Class", 'N' },
+    { "Georgia", 0, "Regular/Bold Class", 'N' },
   };
 
 
@@ -400,16 +388,6 @@
   };
 
 
-  /* Allow a Direct_Move_X along X freedom vector if matched.              */
-#define ALLOW_X_DMOVEX_RULES_SIZE  1
-
-  const SPH_TweakRule  ALLOW_X_DMOVEX_Rules
-                       [ALLOW_X_DMOVEX_RULES_SIZE] =
-  {
-    { "-", 0, "Regular", 0 },
-  };
-
-
   /* Allow a Direct_Move along X freedom vector if matched.                */
 #define ALLOW_X_DMOVE_RULES_SIZE  1
 
@@ -421,17 +399,6 @@
   };
 
 
-  /* 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
-
-  const 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
 
@@ -456,7 +423,8 @@
   const SPH_TweakRule  NORMAL_ROUND_Rules
                        [NORMAL_ROUND_RULES_SIZE] =
   {
-    /* Fix serif thickness */
+    /* Fix serif thickness for certain ppems */
+    /* Can probably be generalized somehow   */
     { "Courier New", 0, "", 0 },
   };
 
@@ -482,7 +450,7 @@
 
 
   /* Skip DELTAP instructions if matched.                                  */
-#define ALWAYS_SKIP_DELTAP_RULES_SIZE  15
+#define ALWAYS_SKIP_DELTAP_RULES_SIZE  18
 
   const SPH_TweakRule  ALWAYS_SKIP_DELTAP_Rules
                        [ALWAYS_SKIP_DELTAP_RULES_SIZE] =
@@ -492,7 +460,11 @@
     { "Trebuchet MS", 14, "Regular", 'e' },
     { "Trebuchet MS", 13, "Regular", 'e' },
     { "Trebuchet MS", 15, "Regular", 'e' },
+    { "Trebuchet MS", 0, "Italic", 'v' },
+    { "Trebuchet MS", 0, "Italic", 'w' },
+    { "Trebuchet MS", 0, "Regular", 'Y' },
     { "Arial", 11, "Regular", 's' },
+    /* prevent problems with '3' and others */
     { "Verdana", 10, "Regular", 0 },
     { "Verdana", 9, "Regular", 0 },
     /* Cyrillic small letter short I */
@@ -509,57 +481,23 @@
 
 
   /* Always do DELTAP instructions if matched.                             */
-#define ALWAYS_DO_DELTAP_RULES_SIZE  2
+#define ALWAYS_DO_DELTAP_RULES_SIZE  1
 
   const 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
-
-  static const 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
-
-  static const SPH_TweakRule  MIRP_CVT_ZERO_Rules
-                              [MIRP_CVT_ZERO_RULES_SIZE] =
-  {
-    { "-", 0, "", 0 },
-  };
-
-
-  /* Skip moves that meet or exceed 1 pixel.                               */
-#define DELTAP_SKIP_EXAGGERATED_VALUES_RULES_SIZE  1
-
-  static const SPH_TweakRule  DELTAP_SKIP_EXAGGERATED_VALUES_Rules
-                              [DELTAP_SKIP_EXAGGERATED_VALUES_RULES_SIZE] =
-  {
     { "-", 0, "", 0 },
   };
 
 
   /* Don't allow ALIGNRP after IUP.                                        */
-#define NO_ALIGNRP_AFTER_IUP_RULES_SIZE  4
+#define NO_ALIGNRP_AFTER_IUP_RULES_SIZE  1
 
   static const 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' },
+    { "-", 0, "", 0 },
   };
 
 
@@ -574,16 +512,13 @@
 
 
   /* Don't allow CALL after IUP.                                           */
-#define NO_CALL_AFTER_IUP_RULES_SIZE  4
+#define NO_CALL_AFTER_IUP_RULES_SIZE  1
 
   static const 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' },
+    { "-", 0, "", 0 },
   };
 
 
@@ -606,29 +541,16 @@
 
 
   /* Embolden these glyphs slightly.                                       */
-#define EMBOLDEN_RULES_SIZE  5
+#define EMBOLDEN_RULES_SIZE  2
 
   static const 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
-
-  static const 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
@@ -999,12 +921,9 @@
     }
 
     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 );
@@ -1013,13 +932,13 @@
     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_DELTAP );
+
     TWEAK_RULES( SKIP_NONPIXEL_Y_MOVES );
     TWEAK_RULES_EXCEPTIONS( SKIP_NONPIXEL_Y_MOVES );
 
diff --git a/src/truetype/ttsubpix.h b/src/truetype/ttsubpix.h
index 5e5d8e6..8a54fc7 100644
--- a/src/truetype/ttsubpix.h
+++ b/src/truetype/ttsubpix.h
@@ -34,14 +34,15 @@ FT_BEGIN_HEADER
   /* ID flags to identify special functions at FDEF and runtime.           */
   /*                                                                       */
   /*                                                                       */
-#define SPH_FDEF_INLINE_DELTA_1    0x0000001
-#define SPH_FDEF_INLINE_DELTA_2    0x0000002
-#define SPH_FDEF_DIAGONAL_STROKE   0x0000004
-#define SPH_FDEF_VACUFORM_ROUND_1  0x0000008
-#define SPH_FDEF_TTFAUTOHINT_1     0x0000010
-#define SPH_FDEF_SPACING_1         0x0000020
-#define SPH_FDEF_SPACING_2         0x0000040
-#define SPH_FDEF_TYPEMAN_STROKES   0x0000080
+#define SPH_FDEF_INLINE_DELTA_1       0x0000001
+#define SPH_FDEF_INLINE_DELTA_2       0x0000002
+#define SPH_FDEF_DIAGONAL_STROKE      0x0000004
+#define SPH_FDEF_VACUFORM_ROUND_1     0x0000008
+#define SPH_FDEF_TTFAUTOHINT_1        0x0000010
+#define SPH_FDEF_SPACING_1            0x0000020
+#define SPH_FDEF_SPACING_2            0x0000040
+#define SPH_FDEF_TYPEMAN_STROKES      0x0000080
+#define SPH_FDEF_TYPEMAN_DIAGENDCTRL  0x0000100
 
 
   /*************************************************************************/
@@ -50,29 +51,25 @@ FT_BEGIN_HEADER
   /*                                                                       */
   /*                                                                       */
 #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
+#define SPH_TWEAK_ALWAYS_DO_DELTAP                0x0000002
+#define SPH_TWEAK_ALWAYS_SKIP_DELTAP              0x0000004
+#define SPH_TWEAK_COURIER_NEW_2_HACK              0x0000008
+#define SPH_TWEAK_DEEMBOLDEN                      0x0000010
+#define SPH_TWEAK_DO_SHPIX                        0x0000020
+#define SPH_TWEAK_EMBOLDEN                        0x0000040
+#define SPH_TWEAK_MIAP_HACK                       0x0000080
+#define SPH_TWEAK_NORMAL_ROUND                    0x0000100
+#define SPH_TWEAK_NO_ALIGNRP_AFTER_IUP            0x0000200
+#define SPH_TWEAK_NO_CALL_AFTER_IUP               0x0000400
+#define SPH_TWEAK_NO_DELTAP_AFTER_IUP             0x0000800
+#define SPH_TWEAK_PIXEL_HINTING                   0x0001000
+#define SPH_TWEAK_RASTERIZER_35                   0x0002000
+#define SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES          0x0004000
+#define SPH_TWEAK_SKIP_IUP                        0x0008000
+#define SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES           0x0010000
+#define SPH_TWEAK_SKIP_OFFPIXEL_Y_MOVES           0x0020000
+#define SPH_TWEAK_TIMES_NEW_ROMAN_HACK            0x0040000
+#define SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES_DELTAP    0x0080000
 
 
   FT_LOCAL( FT_Bool )