modified the TrueType interpreter to let it use the new trigonometric functions provided in "fttrigon.h". This gets rid of some old 64-bit computation routines, as well as many warnings when compiling the library with the "long long" 64-bit integer type.
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
diff --git a/ChangeLog b/ChangeLog
index b1cb853..cde12da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2001-06-14 David Turner <david@freetype.org>
+
+ * src/base/ftcalc.c, include/internal/ftcalc.h, src/truetype/ttinterp.c,
+ include/config/ftoption.h: modified the TrueType interpreter to let it
+ use the new trigonometric functions provided in "fttrigon.h". This
+ gets rid of some old 64-bit computation routines, as well as many
+ warnings when compiling the library with the "long long" 64-bit
+ integer type.
+
+
2001-06-11 Mike Owens <MOwens@amtdatasouth.com>
* src/base/ftcalc.c (FT_MulDiv, FT_DivFix, FT_Sqrt64): Remove
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index 567c865..dafcd3a 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -237,7 +237,7 @@ FT_BEGIN_HEADER
/* Used for debugging, this configuration macro should disappear */
/* soon. */
/* */
-#define FT_CONFIG_OPTION_OLD_CALCS
+#undef FT_CONFIG_OPTION_OLD_CALCS
/*************************************************************************/
diff --git a/include/freetype/internal/ftcalc.h b/include/freetype/internal/ftcalc.h
index 477083f..e47f402 100644
--- a/include/freetype/internal/ftcalc.h
+++ b/include/freetype/internal/ftcalc.h
@@ -27,18 +27,19 @@
FT_BEGIN_HEADER
-#ifdef FT_LONG64
+/* OLD 64-bits internal API */
+#ifdef FT_CONFIG_OPTION_OLD_CALCS
+
+# ifdef FT_LONG64
typedef FT_INT64 FT_Int64;
-#define ADD_64( x, y, z ) z = (x) + (y)
-#define MUL_64( x, y, z ) z = (FT_Int64)(x) * (y)
-#define DIV_64( x, y ) ( (x) / (y) )
+# define ADD_64( x, y, z ) z = (x) + (y)
+# define MUL_64( x, y, z ) z = (FT_Int64)(x) * (y)
+# define DIV_64( x, y ) ( (x) / (y) )
-#ifdef FT_CONFIG_OPTION_OLD_CALCS
-
-#define SQRT_64( z ) FT_Sqrt64( z )
+# define SQRT_64( z ) FT_Sqrt64( z )
/*************************************************************************/
/* */
@@ -58,10 +59,8 @@ FT_BEGIN_HEADER
/* */
FT_EXPORT( FT_Int32 ) FT_Sqrt64( FT_Int64 l );
-#endif /* FT_CONFIG_OPTION_OLD_CALCS */
-
-#else /* FT_LONG64 */
+# else /* !FT_LONG64 */
typedef struct FT_Int64_
@@ -72,9 +71,9 @@ FT_BEGIN_HEADER
} FT_Int64;
-#define ADD_64( x, y, z ) FT_Add64( &x, &y, &z )
-#define MUL_64( x, y, z ) FT_MulTo64( x, y, &z )
-#define DIV_64( x, y ) FT_Div64by32( &x, y )
+# define ADD_64( x, y, z ) FT_Add64( &x, &y, &z )
+# define MUL_64( x, y, z ) FT_MulTo64( x, y, &z )
+# define DIV_64( x, y ) FT_Div64by32( &x, y )
/*************************************************************************/
@@ -146,9 +145,7 @@ FT_BEGIN_HEADER
FT_Int32 y );
-#ifdef FT_CONFIG_OPTION_OLD_CALCS
-
-#define SQRT_64( z ) FT_Sqrt64( &z )
+# define SQRT_64( z ) FT_Sqrt64( &z )
/*************************************************************************/
/* */
@@ -168,10 +165,10 @@ FT_BEGIN_HEADER
/* */
FT_EXPORT( FT_Int32 ) FT_Sqrt64( FT_Int64* x );
-#endif /* FT_CONFIG_OPTION_OLD_CALCS */
+# endif /* !FT_LONG64 */
+#endif /* FT_CONFIG_OPTION_OLD_CALCS */
-#endif /* FT_LONG64 */
FT_EXPORT( FT_Int32 ) FT_SqrtFixed( FT_Int32 x );
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index c4a60b1..ab2ced3 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -38,6 +38,27 @@
#include FT_INTERNAL_OBJECTS_H
+/* we need to define a 64-bits data type here */
+#ifndef FT_CONFIG_OPTION_OLD_CALCS
+
+# ifdef FT_LONG64
+
+ typedef FT_INT64 FT_Int64;
+
+# else
+
+ typedef struct FT_Int64_
+ {
+ FT_UInt32 lo;
+ FT_UInt32 hi;
+
+ } FT_Int64;
+
+# endif
+
+#endif
+
+
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c
index 1f5b6c7..43f5767 100644
--- a/src/truetype/ttinterp.c
+++ b/src/truetype/ttinterp.c
@@ -19,6 +19,7 @@
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_CALC_H
+#include FT_TRIGONOMETRY_H
#include FT_SYSTEM_H
#include "ttinterp.h"
@@ -31,10 +32,8 @@
#define TT_MULFIX FT_MulFix
#define TT_MULDIV FT_MulDiv
-
#define TT_INT64 FT_Int64
-
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
@@ -825,6 +824,7 @@
}
+ /* return length of given vector */
#ifdef FT_CONFIG_OPTION_OLD_CALCS
static FT_F26Dot6 Norm( FT_F26Dot6 X,
@@ -841,6 +841,18 @@
return (FT_F26Dot6)SQRT_64( T1 );
}
+#else /* !FT_CONFIG_OPTION_OLD_CALCS */
+
+ static FT_F26Dot6 Norm( FT_F26Dot6 X,
+ FT_F26Dot6 Y )
+ {
+ FT_Vector v;
+
+ v.x = X;
+ v.y = Y;
+ return FT_Vector_Length( &v );
+ }
+
#endif /* FT_CONFIG_OPTION_OLD_CALCS */
@@ -1214,21 +1226,9 @@
{
FT_Long x, y;
-
-#ifdef FT_CONFIG_OPTION_OLD_CALCS
-
x = TT_MULDIV( CUR.GS.projVector.x, CUR.tt_metrics.x_ratio, 0x4000 );
y = TT_MULDIV( CUR.GS.projVector.y, CUR.tt_metrics.y_ratio, 0x4000 );
CUR.tt_metrics.ratio = Norm( x, y );
-
-#else
-
- x = TT_MULDIV( CUR.GS.projVector.x, CUR.tt_metrics.x_ratio, 0x8000 );
- y = TT_MULDIV( CUR.GS.projVector.y, CUR.tt_metrics.y_ratio, 0x8000 );
- CUR.tt_metrics.ratio = FT_Sqrt32( x * x + y * y ) << 1;
-
-#endif /* FT_CONFIG_OPTION_OLD_CALCS */
-
}
return CUR.tt_metrics.ratio;
@@ -2287,123 +2287,16 @@
FT_F26Dot6 Vy,
FT_UnitVector* R )
{
- FT_F26Dot6 u, v, d;
- FT_Int shift;
- FT_ULong H, L, L2, hi, lo, med;
-
-
- u = ABS( Vx );
- v = ABS( Vy );
-
- if ( u < v )
- {
- d = u;
- u = v;
- v = d;
- }
-
- R->x = 0;
- R->y = 0;
-
- /* check that we are not trying to normalise zero! */
- if ( u == 0 )
- return SUCCESS;
-
- /* compute (u*u + v*v) on 64 bits with two 32-bit registers [H:L] */
- hi = (FT_ULong)u >> 16;
- lo = (FT_ULong)u & 0xFFFF;
- med = hi * lo;
-
- H = hi * hi + ( med >> 15 );
- med <<= 17;
- L = lo * lo + med;
- if ( L < med )
- H++;
-
- hi = (FT_ULong)v >> 16;
- lo = (FT_ULong)v & 0xFFFF;
- med = hi * lo;
-
- H += hi * hi + ( med >> 15 );
- med <<= 17;
- L2 = lo * lo + med;
- if ( L2 < med )
- H++;
-
- L += L2;
- if ( L < L2 )
- H++;
-
- /* if the value is smaller than 32-bits */
- if ( H == 0 )
- {
- shift = 0;
- while ( ( L & 0xC0000000L ) == 0 )
- {
- L <<= 2;
- shift++;
- }
-
- d = FT_Sqrt32( L );
- R->x = (FT_F2Dot14)TT_MULDIV( Vx << shift, 0x4000, d );
- R->y = (FT_F2Dot14)TT_MULDIV( Vy << shift, 0x4000, d );
- }
- /* if the value is greater than 64-bits */
- else
- {
- shift = 0;
- while ( H )
- {
- L = ( L >> 2 ) | ( H << 30 );
- H >>= 2;
- shift++;
- }
-
- d = FT_Sqrt32( L );
- R->x = (FT_F2Dot14)TT_MULDIV( Vx >> shift, 0x4000, d );
- R->y = (FT_F2Dot14)TT_MULDIV( Vy >> shift, 0x4000, d );
- }
-
- {
- FT_ULong x, y, w;
- FT_Int sx, sy;
-
-
- sx = R->x >= 0 ? 1 : -1;
- sy = R->y >= 0 ? 1 : -1;
- x = (FT_ULong)sx * R->x;
- y = (FT_ULong)sy * R->y;
-
- w = x * x + y * y;
-
- /* we now want to adjust (x,y) in order to have sqrt(w) == 0x4000 */
- /* which means 0x1000000 <= w < 0x1004000 */
- while ( w <= 0x10000000L )
- {
- /* increment the smallest coordinate */
- if ( x < y )
- x++;
- else
- y++;
-
- w = x * x + y * y;
- }
-
- while ( w >= 0x10040000L )
- {
- /* decrement the smallest coordinate */
- if ( x < y )
- x--;
- else
- y--;
-
- w = x * x + y * y;
- }
-
- R->x = sx * x;
- R->y = sy * y;
- }
+ FT_Vector v;
+ FT_Angle angle;
+
+ angle = FT_Atan2( Vx, Vy );
+ FT_Vector_Unit( &v, angle );
+
+ R->x = v.x >> 2;
+ R->y = v.y >> 2;
+
return SUCCESS;
}