* src/pshinter/pshalgo3.c, src/autohint/ahangles.c, src/autohint/ahangles.h, src/autohint/ahglyph.c, src/autohint/ahhint.c, src/autohint/ahtypes.h: the automatic and Postscript hinter now automatically detect inflection points in glyph outlines and treats them specially. This is very useful to prevent nasty effect like the disappearing diagonals of "S" and "s" in many, many fonts..
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
diff --git a/src/autohint/ahangles.c b/src/autohint/ahangles.c
index 1a13b27..a4ef842 100644
--- a/src/autohint/ahangles.c
+++ b/src/autohint/ahangles.c
@@ -127,4 +127,20 @@
}
+ FT_LOCAL_DEF( AH_Angle )
+ ah_angle_diff( AH_Angle angle1,
+ AH_Angle angle2 )
+ {
+ AH_Angle delta;
+
+ delta = ( angle2 - angle1 );
+ if ( delta < 0 )
+ delta += AH_2PI;
+
+ if ( delta > AH_PI )
+ delta -= AH_2PI;
+
+ return delta;
+ }
+
/* END */
diff --git a/src/autohint/ahangles.h b/src/autohint/ahangles.h
index d509e00..f46bfaa 100644
--- a/src/autohint/ahangles.h
+++ b/src/autohint/ahangles.h
@@ -51,6 +51,11 @@ FT_BEGIN_HEADER
ah_angle( FT_Vector* v );
+ FT_LOCAL( AH_Angle )
+ ah_angle_diff( AH_Angle angle1,
+ AH_Angle angle2 );
+
+
FT_END_HEADER
#endif /* __AHANGLES_H__ */
diff --git a/src/autohint/ahglyph.c b/src/autohint/ahglyph.c
index 2f0582e..8939b74 100644
--- a/src/autohint/ahglyph.c
+++ b/src/autohint/ahglyph.c
@@ -674,6 +674,120 @@
}
}
+ /* compute all inflex points in a given glyph */
+ static void
+ ah_outline_compute_inflections( AH_Outline* outline )
+ {
+ AH_Point** contour = outline->contours;
+ AH_Point** contour_limit = contour + outline->num_contours;
+
+ /* load original coordinates in (u,v) */
+ ah_setup_uv( outline, ah_uv_fxy );
+
+ /* do each contour separately */
+ for ( ; contour < contour_limit; contour++ )
+ {
+ FT_Vector vec;
+ AH_Point* point = contour[0];
+ AH_Point* first = point;
+ AH_Point* start = point;
+ AH_Point* end = point;
+ AH_Point* before;
+ AH_Point* after;
+ AH_Angle angle_in, angle_seg, angle_out;
+ AH_Angle diff_in, diff_out;
+ FT_Int finished = 0;
+
+ /* compute first segment in contour */
+ first = point;
+
+ start = end = first;
+ do
+ {
+ end = end->next;
+ if ( end == first )
+ goto Skip;
+ }
+ while ( end->u == first->u && end->v == first->v );
+
+ vec.x = end->u - start->u;
+ vec.y = end->v - start->v;
+ angle_seg = ah_angle( &vec );
+
+ /* extend the segment start whenever possible */
+ before = start;
+ do
+ {
+ do
+ {
+ start = before;
+ before = before->prev;
+ if ( before == first )
+ goto Skip;
+ }
+ while ( before->u == start->u && before->v == start->v );
+
+ vec.x = start->u - before->u;
+ vec.y = start->v - before->v;
+ angle_in = ah_angle( &vec );
+ }
+ while ( angle_in == angle_seg );
+
+ first = start;
+ diff_in = ah_angle_diff( angle_in, angle_seg );
+
+ /* now, process all segments in the contour */
+ do
+ {
+ /* first, extend current segment's end whenever possible */
+ after = end;
+ do
+ {
+ do
+ {
+ end = after;
+ after = after->next;
+ if ( after == first )
+ finished = 1;
+ }
+ while ( end->u == after->u && end->v == after->v );
+
+ vec.x = after->u - end->u;
+ vec.y = after->v - end->v;
+ angle_out = ah_angle( &vec );
+ }
+ while ( angle_out == angle_seg );
+
+ diff_out = ah_angle_diff( angle_seg, angle_out );
+
+ if ( diff_in ^ diff_out < 0 )
+ {
+ /* diff_in and diff_out have different signs, we have */
+ /* inflection points here... */
+
+ do
+ {
+ start->flags |= ah_flag_inflection;
+ start = start->next;
+ }
+ while ( start != end );
+
+ start->flags |= ah_flag_inflection;
+ }
+
+ start = end;
+ end = after;
+ angle_seg = angle_out;
+ diff_in = diff_out;
+ }
+ while ( !finished );
+
+ Skip:
+ ;
+ }
+ }
+
+
FT_LOCAL_DEF( void )
ah_outline_compute_segments( AH_Outline* outline )
@@ -1290,6 +1404,7 @@
ah_outline_compute_segments( outline );
ah_outline_link_segments ( outline );
ah_outline_compute_edges ( outline );
+ ah_outline_compute_inflections( outline );
}
diff --git a/src/autohint/ahhint.c b/src/autohint/ahhint.c
index 243b4d0..0aa5f2e 100644
--- a/src/autohint/ahhint.c
+++ b/src/autohint/ahhint.c
@@ -612,7 +612,8 @@
#ifndef AH_OPTION_NO_WEAK_INTERPOLATION
/* if this point is candidate to weak interpolation, we will */
/* interpolate it after all strong points have been processed */
- if ( point->flags & ah_flag_weak_interpolation )
+ if ( (point->flags & ah_flag_weak_interpolation) &&
+ !(point->flags & ah_flag_inflection) )
continue;
#endif
diff --git a/src/autohint/ahtypes.h b/src/autohint/ahtypes.h
index cd62101..4c91655 100644
--- a/src/autohint/ahtypes.h
+++ b/src/autohint/ahtypes.h
@@ -147,6 +147,7 @@ FT_BEGIN_HEADER
/* weak interpolation */
#define ah_flag_weak_interpolation 256
+#define ah_flag_inflection 512
typedef FT_Int AH_Flags;
diff --git a/src/pshinter/pshalgo3.c b/src/pshinter/pshalgo3.c
index ccf5bc2..18ea48d 100644
--- a/src/pshinter/pshalgo3.c
+++ b/src/pshinter/pshalgo3.c
@@ -1422,7 +1422,8 @@
point->dir_in != point->dir_out )
continue;
- if ( !psh3_point_is_extremum( point ) )
+ if ( !psh3_point_is_extremum( point ) &&
+ !psh3_point_is_inflection( point ) )
continue;
point->flags &= ~PSH3_POINT_SMOOTH;