Commit 5210306145ce372ec167cc79ae03563d1103217b

Werner Lemberg 2012-07-04T17:20:33

Fix Savannah bug #36091. * src/autofit/aflatin.c (af_latin_metrics_init_blues), src/autofit/aflatin2.c (af_latin2_metrics_init_blues): Change the constraint for testing round vs. flat segment: Accept either a small distance or a small angle.

diff --git a/ChangeLog b/ChangeLog
index 16ad35d..4cd2209 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2012-07-04  Werner Lemberg  <wl@gnu.org>
 
+	Fix Savannah bug #36091.
+
+	* src/autofit/aflatin.c (af_latin_metrics_init_blues),
+	src/autofit/aflatin2.c (af_latin2_metrics_init_blues): Change the
+	constraint for testing round vs. flat segment: Accept either a
+	small distance or a small angle.
+
+2012-07-04  Werner Lemberg  <wl@gnu.org>
+
 	[autofit] Beautify blue zone tracing.
 
 	* src/autofit/aflatin.c (af_latin_metrics_init_blues),
diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c
index 8ccef60..6f55d95 100644
--- a/src/autofit/aflatin.c
+++ b/src/autofit/aflatin.c
@@ -301,6 +301,7 @@
         /* lies, then inspect its previous and next points              */
         if ( best_point >= 0 )
         {
+          FT_Pos  best_x = points[best_point].x;
           FT_Int  prev, next;
           FT_Pos  dist;
 
@@ -317,9 +318,12 @@
             else
               prev = best_last;
 
-            dist = points[prev].y - best_y;
-            if ( dist < -5 || dist > 5 )
-              break;
+            dist = FT_ABS( points[prev].y - best_y );
+            /* accept a small distance or a small angle (both values are */
+            /* heuristic; value 20 corresponds to approx. 2.9 degrees)   */
+            if ( dist > 5 )
+              if ( FT_ABS( points[prev].x - best_x ) <= 20 * dist )
+                break;
 
           } while ( prev != best_point );
 
@@ -330,9 +334,10 @@
             else
               next = best_first;
 
-            dist = points[next].y - best_y;
-            if ( dist < -5 || dist > 5 )
-              break;
+            dist = FT_ABS( points[next].y - best_y );
+            if ( dist > 5 )
+              if ( FT_ABS( points[next].x - best_x ) <= 20 * dist )
+                break;
 
           } while ( next != best_point );
 
diff --git a/src/autofit/aflatin2.c b/src/autofit/aflatin2.c
index 50a6f8b..1aa312e 100644
--- a/src/autofit/aflatin2.c
+++ b/src/autofit/aflatin2.c
@@ -290,6 +290,7 @@
         /* segment; we first need to find in which contour the extremum */
         /* lies, then inspect its previous and next points              */
         {
+          FT_Pos  best_x = points[best_point].x;
           FT_Int  start, end, prev, next;
           FT_Pos  dist;
 
@@ -300,13 +301,16 @@
 
           do
           {
-            prev = start-1;
+            prev = start - 1;
             if ( prev < best_first )
               prev = best_last;
 
-            dist = points[prev].y - best_y;
-            if ( dist < -5 || dist > 5 )
-              break;
+            dist = FT_ABS( points[prev].y - best_y );
+            /* accept a small distance or a small angle (both values are */
+            /* heuristic; value 20 corresponds to approx. 2.9 degrees)   */
+            if ( dist > 5 )
+              if ( FT_ABS( points[prev].x - best_x ) <= 20 * dist )
+                break;
 
             start = prev;
 
@@ -314,13 +318,14 @@
 
           do
           {
-            next = end+1;
+            next = end + 1;
             if ( next > best_last )
               next = best_first;
 
-            dist = points[next].y - best_y;
-            if ( dist < -5 || dist > 5 )
-              break;
+            dist = FT_ABS( points[next].y - best_y );
+            if ( dist > 5 )
+              if ( FT_ABS( points[next].x - best_x ) <= 20 * dist )
+                break;
 
             end = next;