[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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
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 );