summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2013-01-23 23:31:41 -0500
committerAlexei Podtelezhnikov <apodtele@gmail.com>2013-01-23 23:31:41 -0500
commitb6de8e661251ebd14b363b8286e68ce16de20174 (patch)
treecb5070c0e05ef82b09d31a6f90c07867b81bd9cf
parentdcc0d070e00179b23766ff52d0fa63cd3ef5aea0 (diff)
downloadfreetype2-b6de8e661251ebd14b363b8286e68ce16de20174.tar.gz
[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.
-rw-r--r--ChangeLog12
-rw-r--r--include/freetype/fttrigon.h10
-rw-r--r--src/base/fttrigon.c15
-rw-r--r--src/truetype/ttgload.c15
-rw-r--r--src/truetype/ttinterp.c21
5 files changed, 44 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index f361519c6..11843b536 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 f50e2b420..f4d688abf 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 e8cc3e3a7..25498f9ee 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 031a5fc41..f611f457b 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 1cbb351ad..f71a7ec93 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 );