Commit d1245c0dd28f3604e266b44e7b3ff0108ae0c806

David Turner 2002-08-27T22:34:20

updating sources to support the new FT_LOAD_TARGET_ constants to support target-specific hinting

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
diff --git a/include/freetype/internal/autohint.h b/include/freetype/internal/autohint.h
index cf1568e..22340af 100644
--- a/include/freetype/internal/autohint.h
+++ b/include/freetype/internal/autohint.h
@@ -176,7 +176,7 @@ FT_BEGIN_HEADER
                                   FT_GlyphSlot   slot,
                                   FT_Size        size,
                                   FT_UInt        glyph_index,
-                                  FT_ULong       load_flags );
+                                  FT_Int32       load_flags );
 
 
   /*************************************************************************/
diff --git a/include/freetype/internal/psaux.h b/include/freetype/internal/psaux.h
index fbb7434..e79f83a 100644
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -610,6 +610,7 @@ FT_BEGIN_HEADER
              FT_Byte**            glyph_names,
              PS_Blend             blend,
              FT_Bool              hinting,
+             FT_Render_Mode       hint_mode,
              T1_Decoder_Callback  callback );
 
     void
@@ -652,6 +653,7 @@ FT_BEGIN_HEADER
     PS_Blend             blend;       /* for multiple master support */
 
     FT_UInt32            hint_flags;
+    FT_Render_Mode       hint_mode;
 
     T1_Decoder_Callback  parse_callback;
     T1_Decoder_FuncsRec  funcs;
diff --git a/include/freetype/internal/pshints.h b/include/freetype/internal/pshints.h
index 5af27b1..15571d9 100644
--- a/include/freetype/internal/pshints.h
+++ b/include/freetype/internal/pshints.h
@@ -280,10 +280,10 @@ FT_BEGIN_HEADER
   /*    which must correspond to the same font as the glyph.               */
   /*                                                                       */
   typedef FT_Error
-  (*T1_Hints_ApplyFunc)( T1_Hints     hints,
-                         FT_Outline*  outline,
-                         PSH_Globals  globals,
-                         FT_UInt32    hint_flags );
+  (*T1_Hints_ApplyFunc)( T1_Hints        hints,
+                         FT_Outline*     outline,
+                         PSH_Globals     globals,
+                         FT_Render_Mode  hint_mode );
 
 
   /*************************************************************************/
@@ -561,10 +561,10 @@ FT_BEGIN_HEADER
   /*    which must correspond to the same font than the glyph.             */
   /*                                                                       */
   typedef FT_Error
-  (*T2_Hints_ApplyFunc)( T2_Hints     hints,
-                         FT_Outline*  outline,
-                         PSH_Globals  globals,
-                         FT_UInt32    hint_flags );
+  (*T2_Hints_ApplyFunc)( T2_Hints        hints,
+                         FT_Outline*     outline,
+                         PSH_Globals     globals,
+                         FT_Render_Mode  hint_mode );
 
 
   /*************************************************************************/
diff --git a/src/autohint/ahhint.c b/src/autohint/ahhint.c
index e9fcedb..33d65c6 100644
--- a/src/autohint/ahhint.c
+++ b/src/autohint/ahhint.c
@@ -40,7 +40,6 @@
   /*************************************************************************/
   /*************************************************************************/
 
-#if 0
   /* snap a given width in scaled coordinates to one of the */
   /* current standard widths                                */
   static FT_Pos
@@ -86,11 +85,11 @@
 
     return width;
   }
-#endif
+
 
   /* compute the snapped width of a given stem */
   static FT_Pos
-  ah_compute_stem_width( AH_Hinter  hinter,
+  ah_compute_stem_width( AH_Hinter   hinter,
                          int         vertical,
                          FT_Pos      width )
   {
@@ -105,85 +104,93 @@
       sign = 1;
     }
 
-#if 1
-    if ( dist < 64 )
-      dist = 64;
-
+    if ( ( vertical  && hinter->no_vert_snapping ) ||
+         ( !vertical && hinter->no_horz_snapping ) )
     {
-      FT_Pos  delta = dist - globals->stds[vertical];
-
-
-      if ( delta < 0 )
-        delta = -delta;
-
-      if ( delta < 40 )
-      {
-        dist = globals->stds[vertical];
-        if ( dist < 32 )
-          dist = 32;
-      }
-
-      if ( dist < 3 * 64 )
+      /* smooth hinting process, very lightly quantize the stem width */
+      /*                                                              */
+      if ( dist < 64 )
+        dist = 64;
+  
       {
-        delta = ( dist & 63 );
-        dist &= -64;
-
-        if ( delta < 10 )
-          dist += delta;
-
-        else if ( delta < 32 )
-          dist += 10;
-
-        else if ( delta < 54 )
-          dist += 54;
-
+        FT_Pos  delta = dist - globals->stds[vertical];
+  
+  
+        if ( delta < 0 )
+          delta = -delta;
+  
+        if ( delta < 40 )
+        {
+          dist = globals->stds[vertical];
+          if ( dist < 32 )
+            dist = 32;
+        }
+  
+        if ( dist < 3 * 64 )
+        {
+          delta = ( dist & 63 );
+          dist &= -64;
+  
+          if ( delta < 10 )
+            dist += delta;
+  
+          else if ( delta < 32 )
+            dist += 10;
+  
+          else if ( delta < 54 )
+            dist += 54;
+  
+          else
+            dist += delta;
+        }
         else
-          dist += delta;
+          dist = ( dist + 32 ) & -64;
       }
-      else
-        dist = ( dist + 32 ) & -64;
-    }
-#else
-    if ( vertical )
-    {
-      dist = ah_snap_width( globals->heights, globals->num_heights, dist );
-
-      /* in the case of vertical hinting, always round */
-      /* the stem heights to integer pixels            */
-      if ( dist >= 64 )
-        dist = ( dist + 16 ) & -64;
-      else
-        dist = 64;
     }
     else
     {
-      dist = ah_snap_width( globals->widths,  globals->num_widths, dist );
-
-      if ( hinter->flags & AH_HINTER_MONOCHROME )
+      /* strong hinting process, snap the stem width to integer pixels */
+      /*                                                               */
+      if ( vertical )
       {
-        /* monochrome horizontal hinting: snap widths to integer pixels */
-        /* with a different threshold                                   */
-        if ( dist < 64 )
-          dist = 64;
+        dist = ah_snap_width( globals->heights, globals->num_heights, dist );
+  
+        /* in the case of vertical hinting, always round */
+        /* the stem heights to integer pixels            */
+        if ( dist >= 64 )
+          dist = ( dist + 16 ) & -64;
         else
-          dist = ( dist + 32 ) & -64;
+          dist = 64;
       }
       else
       {
-        /* for horizontal anti-aliased hinting, we adopt a more subtle */
-        /* approach: we strengthen small stems, round stems whose size */
-        /* is between 1 and 2 pixels to an integer, otherwise nothing  */
-        if ( dist < 48 )
-          dist = ( dist + 64 ) >> 1;
-
-        else if ( dist < 128 )
-          dist = ( dist + 22 ) & -64;
+        dist = ah_snap_width( globals->widths,  globals->num_widths, dist );
+  
+        if ( hinter->flags & AH_HINTER_MONOCHROME )
+        {
+          /* monochrome horizontal hinting: snap widths to integer pixels */
+          /* with a different threshold                                   */
+          if ( dist < 64 )
+            dist = 64;
+          else
+            dist = ( dist + 32 ) & -64;
+        }
         else
-          /* XXX: round otherwise, prevent color fringes in LCD mode */
-          dist = ( dist + 32 ) & -64;
+        {
+          /* for horizontal anti-aliased hinting, we adopt a more subtle */
+          /* approach: we strengthen small stems, round stems whose size */
+          /* is between 1 and 2 pixels to an integer, otherwise nothing  */
+          if ( dist < 48 )
+            dist = ( dist + 64 ) >> 1;
+  
+          else if ( dist < 128 )
+            dist = ( dist + 22 ) & -64;
+          else
+            /* XXX: round otherwise, prevent color fringes in LCD mode */
+            dist = ( dist + 32 ) & -64;
+        }
       }
     }
-#endif
 
     if ( sign )
       dist = -dist;
@@ -278,10 +285,10 @@
       int       has_serifs = 0;
 
 
-      if ( ah_debug_disable_vert && !dimension )
+      if ( hinter->no_horz_hints && !dimension )
         goto Next_Dimension;
 
-      if ( ah_debug_disable_horz && dimension )
+      if ( hinter->no_vert_hints && dimension )
         goto Next_Dimension;
 
       /* we begin by aligning all stems relative to the blue zone */
@@ -467,38 +474,13 @@
 
 
   FT_LOCAL_DEF( void )
-  ah_hinter_hint_edges( AH_Hinter  hinter,
-                        FT_Bool     no_horz_edges,
-                        FT_Bool     no_vert_edges )
+  ah_hinter_hint_edges( AH_Hinter  hinter )
   {
-#if 0
-    ah_debug_disable_horz = no_horz_edges;
-    ah_debug_disable_vert = no_vert_edges;
-#else
-    FT_UNUSED( no_horz_edges );
-    FT_UNUSED( no_vert_edges );
-#endif
     /* AH_Interpolate_Blue_Edges( hinter ); -- doesn't seem to help      */
     /* reduce the problem of the disappearing eye in the `e' of Times... */
     /* also, creates some artifacts near the blue zones?                 */
     {
       ah_hint_edges_3( hinter );
-
-#if 0
-      /* outline optimizer removed temporarily */
-      if ( hinter->flags & AH_HINTER_OPTIMIZE )
-      {
-        AH_Optimizer  opt;
-
-
-        if ( !AH_Optimizer_Init( &opt, hinter->glyph, hinter->memory ) )
-        {
-          AH_Optimizer_Compute( &opt );
-          AH_Optimizer_Done( &opt );
-        }
-      }
-#endif
-
     }
   }
 
@@ -1048,7 +1030,7 @@
 
   /* create a face's autohint globals */
   FT_LOCAL_DEF( FT_Error )
-  ah_hinter_new_face_globals( AH_Hinter   hinter,
+  ah_hinter_new_face_globals( AH_Hinter    hinter,
                               FT_Face      face,
                               AH_Globals   globals )
   {
@@ -1091,9 +1073,9 @@
 
 
   static FT_Error
-  ah_hinter_load( AH_Hinter  hinter,
+  ah_hinter_load( AH_Hinter   hinter,
                   FT_UInt     glyph_index,
-                  FT_UInt     load_flags,
+                  FT_Int32    load_flags,
                   FT_UInt     depth )
   {
     FT_Face           face     = hinter->face;
@@ -1104,11 +1086,6 @@
     FT_Error          error;
     AH_Outline        outline  = hinter->glyph;
     AH_Loader         gloader  = hinter->loader;
-    FT_Bool           no_horz_hints = FT_BOOL(
-                        ( load_flags & AH_HINT_NO_HORZ_EDGES ) != 0 );
-    FT_Bool           no_vert_hints = FT_BOOL(
-                        ( load_flags & AH_HINT_NO_VERT_EDGES ) != 0 );
-
 
     /* load the glyph */
     error = FT_Load_Glyph( face, glyph_index, load_flags );
@@ -1191,14 +1168,14 @@
       /* perform feature detection */
       ah_outline_detect_features( outline );
 
-      if ( !no_horz_hints )
+      if ( !hinter->no_vert_hints )
       {
         ah_outline_compute_blue_edges( outline, hinter->globals );
         ah_outline_scale_blue_edges( outline, hinter->globals );
       }
 
       /* perform alignment control */
-      ah_hinter_hint_edges( hinter, no_horz_hints, no_vert_hints );
+      ah_hinter_hint_edges( hinter );
       ah_hinter_align( hinter );
 
       /* now save the current outline into the loader's current table */
@@ -1421,17 +1398,18 @@
 
   /* load and hint a given glyph */
   FT_LOCAL_DEF( FT_Error )
-  ah_hinter_load_glyph( AH_Hinter    hinter,
+  ah_hinter_load_glyph( AH_Hinter     hinter,
                         FT_GlyphSlot  slot,
                         FT_Size       size,
                         FT_UInt       glyph_index,
-                        FT_Int        load_flags )
+                        FT_Int32      load_flags )
   {
     FT_Face           face         = slot->face;
     FT_Error          error;
     FT_Fixed          x_scale      = size->metrics.x_scale;
     FT_Fixed          y_scale      = size->metrics.y_scale;
     AH_Face_Globals   face_globals = FACE_GLOBALS( face );
+    FT_Render_Mode    hint_mode    = FT_LOAD_TARGET_MODE(load_flags);
 
 
     /* first of all, we need to check that we're using the correct face and */
@@ -1459,6 +1437,25 @@
 
     ah_loader_rewind( hinter->loader );
 
+    /* reset hinting flags according to load flags and current render target */
+    hinter->no_horz_hints = FT_BOOL( load_flags & FT_LOAD_NO_AUTOHINT );
+    hinter->no_vert_hints = FT_BOOL( load_flags & FT_LOAD_NO_AUTOHINT );
+    
+#ifdef DEBUG_HINTER
+    hinter->no_horz_hints = ah_debug_disable_vert;  /* not a bug, the meaning */
+    hinter->no_vert_hints = ah_debug_disable_horz;  /* of h/v is inverted !!  */
+#endif    
+
+    /* we snap the width of vertical stems for the monochrome and horizontal */
+    /* LCD rendering targets only. Corresponds to X snapping                 */
+    hinter->no_horz_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_NORMAL ||
+                                        hint_mode == FT_RENDER_MODE_LCD_V  );
+
+    /* we snap the width of horizontal stems for the monochrome and vertical */
+    /* LCD rendering targets only. Corresponds to Y snapping                 */
+    hinter->no_vert_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_NORMAL ||
+                                        hint_mode == FT_RENDER_MODE_LCD    );
+
 #if 1
     load_flags  = FT_LOAD_NO_SCALE
                 | FT_LOAD_IGNORE_TRANSFORM ;
diff --git a/src/autohint/ahhint.h b/src/autohint/ahhint.h
index 88b950f..d190eb4 100644
--- a/src/autohint/ahhint.h
+++ b/src/autohint/ahhint.h
@@ -32,8 +32,8 @@ FT_BEGIN_HEADER
 
 #define AH_HINT_DEFAULT        0
 #define AH_HINT_NO_ALIGNMENT   1
-#define AH_HINT_NO_HORZ_EDGES  0x20000L
-#define AH_HINT_NO_VERT_EDGES  0x40000L
+#define AH_HINT_NO_HORZ_EDGES  0x200000L  /* temporary hack */
+#define AH_HINT_NO_VERT_EDGES  0x400000L  /* temporary hack */
 
 
   /* create a new empty hinter object */
@@ -47,7 +47,7 @@ FT_BEGIN_HEADER
                         FT_GlyphSlot  slot,
                         FT_Size       size,
                         FT_UInt       glyph_index,
-                        FT_Int        load_flags );
+                        FT_Int32      load_flags );
 
   /* finalize a hinter object */
   FT_LOCAL( void )
diff --git a/src/autohint/ahmodule.c b/src/autohint/ahmodule.c
index c44e396..eb4ab1c 100644
--- a/src/autohint/ahmodule.c
+++ b/src/autohint/ahmodule.c
@@ -69,7 +69,7 @@
                             FT_GlyphSlot   slot,
                             FT_Size        size,
                             FT_UInt        glyph_index,
-                            FT_ULong       load_flags )
+                            FT_Int32       load_flags )
   {
     return ah_hinter_load_glyph( module->hinter,
                                  slot, size, glyph_index, load_flags );
diff --git a/src/autohint/ahtypes.h b/src/autohint/ahtypes.h
index de053e9..04f9b29 100644
--- a/src/autohint/ahtypes.h
+++ b/src/autohint/ahtypes.h
@@ -491,6 +491,11 @@ FT_BEGIN_HEADER
     FT_Vector         trans_delta;
     FT_Matrix         trans_matrix;
 
+    FT_Bool           no_horz_hints;     /* disable X hinting            */
+    FT_Bool           no_vert_hints;     /* disable Y hinting            */
+    FT_Bool           no_horz_snapping;  /* disable X stem size snapping */
+    FT_Bool           no_vert_snapping;  /* disable Y stem size snapping */
+
   } AH_HinterRec, *AH_Hinter;
 
 
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index c9098fc..f24da51 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -347,11 +347,12 @@
   /*    slot    :: The current glyph object.                               */
   /*                                                                       */
   FT_LOCAL_DEF( void )
-  cff_decoder_init( CFF_Decoder*   decoder,
-                    TT_Face        face,
-                    CFF_Size       size,
-                    CFF_GlyphSlot  slot,
-                    FT_Bool        hinting )
+  cff_decoder_init( CFF_Decoder*    decoder,
+                    TT_Face         face,
+                    CFF_Size        size,
+                    CFF_GlyphSlot   slot,
+                    FT_Bool         hinting,
+                    FT_Render_Mode  hint_mode )
   {
     CFF_Font  cff = (CFF_Font)face->extra.data;
 
@@ -366,6 +367,8 @@
     decoder->num_globals  = cff->num_global_subrs;
     decoder->globals      = cff->global_subrs;
     decoder->globals_bias = cff_compute_bias( decoder->num_globals );
+    
+    decoder->hint_mode    = hint_mode;
   }
 
 
@@ -2203,7 +2206,7 @@
     *max_advance = 0;
 
     /* Initialize load decoder */
-    cff_decoder_init( &decoder, face, 0, 0, 0 );
+    cff_decoder_init( &decoder, face, 0, 0, 0, 0 );
 
     decoder.builder.metrics_only = 1;
     decoder.builder.load_points  = 0;
@@ -2262,7 +2265,7 @@
   cff_slot_load( CFF_GlyphSlot  glyph,
                  CFF_Size       size,
                  FT_Int         glyph_index,
-                 FT_Int         load_flags )
+                 FT_Int32       load_flags )
   {
     FT_Error     error;
     CFF_Decoder  decoder;
@@ -2298,7 +2301,8 @@
       FT_ULong  charstring_len;
 
 
-      cff_decoder_init( &decoder, face, size, glyph, hinting );
+      cff_decoder_init( &decoder, face, size, glyph, hinting,
+                        FT_LOAD_TARGET_MODE(load_flags) );
 
       decoder.builder.no_recurse =
         (FT_Bool)( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 );
diff --git a/src/cff/cffgload.h b/src/cff/cffgload.h
index c974837..146cfdd 100644
--- a/src/cff/cffgload.h
+++ b/src/cff/cffgload.h
@@ -168,15 +168,18 @@ FT_BEGIN_HEADER
     FT_Byte**          glyph_names;   /* for pure CFF fonts only  */
     FT_UInt            num_glyphs;    /* number of glyphs in font */
 
+    FT_Render_Mode     hint_mode;
+
   } CFF_Decoder;
 
 
   FT_LOCAL( void )
-  cff_decoder_init( CFF_Decoder*   decoder,
-                    TT_Face        face,
-                    CFF_Size       size,
-                    CFF_GlyphSlot  slot,
-                    FT_Bool        hinting );
+  cff_decoder_init( CFF_Decoder*    decoder,
+                    TT_Face         face,
+                    CFF_Size        size,
+                    CFF_GlyphSlot   slot,
+                    FT_Bool         hinting,
+                    FT_Render_Mode  hint_mode );
 
   FT_LOCAL( void )
   cff_decoder_prepare( CFF_Decoder*  decoder,
@@ -200,7 +203,7 @@ FT_BEGIN_HEADER
   cff_slot_load( CFF_GlyphSlot  glyph,
                  CFF_Size       size,
                  FT_Int         glyph_index,
-                 FT_Int         load_flags );
+                 FT_Int32       load_flags );
 
 
 FT_END_HEADER
diff --git a/src/cid/cidgload.c b/src/cid/cidgload.c
index b5b58f1..c5b2ecf 100644
--- a/src/cid/cidgload.c
+++ b/src/cid/cidgload.c
@@ -272,7 +272,7 @@
   cid_slot_load_glyph( CID_GlyphSlot  glyph,
                        CID_Size       size,
                        FT_Int         glyph_index,
-                       FT_Int         load_flags )
+                       FT_Int32       load_flags )
   {
     FT_Error       error;
     T1_DecoderRec  decoder;
@@ -306,6 +306,7 @@
                                              0, /* glyph names -- XXX */
                                              0, /* blend == 0 */
                                              hinting,
+                                             FT_LOAD_TARGET_MODE(load_flags),
                                              cid_load_glyph );
 
       /* set up the decoder */
diff --git a/src/cid/cidgload.h b/src/cid/cidgload.h
index 578b7c4..93858e8 100644
--- a/src/cid/cidgload.h
+++ b/src/cid/cidgload.h
@@ -40,7 +40,7 @@ FT_BEGIN_HEADER
   cid_slot_load_glyph( CID_GlyphSlot  glyph,
                        CID_Size       size,
                        FT_Int         glyph_index,
-                       FT_Int         load_flags );
+                       FT_Int32       load_flags );
 
 
 FT_END_HEADER
diff --git a/src/psaux/t1decode.c b/src/psaux/t1decode.c
index 5abc8cf..0519305 100644
--- a/src/psaux/t1decode.c
+++ b/src/psaux/t1decode.c
@@ -752,8 +752,8 @@
             /* apply hints to the loaded glyph outline now */
             hinter->apply( hinter->hints,
                            builder->current,
-                           (PSH_Globals)builder->hints_globals,
-                           decoder->hint_flags );
+                           (PSH_Globals) builder->hints_globals,
+                           decoder->hint_mode );
           }
 
           /* add current outline to the glyph slot */
@@ -1122,6 +1122,7 @@
                    FT_Byte**            glyph_names,
                    PS_Blend             blend,
                    FT_Bool              hinting,
+                   FT_Render_Mode       hint_mode,
                    T1_Decoder_Callback  parse_callback )
   {
     FT_MEM_ZERO( decoder, sizeof ( *decoder ) );
@@ -1148,6 +1149,7 @@
     decoder->num_glyphs     = face->num_glyphs;
     decoder->glyph_names    = glyph_names;
     decoder->hint_flags     = face->internal->hint_flags;
+    decoder->hint_mode      = hint_mode;
     decoder->blend          = blend;
     decoder->parse_callback = parse_callback;
 
diff --git a/src/psaux/t1decode.h b/src/psaux/t1decode.h
index 4540d4a..fcb853c 100644
--- a/src/psaux/t1decode.h
+++ b/src/psaux/t1decode.h
@@ -50,6 +50,7 @@ FT_BEGIN_HEADER
                    FT_Byte**            glyph_names,
                    PS_Blend             blend,
                    FT_Bool              hinting,
+                   FT_Render_Mode       hint_mode,
                    T1_Decoder_Callback  parse_glyph );
 
   FT_LOCAL( void )
diff --git a/src/pshinter/pshalgo1.c b/src/pshinter/pshalgo1.c
index 7f4d7e8..06da597 100644
--- a/src/pshinter/pshalgo1.c
+++ b/src/pshinter/pshalgo1.c
@@ -742,17 +742,17 @@
   /*************************************************************************/
 
   FT_Error
-  ps1_hints_apply( PS_Hints     ps_hints,
-                   FT_Outline*  outline,
-                   PSH_Globals  globals,
-                   FT_UInt32    hint_flags )
+  ps1_hints_apply( PS_Hints        ps_hints,
+                   FT_Outline*     outline,
+                   PSH_Globals     globals,
+                   FT_Render_Mode  hint_mode )
   {
     PSH1_Hint_TableRec  hints;
     FT_Error            error = 0;
     FT_Int              dimension;
 
 
-    FT_UNUSED( hint_flags );
+    FT_UNUSED( hint_mode );
 
     for ( dimension = 1; dimension >= 0; dimension-- )
     {
diff --git a/src/pshinter/pshalgo1.h b/src/pshinter/pshalgo1.h
index 1eae160..2f795a6 100644
--- a/src/pshinter/pshalgo1.h
+++ b/src/pshinter/pshalgo1.h
@@ -86,10 +86,10 @@ FT_BEGIN_HEADER
 
 
   extern FT_Error
-  ps1_hints_apply( PS_Hints     ps_hints,
-                   FT_Outline*  outline,
-                   PSH_Globals  globals,
-                   FT_UInt32    hint_flags );
+  ps1_hints_apply( PS_Hints        ps_hints,
+                   FT_Outline*     outline,
+                   PSH_Globals     globals,
+                   FT_Render_Mode  hint_mode );
 
 
 #ifdef DEBUG_HINTER
diff --git a/src/pshinter/pshalgo2.c b/src/pshinter/pshalgo2.c
index 65ff454..372ff28 100644
--- a/src/pshinter/pshalgo2.c
+++ b/src/pshinter/pshalgo2.c
@@ -1492,10 +1492,10 @@
   /*************************************************************************/
 
   FT_Error
-  ps2_hints_apply( PS_Hints     ps_hints,
-                   FT_Outline*  outline,
-                   PSH_Globals  globals,
-                   FT_UInt32    hint_flags )
+  ps2_hints_apply( PS_Hints        ps_hints,
+                   FT_Outline*     outline,
+                   PSH_Globals     globals,
+                   FT_Render_Mode  hint_mode )
   {
     PSH2_GlyphRec  glyphrec;
     PSH2_Glyph     glyph = &glyphrec;
@@ -1505,7 +1505,7 @@
 #endif
     FT_Int         dimension;
 
-    FT_UNUSED( hint_flags );
+    FT_UNUSED( hint_mode );
 
 #ifdef DEBUG_HINTER
     memory = globals->memory;
diff --git a/src/pshinter/pshalgo2.h b/src/pshinter/pshalgo2.h
index 408cd95..405d34b 100644
--- a/src/pshinter/pshalgo2.h
+++ b/src/pshinter/pshalgo2.h
@@ -188,10 +188,10 @@ FT_BEGIN_HEADER
 
 
   extern FT_Error
-  ps2_hints_apply( PS_Hints     ps_hints,
-                   FT_Outline*  outline,
-                   PSH_Globals  globals,
-                   FT_UInt32    hint_flags );
+  ps2_hints_apply( PS_Hints        ps_hints,
+                   FT_Outline*     outline,
+                   PSH_Globals     globals,
+                   FT_Render_Mode  hint_mode );
 
 
 FT_END_HEADER
diff --git a/src/pshinter/pshalgo3.c b/src/pshinter/pshalgo3.c
index 90009a5..0a178e0 100644
--- a/src/pshinter/pshalgo3.c
+++ b/src/pshinter/pshalgo3.c
@@ -380,7 +380,7 @@
   psh3_hint_align( PSH3_Hint    hint,
                    PSH_Globals  globals,
                    FT_Int       dimension,
-                   FT_UInt32    hint_flags )
+                   PSH3_Glyph   glyph )
   {
     PSH_Dimension  dim   = &globals->dimension[dimension];
     FT_Fixed       scale = dim->scale_mult;
@@ -392,14 +392,15 @@
       FT_Pos  pos = FT_MulFix( hint->org_pos, scale ) + delta;
       FT_Pos  len = FT_MulFix( hint->org_len, scale );
 
+      FT_Int            no_snapping;
       FT_Pos            fit_center;
       FT_Pos            fit_len;
       PSH_AlignmentRec  align;
 
 
       /* ignore stem alignments when requested through the hint flags */
-      if ( ( dimension == 0 && ( hint_flags & FT_HINT_NO_VSTEM_ALIGN ) != 0 ) ||
-           ( dimension == 1 && ( hint_flags & FT_HINT_NO_HSTEM_ALIGN ) != 0 ) )
+      if ( ( dimension == 0 && glyph->no_horz_hints ) ||
+           ( dimension == 1 && glyph->no_vert_hints ) )
       {
         hint->cur_pos = pos;
         hint->cur_len = len;
@@ -409,7 +410,10 @@
       }
 
       /* perform stem snapping when requested */
-      if ( ( hint_flags & FT_HINT_NO_INTEGER_STEM ) == 0 )
+      no_snapping = ( dimension == 0 && !glyph->no_horz_snapping ) ||
+                    ( dimension == 1 && !glyph->no_vert_snapping );
+                    
+      if ( !no_snapping )
       {
         /* compute fitted width/height */
         fit_len = 0;
@@ -468,7 +472,7 @@
 
             /* ensure that parent is already fitted */
             if ( !psh3_hint_is_fitted( parent ) )
-              psh3_hint_align( parent, globals, dimension, hint_flags );
+              psh3_hint_align( parent, globals, dimension, glyph );
 
             par_org_center = parent->org_pos + ( parent->org_len >> 1 );
             par_cur_center = parent->cur_pos + ( parent->cur_len >> 1 );
@@ -478,7 +482,7 @@
             pos       = par_cur_center + cur_delta - ( len >> 1 );
           }
 
-          if ( ( hint_flags & FT_HINT_NO_INTEGER_STEM ) == 0 )
+          if ( !no_snapping )
           {
             /* normal processing */
             if ( fit_len & 64 )
@@ -537,7 +541,7 @@
               FT_Fixed delta_a, delta_b;
 
 
-              if ( ( len / 64 ) & 1 )
+              if ( len & 64 )           
               {
                 delta_a = ( center & -64 ) + 32 - center;
                 delta_b = ( ( center + 32 ) & - 64 ) - center;
@@ -587,7 +591,7 @@
   psh3_hint_table_align_hints( PSH3_Hint_Table  table,
                                PSH_Globals      globals,
                                FT_Int           dimension,
-                               FT_UInt32        hint_flags )
+                               PSH3_Glyph       glyph )
   {
     PSH3_Hint      hint;
     FT_UInt        count;
@@ -617,7 +621,7 @@
     count = table->max_hints;
 
     for ( ; count > 0; count--, hint++ )
-      psh3_hint_align( hint, globals, dimension, hint_flags );
+      psh3_hint_align( hint, globals, dimension, glyph );
   }
 
 
@@ -1675,10 +1679,10 @@
   /*************************************************************************/
 
   FT_Error
-  ps3_hints_apply( PS_Hints     ps_hints,
-                   FT_Outline*  outline,
-                   PSH_Globals  globals,
-                   FT_UInt32    hint_flags )
+  ps3_hints_apply( PS_Hints        ps_hints,
+                   FT_Outline*     outline,
+                   PSH_Globals     globals,
+                   FT_Render_Mode  hint_mode )
   {
     PSH3_GlyphRec  glyphrec;
     PSH3_Glyph     glyph = &glyphrec;
@@ -1706,6 +1710,15 @@
 
 #endif /* DEBUG_HINTER */
 
+    glyph->no_horz_hints = 0;
+    glyph->no_vert_hints = 0;
+    
+    glyph->no_horz_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_NORMAL ||
+                                       hint_mode == FT_RENDER_MODE_LCD_V  );
+
+    glyph->no_vert_snapping = FT_BOOL( hint_mode == FT_RENDER_MODE_NORMAL ||
+                                       hint_mode == FT_RENDER_MODE_LCD    );
+
     error = psh3_glyph_init( glyph, outline, ps_hints, globals );
     if ( error )
       goto Exit;
@@ -1722,7 +1735,7 @@
       psh3_hint_table_align_hints( &glyph->hint_tables[dimension],
                                    glyph->globals,
                                    dimension,
-                                   hint_flags );
+                                   glyph );
 
       /* find strong points, align them, then interpolate others */
       psh3_glyph_find_strong_points( glyph, dimension );
diff --git a/src/pshinter/pshalgo3.h b/src/pshinter/pshalgo3.h
index 5813dc2..a1a01db 100644
--- a/src/pshinter/pshalgo3.h
+++ b/src/pshinter/pshalgo3.h
@@ -217,6 +217,11 @@ FT_BEGIN_HEADER
     FT_Int              major_dir;
     FT_Int              minor_dir;
 
+    FT_Bool             no_horz_hints;
+    FT_Bool             no_vert_hints;
+    FT_Bool             no_horz_snapping;
+    FT_Bool             no_vert_snapping;
+
   } PSH3_GlyphRec, *PSH3_Glyph;
 
 
@@ -234,10 +239,10 @@ FT_BEGIN_HEADER
 
 
   extern FT_Error
-  ps3_hints_apply( PS_Hints     ps_hints,
-                   FT_Outline*  outline,
-                   PSH_Globals  globals,
-                   FT_UInt32    hint_flags );
+  ps3_hints_apply( PS_Hints        ps_hints,
+                   FT_Outline*     outline,
+                   PSH_Globals     globals,
+                   FT_Render_Mode  hint_mode );
 
 
 FT_END_HEADER
diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c
index ecf85f6..9197904 100644
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -164,6 +164,7 @@
                                            (FT_Byte**)type1->glyph_names,
                                            face->blend,
                                            0,
+                                           0,
                                            T1_Parse_Glyph );
     if ( error )
       return error;
@@ -214,7 +215,7 @@
   T1_Load_Glyph( T1_GlyphSlot  glyph,
                  T1_Size       size,
                  FT_UInt       glyph_index,
-                 FT_Int        load_flags )
+                 FT_Int32      load_flags )
   {
     FT_Error                error;
     T1_DecoderRec           decoder;
@@ -251,6 +252,7 @@
                                  (FT_Byte**)type1->glyph_names,
                                  face->blend,
                                  FT_BOOL( hinting ),
+                                 FT_LOAD_TARGET_MODE(load_flags),
                                  T1_Parse_Glyph );
     if ( error )
       goto Exit;
diff --git a/src/type1/t1gload.h b/src/type1/t1gload.h
index 4b7ba5d..0324a0d 100644
--- a/src/type1/t1gload.h
+++ b/src/type1/t1gload.h
@@ -35,7 +35,7 @@ FT_BEGIN_HEADER
   T1_Load_Glyph( T1_GlyphSlot  glyph,
                  T1_Size       size,
                  FT_UInt       glyph_index,
-                 FT_Int        load_flags );
+                 FT_Int32      load_flags );
 
 
 FT_END_HEADER