• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ftmisc.h                                                               */
4 /*                                                                         */
5 /*    Miscellaneous macros for stand-alone rasterizer (specification       */
6 /*    only).                                                               */
7 /*                                                                         */
8 /*  Copyright 2005-2017 by                                                 */
9 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
10 /*                                                                         */
11 /*  This file is part of the FreeType project, and may only be used        */
12 /*  modified and distributed under the terms of the FreeType project       */
13 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
14 /*  this file you indicate that you have read the license and              */
15 /*  understand and accept it fully.                                        */
16 /*                                                                         */
17 /***************************************************************************/
18 
19 
20   /***************************************************/
21   /*                                                 */
22   /* This file is *not* portable!  You have to adapt */
23   /* its definitions to your platform.               */
24   /*                                                 */
25   /***************************************************/
26 
27 #ifndef FTMISC_H_
28 #define FTMISC_H_
29 
30 
31   /* memset */
32 #include FT_CONFIG_STANDARD_LIBRARY_H
33 
34 #define FT_BEGIN_HEADER
35 #define FT_END_HEADER
36 
37 #define FT_LOCAL_DEF( x )   static x
38 
39 
40   /* from include/freetype/fttypes.h */
41 
42   typedef unsigned char  FT_Byte;
43   typedef signed int     FT_Int;
44   typedef unsigned int   FT_UInt;
45   typedef signed long    FT_Long;
46   typedef unsigned long  FT_ULong;
47   typedef signed long    FT_F26Dot6;
48   typedef int            FT_Error;
49 
50 #define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
51           ( ( (FT_ULong)_x1 << 24 ) |     \
52             ( (FT_ULong)_x2 << 16 ) |     \
53             ( (FT_ULong)_x3 <<  8 ) |     \
54               (FT_ULong)_x4         )
55 
56 
57   /* from include/freetype/ftsystem.h */
58 
59   typedef struct FT_MemoryRec_*  FT_Memory;
60 
61   typedef void* (*FT_Alloc_Func)( FT_Memory  memory,
62                                   long       size );
63 
64   typedef void (*FT_Free_Func)( FT_Memory  memory,
65                                 void*      block );
66 
67   typedef void* (*FT_Realloc_Func)( FT_Memory  memory,
68                                     long       cur_size,
69                                     long       new_size,
70                                     void*      block );
71 
72   typedef struct FT_MemoryRec_
73   {
74     void*            user;
75 
76     FT_Alloc_Func    alloc;
77     FT_Free_Func     free;
78     FT_Realloc_Func  realloc;
79 
80   } FT_MemoryRec;
81 
82 
83   /* from src/ftcalc.c */
84 
85 #if ( defined _WIN32 || defined _WIN64 )
86 
87   typedef __int64  FT_Int64;
88 
89 #else
90 
91 #include "inttypes.h"
92 
93   typedef int64_t  FT_Int64;
94 
95 #endif
96 
97 
98   static FT_Long
FT_MulDiv(FT_Long a,FT_Long b,FT_Long c)99   FT_MulDiv( FT_Long  a,
100              FT_Long  b,
101              FT_Long  c )
102   {
103     FT_Int   s;
104     FT_Long  d;
105 
106 
107     s = 1;
108     if ( a < 0 ) { a = -a; s = -1; }
109     if ( b < 0 ) { b = -b; s = -s; }
110     if ( c < 0 ) { c = -c; s = -s; }
111 
112     d = (FT_Long)( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c
113                          : 0x7FFFFFFFL );
114 
115     return ( s > 0 ) ? d : -d;
116   }
117 
118 
119   static FT_Long
FT_MulDiv_No_Round(FT_Long a,FT_Long b,FT_Long c)120   FT_MulDiv_No_Round( FT_Long  a,
121                       FT_Long  b,
122                       FT_Long  c )
123   {
124     FT_Int   s;
125     FT_Long  d;
126 
127 
128     s = 1;
129     if ( a < 0 ) { a = -a; s = -1; }
130     if ( b < 0 ) { b = -b; s = -s; }
131     if ( c < 0 ) { c = -c; s = -s; }
132 
133     d = (FT_Long)( c > 0 ? (FT_Int64)a * b / c
134                          : 0x7FFFFFFFL );
135 
136     return ( s > 0 ) ? d : -d;
137   }
138 
139 #endif /* FTMISC_H_ */
140 
141 
142 /* END */
143