a small improvement to the Type 1 hinter, that comes from research with the auto-hinter. Nothing fancy but gets rid of the un-normalized widths :-)
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
diff --git a/src/type1/t1hinter.c b/src/type1/t1hinter.c
index 1d8648a..bb2f235 100644
--- a/src/type1/t1hinter.c
+++ b/src/type1/t1hinter.c
@@ -889,16 +889,34 @@
{
T1_Snap_Zone* zone = hints->snap_heights;
T1_Snap_Zone* zone_limit = zone + hints->num_snap_heights;
+ T1_Pos best_dist = 32000;
+ T1_Snap_Zone* best_zone = 0;
for ( ; zone < zone_limit; zone++ )
{
- if ( width_pix < zone->min )
- break;
-
- if ( width_pix <= zone->max )
+ T1_Pos dist;
+
+ dist = width_pix - zone->min; if (dist < 0) dist = -dist;
+ if (dist < best_dist)
{
- width_pix = zone->pix;
- break;
+ best_zone = zone;
+ best_dist = dist;
+ }
+ }
+
+ if (best_zone)
+ {
+ if (width_pix > best_zone->pix)
+ {
+ width_pix -= 0x20;
+ if (width_pix < best_zone->pix)
+ width_pix = best_zone->pix;
+ }
+ else
+ {
+ width_pix += 0x20;
+ if (width_pix > best_zone->pix)
+ width_pix = best_zone->pix;
}
}
}
@@ -1053,18 +1071,36 @@
/* Snap pixel width if in stem snap range */
{
- T1_Snap_Zone* zone = hints->snap_widths;
- T1_Snap_Zone* zone_limit = zone + hints->num_snap_widths;
+ T1_Snap_Zone* zone = hints->snap_heights;
+ T1_Snap_Zone* zone_limit = zone + hints->num_snap_heights;
+ T1_Pos best_dist = 32000;
+ T1_Snap_Zone* best_zone = 0;
for ( ; zone < zone_limit; zone++ )
{
- if ( width_pix < zone->min )
- break;
-
- if ( width_pix <= zone->max )
+ T1_Pos dist;
+
+ dist = width_pix - zone->min; if (dist < 0) dist = -dist;
+ if (dist < best_dist)
{
- width_pix = zone->pix;
- break;
+ best_zone = zone;
+ best_dist = dist;
+ }
+ }
+
+ if (best_zone)
+ {
+ if (width_pix > best_zone->pix)
+ {
+ width_pix -= 0x20;
+ if (width_pix < best_zone->pix)
+ width_pix = best_zone->pix;
+ }
+ else
+ {
+ width_pix += 0x20;
+ if (width_pix > best_zone->pix)
+ width_pix = best_zone->pix;
}
}
}