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

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