Blame SOURCES/freetype-2.4.11-fix-emboldening.patch

57e9c6
--- freetype-2.4.11/include/freetype/internal/ftcalc.h
57e9c6
+++ freetype-2.4.11/include/freetype/internal/ftcalc.h
57e9c6
@@ -156,6 +156,13 @@ FT_BEGIN_HEADER
57e9c6
                      FT_Pos  out_y );
57e9c6
 
57e9c6
 
57e9c6
+  /*
57e9c6
+   *  Return the most significant bit index.
57e9c6
+   */
57e9c6
+  FT_BASE( FT_Int )
57e9c6
+  FT_MSB( FT_UInt32 z );
57e9c6
+
57e9c6
+
57e9c6
 #define INT_TO_F26DOT6( x )    ( (FT_Long)(x) << 6  )
57e9c6
 #define INT_TO_F2DOT14( x )    ( (FT_Long)(x) << 14 )
57e9c6
 #define INT_TO_FIXED( x )      ( (FT_Long)(x) << 16 )
57e9c6
--- freetype-2.4.11/src/base/ftcalc.c
57e9c6
+++ freetype-2.4.11/src/base/ftcalc.c
57e9c6
@@ -103,6 +103,42 @@
57e9c6
   }
57e9c6
 
57e9c6
 
57e9c6
+  FT_BASE_DEF ( FT_Int )
57e9c6
+  FT_MSB( FT_UInt32 z )
57e9c6
+  {
57e9c6
+    FT_Int shift = 0;
57e9c6
+
57e9c6
+    /* determine msb bit index in `shift' */
57e9c6
+    if ( z >= ( 1L << 16 ) )
57e9c6
+    {
57e9c6
+      z     >>= 16;
57e9c6
+      shift  += 16;
57e9c6
+    }
57e9c6
+    if ( z >= ( 1L << 8 ) )
57e9c6
+    {
57e9c6
+      z     >>= 8;
57e9c6
+      shift  += 8;
57e9c6
+    }
57e9c6
+    if ( z >= ( 1L << 4 ) )
57e9c6
+    {
57e9c6
+      z     >>= 4;
57e9c6
+      shift  += 4;
57e9c6
+    }
57e9c6
+    if ( z >= ( 1L << 2 ) )
57e9c6
+    {
57e9c6
+      z     >>= 2;
57e9c6
+      shift  += 2;
57e9c6
+    }
57e9c6
+    if ( z >= ( 1L << 1 ) )
57e9c6
+    {
57e9c6
+      z     >>= 1;
57e9c6
+      shift  += 1;
57e9c6
+    }
57e9c6
+
57e9c6
+    return shift;
57e9c6
+  }
57e9c6
+
57e9c6
+
57e9c6
 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
57e9c6
 
57e9c6
   /* documentation is in ftcalc.h */
57e9c6
--- freetype-2.4.11/src/base/ftoutln.c
57e9c6
+++ freetype-2.4.11/src/base/ftoutln.c
57e9c6
@@ -930,10 +930,15 @@
57e9c6
       v_prev  = points[last];
57e9c6
       v_cur   = v_first;
57e9c6
 
57e9c6
-      /* compute the incoming vector and its length */
57e9c6
+      /* compute the incoming normalized vector */
57e9c6
       in.x = v_cur.x - v_prev.x;
57e9c6
       in.y = v_cur.y - v_prev.y;
57e9c6
       l_in = FT_Vector_Length( &in );
57e9c6
+      if ( l_in )
57e9c6
+      {
57e9c6
+        in.x = FT_DivFix( in.x, l_in );
57e9c6
+        in.y = FT_DivFix( in.y, l_in );
57e9c6
+      }
57e9c6
 
57e9c6
       for ( n = first; n <= last; n++ )
57e9c6
       {
57e9c6
@@ -942,20 +947,27 @@
57e9c6
         else
57e9c6
           v_next = v_first;
57e9c6
 
57e9c6
-        /* compute the outgoing vector and its length */
57e9c6
+        /* compute the outgoing normalized vector */
57e9c6
         out.x = v_next.x - v_cur.x;
57e9c6
         out.y = v_next.y - v_cur.y;
57e9c6
         l_out = FT_Vector_Length( &out );
57e9c6
+        if ( l_out )
57e9c6
+        {
57e9c6
+          out.x = FT_DivFix( out.x, l_out );
57e9c6
+          out.y = FT_DivFix( out.y, l_out );
57e9c6
+        }
57e9c6
 
57e9c6
-        d = l_in * l_out + in.x * out.x + in.y * out.y;
57e9c6
+        d = FT_MulFix( in.x, out.x ) + FT_MulFix( in.y, out.y );
57e9c6
 
57e9c6
         /* shift only if turn is less then ~160 degrees */
57e9c6
-        if ( 16 * d > l_in * l_out )
57e9c6
+        if ( d > -0xF000L )
57e9c6
         {
57e9c6
+          d = d + 0x10000L;
57e9c6
+
57e9c6
           /* shift components are aligned along bisector        */
57e9c6
           /* and directed according to the outline orientation. */
57e9c6
-          shift.x = l_out * in.y + l_in * out.y;
57e9c6
-          shift.y = l_out * in.x + l_in * out.x;
57e9c6
+          shift.x = in.y + out.y;
57e9c6
+          shift.y = in.x + out.x;
57e9c6
 
57e9c6
           if ( orientation == FT_ORIENTATION_TRUETYPE )
57e9c6
             shift.x = -shift.x;
57e9c6
@@ -963,18 +975,19 @@
57e9c6
             shift.y = -shift.y;
57e9c6
 
57e9c6
           /* threshold strength to better handle collapsing segments */
57e9c6
-          l = FT_MIN( l_in, l_out );
57e9c6
-          q = out.x * in.y - out.y * in.x;
57e9c6
+          q = FT_MulFix( out.x, in.y ) - FT_MulFix( out.y, in.x );
57e9c6
           if ( orientation == FT_ORIENTATION_TRUETYPE )
57e9c6
             q = -q;
57e9c6
 
57e9c6
-          if ( FT_MulDiv( xstrength, q, l ) < d )
57e9c6
+          l = FT_MIN( l_in, l_out );
57e9c6
+
57e9c6
+          if ( FT_MulFix( xstrength, q ) <= FT_MulFix( d, l ) )
57e9c6
             shift.x = FT_MulDiv( shift.x, xstrength, d );
57e9c6
           else
57e9c6
             shift.x = FT_MulDiv( shift.x, l, q );
57e9c6
 
57e9c6
           
57e9c6
-          if ( FT_MulDiv( ystrength, q, l ) < d )
57e9c6
+          if ( FT_MulFix( ystrength, q ) <= FT_MulFix( d, l ) )
57e9c6
             shift.y = FT_MulDiv( shift.y, ystrength, d );
57e9c6
           else
57e9c6
             shift.y = FT_MulDiv( shift.y, l, q );
57e9c6
@@ -1002,6 +1015,8 @@
57e9c6
   FT_EXPORT_DEF( FT_Orientation )
57e9c6
   FT_Outline_Get_Orientation( FT_Outline*  outline )
57e9c6
   {
57e9c6
+    FT_BBox     cbox;
57e9c6
+    FT_Int      xshift, yshift;
57e9c6
     FT_Vector*  points;
57e9c6
     FT_Vector   v_prev, v_cur;
57e9c6
     FT_Int      c, n, first;
57e9c6
@@ -1016,6 +1031,14 @@
57e9c6
     /* cubic or quadratic curves, this test deals with the polygon    */
57e9c6
     /* only which is spanned up by the control points.                */
57e9c6
 
57e9c6
+    FT_Outline_Get_CBox( outline, &cbox );
57e9c6
+
57e9c6
+    xshift = FT_MSB( FT_ABS( cbox.xMax ) | FT_ABS( cbox.xMin ) ) - 14;
57e9c6
+    xshift = FT_MAX( xshift, 0 );
57e9c6
+
57e9c6
+    yshift = FT_MSB( cbox.yMax - cbox.yMin ) - 14;
57e9c6
+    yshift = FT_MAX( yshift, 0 );
57e9c6
+
57e9c6
     points = outline->points;
57e9c6
 
57e9c6
     first = 0;
57e9c6
@@ -1029,7 +1052,8 @@
57e9c6
       for ( n = first; n <= last; n++ )
57e9c6
       {
57e9c6
         v_cur = points[n];
57e9c6
-        area += ( v_cur.y - v_prev.y ) * ( v_cur.x + v_prev.x );
57e9c6
+        area += ( ( v_cur.y - v_prev.y ) >> yshift ) *
57e9c6
+                ( ( v_cur.x + v_prev.x ) >> xshift );
57e9c6
         v_prev = v_cur;
57e9c6
       }
57e9c6
 
57e9c6
--- freetype-2.4.11/src/base/fttrigon.c
57e9c6
+++ freetype-2.4.11/src/base/fttrigon.c
57e9c6
@@ -104,43 +104,14 @@
57e9c6
   static FT_Int
57e9c6
   ft_trig_prenorm( FT_Vector*  vec )
57e9c6
   {
57e9c6
-    FT_Fixed  x, y, z;
57e9c6
+    FT_Fixed  x, y;
57e9c6
     FT_Int    shift;
57e9c6
 
57e9c6
 
57e9c6
     x = vec->x;
57e9c6
     y = vec->y;
57e9c6
 
57e9c6
-    z     = ( ( x >= 0 ) ? x : - x ) | ( (y >= 0) ? y : -y );
57e9c6
-    shift = 0;
57e9c6
-
57e9c6
-#if 1
57e9c6
-    /* determine msb bit index in `shift' */
57e9c6
-    if ( z >= ( 1L << 16 ) )
57e9c6
-    {
57e9c6
-      z     >>= 16;
57e9c6
-      shift  += 16;
57e9c6
-    }
57e9c6
-    if ( z >= ( 1L << 8 ) )
57e9c6
-    {
57e9c6
-      z     >>= 8;
57e9c6
-      shift  += 8;
57e9c6
-    }
57e9c6
-    if ( z >= ( 1L << 4 ) )
57e9c6
-    {
57e9c6
-      z     >>= 4;
57e9c6
-      shift  += 4;
57e9c6
-    }
57e9c6
-    if ( z >= ( 1L << 2 ) )
57e9c6
-    {
57e9c6
-      z     >>= 2;
57e9c6
-      shift  += 2;
57e9c6
-    }
57e9c6
-    if ( z >= ( 1L << 1 ) )
57e9c6
-    {
57e9c6
-      z    >>= 1;
57e9c6
-      shift += 1;
57e9c6
-    }
57e9c6
+    shift = FT_MSB( FT_ABS( x ) | FT_ABS( y ) );
57e9c6
 
57e9c6
     if ( shift <= 27 )
57e9c6
     {
57e9c6
@@ -156,33 +127,6 @@
57e9c6
       shift  = -shift;
57e9c6
     }
57e9c6
 
57e9c6
-#else /* 0 */
57e9c6
-
57e9c6
-    if ( z < ( 1L << 27 ) )
57e9c6
-    {
57e9c6
-      do
57e9c6
-      {
57e9c6
-        shift++;
57e9c6
-        z <<= 1;
57e9c6
-      } while ( z < ( 1L << 27 ) );
57e9c6
-      vec->x = x << shift;
57e9c6
-      vec->y = y << shift;
57e9c6
-    }
57e9c6
-    else if ( z > ( 1L << 28 ) )
57e9c6
-    {
57e9c6
-      do
57e9c6
-      {
57e9c6
-        shift++;
57e9c6
-        z >>= 1;
57e9c6
-      } while ( z > ( 1L << 28 ) );
57e9c6
-
57e9c6
-      vec->x = x >> shift;
57e9c6
-      vec->y = y >> shift;
57e9c6
-      shift  = -shift;
57e9c6
-    }
57e9c6
-
57e9c6
-#endif /* 0 */
57e9c6
-
57e9c6
     return shift;
57e9c6
   }
57e9c6