Commit b6de8e661251ebd14b363b8286e68ce16de20174

Alexei Podtelezhnikov 2013-01-23T23:31:41

[base, truetype] New internal FT_Hypot function. * include/freetype/fttrigon.h (FT_Hypot): Declare it. * src/base/fttrigon.c (FT_Hypot): Define it. * src/truetype/ttgload.c (TT_Process_Composite_Component): Use it instead of explicit expressions. * src/truetype/ttinterp.c (Current_Ratio, Normalize): Use it instead of TT_VecLen. (TT_VecLen): Removed.

diff --git a/ChangeLog b/ChangeLog
index f361519..11843b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2013-01-23  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
+	[base, truetype] New internal FT_Hypot function.
+
+	* include/freetype/fttrigon.h (FT_Hypot): Declare it.
+	* src/base/fttrigon.c (FT_Hypot): Define it.
+	* src/truetype/ttgload.c (TT_Process_Composite_Component): Use it
+	instead of explicit expressions.
+	* src/truetype/ttinterp.c (Current_Ratio, Normalize): Use it instead
+	of TT_VecLen.
+	(TT_VecLen): Removed.
+
+2013-01-23  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
 	[base] Fix integer overflow.
 
 	* src/base/ftoutln.c (FT_Outline_EmboldenXY): Normalize incoming and
diff --git a/include/freetype/fttrigon.h b/include/freetype/fttrigon.h
index f50e2b4..f4d688a 100644
--- a/include/freetype/fttrigon.h
+++ b/include/freetype/fttrigon.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType trigonometric functions (specification).                    */
 /*                                                                         */
-/*  Copyright 2001, 2003, 2005, 2007 by                                    */
+/*  Copyright 2001, 2003, 2005, 2007, 2013 by                              */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -339,6 +339,14 @@ FT_BEGIN_HEADER
                         FT_Fixed    length,
                         FT_Angle    angle );
 
+  /*
+   * Return sqrt(x*x+y*y), which is the same as FT_Vector_Length but uses
+   * two fixed-point arguments instead.
+   */ 
+  FT_BASE( FT_Fixed )
+  FT_Hypot( FT_Fixed x,
+            FT_Fixed y );
+
   /* */
 
 
diff --git a/src/base/fttrigon.c b/src/base/fttrigon.c
index e8cc3e3..25498f9 100644
--- a/src/base/fttrigon.c
+++ b/src/base/fttrigon.c
@@ -492,4 +492,19 @@
   }
 
 
+  /* documentation is in fttrigon.h */
+
+  FT_BASE_DEF( FT_Fixed )
+  FT_Hypot( FT_Fixed x,
+            FT_Fixed y )
+  {
+    FT_Vector  v;
+
+    v.x = x;
+    v.y = y;
+
+    return FT_Vector_Length( &v );
+  }
+
+
 /* END */
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 031a5fc..f611f45 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -22,6 +22,7 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_INTERNAL_SFNT_H
 #include FT_TRUETYPE_TAGS_H
+#include FT_TRIGONOMETRY_H
 #include FT_OUTLINE_H
 
 #include "ttgload.h"
@@ -1082,16 +1083,10 @@
   /*                                                                       */
   /* This algorithm is a guess and works much better than the above.       */
   /*                                                                       */
-        FT_Fixed  mac_xscale = FT_SqrtFixed(
-                                 (FT_Int32)FT_MulFix( subglyph->transform.xx,
-                                                      subglyph->transform.xx ) +
-                                 (FT_Int32)FT_MulFix( subglyph->transform.xy,
-                                                      subglyph->transform.xy ) );
-        FT_Fixed  mac_yscale = FT_SqrtFixed(
-                                 (FT_Int32)FT_MulFix( subglyph->transform.yy,
-                                                      subglyph->transform.yy ) +
-                                 (FT_Int32)FT_MulFix( subglyph->transform.yx,
-                                                      subglyph->transform.yx ) );
+        FT_Fixed  mac_xscale = FT_Hypot( subglyph->transform.xx,
+                                         subglyph->transform.xy );
+        FT_Fixed  mac_yscale = FT_Hypot( subglyph->transform.yy,
+                                         subglyph->transform.yx );
 
 
         x = FT_MulFix( x, mac_xscale );
diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c
index 1cbb351..f71a7ec 100644
--- a/src/truetype/ttinterp.c
+++ b/src/truetype/ttinterp.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    TrueType bytecode interpreter (body).                                */
 /*                                                                         */
-/*  Copyright 1996-2012                                                    */
+/*  Copyright 1996-2013                                                    */
 /*  by David Turner, Robert Wilhelm, and Werner Lemberg.                   */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -1542,21 +1542,6 @@
   }
 
 
-  /* return length of given vector */
-  static FT_F26Dot6
-  TT_VecLen( FT_F26Dot6  X,
-             FT_F26Dot6  Y )
-  {
-    FT_Vector  v;
-
-
-    v.x = X;
-    v.y = Y;
-
-    return FT_Vector_Length( &v );
-  }
-
-
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
@@ -1600,7 +1585,7 @@
                            CUR.GS.projVector.x );
           y = TT_MulFix14( CUR.tt_metrics.y_ratio,
                            CUR.GS.projVector.y );
-          CUR.tt_metrics.ratio = TT_VecLen( x, y );
+          CUR.tt_metrics.ratio = FT_Hypot( x, y );
         }
       }
     }
@@ -2658,7 +2643,7 @@
       Vy *= 0x4000;
     }
 
-    W = TT_VecLen( Vx, Vy );
+    W = FT_Hypot( Vx, Vy );
 
     R->x = (FT_F2Dot14)TT_DivFix14( Vx, W );
     R->y = (FT_F2Dot14)TT_DivFix14( Vy, W );