1 /***************************************************************************/
2 /*                                                                         */
3 /*  ftcalc.h                                                               */
4 /*                                                                         */
5 /*    Arithmetic computations (specification).                             */
6 /*                                                                         */
7 /*  Copyright 1996-2006, 2008, 2009, 2012-2013 by                          */
8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9 /*                                                                         */
10 /*  This file is part of the FreeType project, and may only be used,       */
11 /*  modified, and distributed under the terms of the FreeType project      */
12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13 /*  this file you indicate that you have read the license and              */
14 /*  understand and accept it fully.                                        */
15 /*                                                                         */
16 /***************************************************************************/
17 
18 
19 #ifndef __FTCALC_H__
20 #define __FTCALC_H__
21 
22 
23 #include <ft2build.h>
24 #include FT_FREETYPE_H
25 
26 
27 FT_BEGIN_HEADER
28 
29 
30 #if 0
31 
32   /*************************************************************************/
33   /*                                                                       */
34   /* <Function>                                                            */
35   /*    FT_SqrtFixed                                                       */
36   /*                                                                       */
37   /* <Description>                                                         */
38   /*    Computes the square root of a 16.16 fixed-point value.             */
39   /*                                                                       */
40   /* <Input>                                                               */
41   /*    x :: The value to compute the root for.                            */
42   /*                                                                       */
43   /* <Return>                                                              */
44   /*    The result of `sqrt(x)'.                                           */
45   /*                                                                       */
46   /* <Note>                                                                */
47   /*    This function is not very fast.                                    */
48   /*                                                                       */
49   FT_BASE( FT_Int32 )
50   FT_SqrtFixed( FT_Int32  x );
51 
52 #endif /* 0 */
53 
54 
55   /*************************************************************************/
56   /*                                                                       */
57   /* FT_MulDiv() and FT_MulFix() are declared in freetype.h.               */
58   /*                                                                       */
59   /*************************************************************************/
60 
61 
62   /*************************************************************************/
63   /*                                                                       */
64   /* <Function>                                                            */
65   /*    FT_MulDiv_No_Round                                                 */
66   /*                                                                       */
67   /* <Description>                                                         */
68   /*    A very simple function used to perform the computation `(a*b)/c'   */
69   /*    (without rounding) with maximum accuracy (it uses a 64-bit         */
70   /*    intermediate integer whenever necessary).                          */
71   /*                                                                       */
72   /*    This function isn't necessarily as fast as some processor specific */
73   /*    operations, but is at least completely portable.                   */
74   /*                                                                       */
75   /* <Input>                                                               */
76   /*    a :: The first multiplier.                                         */
77   /*    b :: The second multiplier.                                        */
78   /*    c :: The divisor.                                                  */
79   /*                                                                       */
80   /* <Return>                                                              */
81   /*    The result of `(a*b)/c'.  This function never traps when trying to */
82   /*    divide by zero; it simply returns `MaxInt' or `MinInt' depending   */
83   /*    on the signs of `a' and `b'.                                       */
84   /*                                                                       */
85   FT_BASE( FT_Long )
86   FT_MulDiv_No_Round( FT_Long  a,
87                       FT_Long  b,
88                       FT_Long  c );
89 
90 
91   /*
92    *  A variant of FT_Matrix_Multiply which scales its result afterwards.
93    *  The idea is that both `a' and `b' are scaled by factors of 10 so that
94    *  the values are as precise as possible to get a correct result during
95    *  the 64bit multiplication.  Let `sa' and `sb' be the scaling factors of
96    *  `a' and `b', respectively, then the scaling factor of the result is
97    *  `sa*sb'.
98    */
99   FT_BASE( void )
100   FT_Matrix_Multiply_Scaled( const FT_Matrix*  a,
101                              FT_Matrix        *b,
102                              FT_Long           scaling );
103 
104 
105   /*
106    *  A variant of FT_Vector_Transform.  See comments for
107    *  FT_Matrix_Multiply_Scaled.
108    */
109   FT_BASE( void )
110   FT_Vector_Transform_Scaled( FT_Vector*        vector,
111                               const FT_Matrix*  matrix,
112                               FT_Long           scaling );
113 
114 
115   /*
116    *  Return -1, 0, or +1, depending on the orientation of a given corner.
117    *  We use the Cartesian coordinate system, with positive vertical values
118    *  going upwards.  The function returns +1 if the corner turns to the
119    *  left, -1 to the right, and 0 for undecidable cases.
120    */
121   FT_BASE( FT_Int )
122   ft_corner_orientation( FT_Pos  in_x,
123                          FT_Pos  in_y,
124                          FT_Pos  out_x,
125                          FT_Pos  out_y );
126 
127   /*
128    *  Return TRUE if a corner is flat or nearly flat.  This is equivalent to
129    *  saying that the angle difference between the `in' and `out' vectors is
130    *  very small.
131    */
132   FT_BASE( FT_Int )
133   ft_corner_is_flat( FT_Pos  in_x,
134                      FT_Pos  in_y,
135                      FT_Pos  out_x,
136                      FT_Pos  out_y );
137 
138 
139   /*
140    *  Return the most significant bit index.
141    */
142   FT_BASE( FT_Int )
143   FT_MSB( FT_UInt32  z );
144 
145 
146   /*
147    *  Return sqrt(x*x+y*y), which is the same as `FT_Vector_Length' but uses
148    *  two fixed-point arguments instead.
149    */
150   FT_BASE( FT_Fixed )
151   FT_Hypot( FT_Fixed  x,
152             FT_Fixed  y );
153 
154 
155 #define INT_TO_F26DOT6( x )    ( (FT_Long)(x) << 6  )
156 #define INT_TO_F2DOT14( x )    ( (FT_Long)(x) << 14 )
157 #define INT_TO_FIXED( x )      ( (FT_Long)(x) << 16 )
158 #define F2DOT14_TO_FIXED( x )  ( (FT_Long)(x) << 2  )
159 #define FLOAT_TO_FIXED( x )    ( (FT_Long)( x * 65536.0 ) )
160 #define FIXED_TO_INT( x )      ( FT_RoundFix( x ) >> 16 )
161 
162 #define ROUND_F26DOT6( x )     ( x >= 0 ? (    ( (x) + 32 ) & -64 )     \
163                                         : ( -( ( 32 - (x) ) & -64 ) ) )
164 
165 
166 FT_END_HEADER
167 
168 #endif /* __FTCALC_H__ */
169 
170 
171 /* END */
172