ftconfig.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /***************************************************************************/
  2. /* */
  3. /* ftconfig.h */
  4. /* */
  5. /* ANSI-specific configuration file (specification only). */
  6. /* */
  7. /* Copyright 1996-2004, 2006-2008, 2010-2011, 2013, 2014 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. /* This header file contains a number of macro definitions that are used */
  20. /* by the rest of the engine. Most of the macros here are automatically */
  21. /* determined at compile time, and you should not need to change it to */
  22. /* port FreeType, except to compile the library with a non-ANSI */
  23. /* compiler. */
  24. /* */
  25. /* Note however that if some specific modifications are needed, we */
  26. /* advise you to place a modified copy in your build directory. */
  27. /* */
  28. /* The build directory is usually `builds/<system>', and contains */
  29. /* system-specific files that are always included first when building */
  30. /* the library. */
  31. /* */
  32. /* This ANSI version should stay in `include/config/'. */
  33. /* */
  34. /*************************************************************************/
  35. #ifndef __FTCONFIG_H__
  36. #define __FTCONFIG_H__
  37. #include <ft2build.h>
  38. #include FT_CONFIG_OPTIONS_H
  39. #include FT_CONFIG_STANDARD_LIBRARY_H
  40. FT_BEGIN_HEADER
  41. /*************************************************************************/
  42. /* */
  43. /* PLATFORM-SPECIFIC CONFIGURATION MACROS */
  44. /* */
  45. /* These macros can be toggled to suit a specific system. The current */
  46. /* ones are defaults used to compile FreeType in an ANSI C environment */
  47. /* (16bit compilers are also supported). Copy this file to your own */
  48. /* `builds/<system>' directory, and edit it to port the engine. */
  49. /* */
  50. /*************************************************************************/
  51. /* There are systems (like the Texas Instruments 'C54x) where a `char' */
  52. /* has 16 bits. ANSI C says that sizeof(char) is always 1. Since an */
  53. /* `int' has 16 bits also for this system, sizeof(int) gives 1 which */
  54. /* is probably unexpected. */
  55. /* */
  56. /* `CHAR_BIT' (defined in limits.h) gives the number of bits in a */
  57. /* `char' type. */
  58. #ifndef FT_CHAR_BIT
  59. #define FT_CHAR_BIT CHAR_BIT
  60. #endif
  61. /* The size of an `int' type. */
  62. #if FT_UINT_MAX == 0xFFFFUL
  63. #define FT_SIZEOF_INT (16 / FT_CHAR_BIT)
  64. #elif FT_UINT_MAX == 0xFFFFFFFFUL
  65. #define FT_SIZEOF_INT (32 / FT_CHAR_BIT)
  66. #elif FT_UINT_MAX > 0xFFFFFFFFUL && FT_UINT_MAX == 0xFFFFFFFFFFFFFFFFUL
  67. #define FT_SIZEOF_INT (64 / FT_CHAR_BIT)
  68. #else
  69. #error "Unsupported size of `int' type!"
  70. #endif
  71. /* The size of a `long' type. A five-byte `long' (as used e.g. on the */
  72. /* DM642) is recognized but avoided. */
  73. #if FT_ULONG_MAX == 0xFFFFFFFFUL
  74. #define FT_SIZEOF_LONG (32 / FT_CHAR_BIT)
  75. #elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFUL
  76. #define FT_SIZEOF_LONG (32 / FT_CHAR_BIT)
  77. #elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFFFFFFFUL
  78. #define FT_SIZEOF_LONG (64 / FT_CHAR_BIT)
  79. #else
  80. #error "Unsupported size of `long' type!"
  81. #endif
  82. /* FT_UNUSED is a macro used to indicate that a given parameter is not */
  83. /* used -- this is only used to get rid of unpleasant compiler warnings */
  84. #ifndef FT_UNUSED
  85. #define FT_UNUSED( arg ) ( (arg) = (arg) )
  86. #endif
  87. /*************************************************************************/
  88. /* */
  89. /* AUTOMATIC CONFIGURATION MACROS */
  90. /* */
  91. /* These macros are computed from the ones defined above. Don't touch */
  92. /* their definition, unless you know precisely what you are doing. No */
  93. /* porter should need to mess with them. */
  94. /* */
  95. /*************************************************************************/
  96. /*************************************************************************/
  97. /* */
  98. /* Mac support */
  99. /* */
  100. /* This is the only necessary change, so it is defined here instead */
  101. /* providing a new configuration file. */
  102. /* */
  103. #if defined( __APPLE__ ) || ( defined( __MWERKS__ ) && defined( macintosh ) )
  104. /* no Carbon frameworks for 64bit 10.4.x */
  105. /* AvailabilityMacros.h is available since Mac OS X 10.2, */
  106. /* so guess the system version by maximum errno before inclusion */
  107. #include <errno.h>
  108. #ifdef ECANCELED /* defined since 10.2 */
  109. #include "AvailabilityMacros.h"
  110. #endif
  111. #if defined( __LP64__ ) && \
  112. ( MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 )
  113. #undef FT_MACINTOSH
  114. #endif
  115. #elif defined( __SC__ ) || defined( __MRC__ )
  116. /* Classic MacOS compilers */
  117. #include "ConditionalMacros.h"
  118. #if TARGET_OS_MAC
  119. #define FT_MACINTOSH 1
  120. #endif
  121. #endif
  122. /*************************************************************************/
  123. /* */
  124. /* <Section> */
  125. /* basic_types */
  126. /* */
  127. /*************************************************************************/
  128. /*************************************************************************/
  129. /* */
  130. /* <Type> */
  131. /* FT_Int16 */
  132. /* */
  133. /* <Description> */
  134. /* A typedef for a 16bit signed integer type. */
  135. /* */
  136. typedef signed short FT_Int16;
  137. /*************************************************************************/
  138. /* */
  139. /* <Type> */
  140. /* FT_UInt16 */
  141. /* */
  142. /* <Description> */
  143. /* A typedef for a 16bit unsigned integer type. */
  144. /* */
  145. typedef unsigned short FT_UInt16;
  146. /* */
  147. /* this #if 0 ... #endif clause is for documentation purposes */
  148. #if 0
  149. /*************************************************************************/
  150. /* */
  151. /* <Type> */
  152. /* FT_Int32 */
  153. /* */
  154. /* <Description> */
  155. /* A typedef for a 32bit signed integer type. The size depends on */
  156. /* the configuration. */
  157. /* */
  158. typedef signed XXX FT_Int32;
  159. /*************************************************************************/
  160. /* */
  161. /* <Type> */
  162. /* FT_UInt32 */
  163. /* */
  164. /* A typedef for a 32bit unsigned integer type. The size depends on */
  165. /* the configuration. */
  166. /* */
  167. typedef unsigned XXX FT_UInt32;
  168. /*************************************************************************/
  169. /* */
  170. /* <Type> */
  171. /* FT_Int64 */
  172. /* */
  173. /* A typedef for a 64bit signed integer type. The size depends on */
  174. /* the configuration. Only defined if there is real 64bit support; */
  175. /* otherwise, it gets emulated with a structure (if necessary). */
  176. /* */
  177. typedef signed XXX FT_Int64;
  178. /*************************************************************************/
  179. /* */
  180. /* <Type> */
  181. /* FT_UInt64 */
  182. /* */
  183. /* A typedef for a 64bit unsigned integer type. The size depends on */
  184. /* the configuration. Only defined if there is real 64bit support; */
  185. /* otherwise, it gets emulated with a structure (if necessary). */
  186. /* */
  187. typedef unsigned XXX FT_UInt64;
  188. /* */
  189. #endif
  190. #if FT_SIZEOF_INT == (32 / FT_CHAR_BIT)
  191. typedef signed int FT_Int32;
  192. typedef unsigned int FT_UInt32;
  193. #elif FT_SIZEOF_LONG == (32 / FT_CHAR_BIT)
  194. typedef signed long FT_Int32;
  195. typedef unsigned long FT_UInt32;
  196. #else
  197. #error "no 32bit type found -- please check your configuration files"
  198. #endif
  199. /* look up an integer type that is at least 32 bits */
  200. #if FT_SIZEOF_INT >= (32 / FT_CHAR_BIT)
  201. typedef int FT_Fast;
  202. typedef unsigned int FT_UFast;
  203. #elif FT_SIZEOF_LONG >= (32 / FT_CHAR_BIT)
  204. typedef long FT_Fast;
  205. typedef unsigned long FT_UFast;
  206. #endif
  207. /* determine whether we have a 64-bit int type for platforms without */
  208. /* Autoconf */
  209. #if FT_SIZEOF_LONG == (64 / FT_CHAR_BIT)
  210. /* FT_LONG64 must be defined if a 64-bit type is available */
  211. #define FT_LONG64
  212. #define FT_INT64 long
  213. #define FT_UINT64 unsigned long
  214. #elif defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */
  215. /* this compiler provides the __int64 type */
  216. #define FT_LONG64
  217. #define FT_INT64 __int64
  218. #define FT_UINT64 unsigned __int64
  219. #elif defined( __BORLANDC__ ) /* Borland C++ */
  220. /* XXXX: We should probably check the value of __BORLANDC__ in order */
  221. /* to test the compiler version. */
  222. /* this compiler provides the __int64 type */
  223. #define FT_LONG64
  224. #define FT_INT64 __int64
  225. #define FT_UINT64 unsigned __int64
  226. #elif defined( __WATCOMC__ ) /* Watcom C++ */
  227. /* Watcom doesn't provide 64-bit data types */
  228. #elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */
  229. #define FT_LONG64
  230. #define FT_INT64 long long int
  231. #define FT_UINT64 unsigned long long int
  232. #elif defined( __GNUC__ )
  233. /* GCC provides the `long long' type */
  234. #define FT_LONG64
  235. #define FT_INT64 long long int
  236. #define FT_UINT64 unsigned long long int
  237. #endif /* FT_SIZEOF_LONG == (64 / FT_CHAR_BIT) */
  238. /*************************************************************************/
  239. /* */
  240. /* A 64-bit data type will create compilation problems if you compile */
  241. /* in strict ANSI mode. To avoid them, we disable its use if __STDC__ */
  242. /* is defined. You can however ignore this rule by defining the */
  243. /* FT_CONFIG_OPTION_FORCE_INT64 configuration macro. */
  244. /* */
  245. #if defined( FT_LONG64 ) && !defined( FT_CONFIG_OPTION_FORCE_INT64 )
  246. #ifdef __STDC__
  247. /* undefine the 64-bit macros in strict ANSI compilation mode */
  248. #undef FT_LONG64
  249. #undef FT_INT64
  250. #endif /* __STDC__ */
  251. #endif /* FT_LONG64 && !FT_CONFIG_OPTION_FORCE_INT64 */
  252. #ifdef FT_LONG64
  253. typedef FT_INT64 FT_Int64;
  254. typedef FT_UINT64 FT_UInt64;
  255. #endif
  256. #define FT_BEGIN_STMNT do {
  257. #define FT_END_STMNT } while ( 0 )
  258. #define FT_DUMMY_STMNT FT_BEGIN_STMNT FT_END_STMNT
  259. #ifndef FT_CONFIG_OPTION_NO_ASSEMBLER
  260. /* Provide assembler fragments for performance-critical functions. */
  261. /* These must be defined `static __inline__' with GCC. */
  262. #if defined( __CC_ARM ) || defined( __ARMCC__ ) /* RVCT */
  263. #define FT_MULFIX_ASSEMBLER FT_MulFix_arm
  264. /* documentation is in freetype.h */
  265. static __inline FT_Int32
  266. FT_MulFix_arm( FT_Int32 a,
  267. FT_Int32 b )
  268. {
  269. register FT_Int32 t, t2;
  270. __asm
  271. {
  272. smull t2, t, b, a /* (lo=t2,hi=t) = a*b */
  273. mov a, t, asr #31 /* a = (hi >> 31) */
  274. add a, a, #0x8000 /* a += 0x8000 */
  275. adds t2, t2, a /* t2 += a */
  276. adc t, t, #0 /* t += carry */
  277. mov a, t2, lsr #16 /* a = t2 >> 16 */
  278. orr a, a, t, lsl #16 /* a |= t << 16 */
  279. }
  280. return a;
  281. }
  282. #endif /* __CC_ARM || __ARMCC__ */
  283. #ifdef __GNUC__
  284. #if defined( __arm__ ) && \
  285. ( !defined( __thumb__ ) || defined( __thumb2__ ) ) && \
  286. !( defined( __CC_ARM ) || defined( __ARMCC__ ) )
  287. #define FT_MULFIX_ASSEMBLER FT_MulFix_arm
  288. /* documentation is in freetype.h */
  289. static __inline__ FT_Int32
  290. FT_MulFix_arm( FT_Int32 a,
  291. FT_Int32 b )
  292. {
  293. register FT_Int32 t, t2;
  294. __asm__ __volatile__ (
  295. "smull %1, %2, %4, %3\n\t" /* (lo=%1,hi=%2) = a*b */
  296. "mov %0, %2, asr #31\n\t" /* %0 = (hi >> 31) */
  297. #if defined( __clang__ ) && defined( __thumb2__ )
  298. "add.w %0, %0, #0x8000\n\t" /* %0 += 0x8000 */
  299. #else
  300. "add %0, %0, #0x8000\n\t" /* %0 += 0x8000 */
  301. #endif
  302. "adds %1, %1, %0\n\t" /* %1 += %0 */
  303. "adc %2, %2, #0\n\t" /* %2 += carry */
  304. "mov %0, %1, lsr #16\n\t" /* %0 = %1 >> 16 */
  305. "orr %0, %0, %2, lsl #16\n\t" /* %0 |= %2 << 16 */
  306. : "=r"(a), "=&r"(t2), "=&r"(t)
  307. : "r"(a), "r"(b)
  308. : "cc" );
  309. return a;
  310. }
  311. #endif /* __arm__ && */
  312. /* ( __thumb2__ || !__thumb__ ) && */
  313. /* !( __CC_ARM || __ARMCC__ ) */
  314. #if defined( __i386__ )
  315. #define FT_MULFIX_ASSEMBLER FT_MulFix_i386
  316. /* documentation is in freetype.h */
  317. static __inline__ FT_Int32
  318. FT_MulFix_i386( FT_Int32 a,
  319. FT_Int32 b )
  320. {
  321. register FT_Int32 result;
  322. __asm__ __volatile__ (
  323. "imul %%edx\n"
  324. "movl %%edx, %%ecx\n"
  325. "sarl $31, %%ecx\n"
  326. "addl $0x8000, %%ecx\n"
  327. "addl %%ecx, %%eax\n"
  328. "adcl $0, %%edx\n"
  329. "shrl $16, %%eax\n"
  330. "shll $16, %%edx\n"
  331. "addl %%edx, %%eax\n"
  332. : "=a"(result), "=d"(b)
  333. : "a"(a), "d"(b)
  334. : "%ecx", "cc" );
  335. return result;
  336. }
  337. #endif /* i386 */
  338. #endif /* __GNUC__ */
  339. #ifdef _MSC_VER /* Visual C++ */
  340. #ifdef _M_IX86
  341. #define FT_MULFIX_ASSEMBLER FT_MulFix_i386
  342. /* documentation is in freetype.h */
  343. static __inline FT_Int32
  344. FT_MulFix_i386( FT_Int32 a,
  345. FT_Int32 b )
  346. {
  347. register FT_Int32 result;
  348. __asm
  349. {
  350. mov eax, a
  351. mov edx, b
  352. imul edx
  353. mov ecx, edx
  354. sar ecx, 31
  355. add ecx, 8000h
  356. add eax, ecx
  357. adc edx, 0
  358. shr eax, 16
  359. shl edx, 16
  360. add eax, edx
  361. mov result, eax
  362. }
  363. return result;
  364. }
  365. #endif /* _M_IX86 */
  366. #endif /* _MSC_VER */
  367. #if defined( __GNUC__ ) && defined( __x86_64__ )
  368. #define FT_MULFIX_ASSEMBLER FT_MulFix_x86_64
  369. static __inline__ FT_Int32
  370. FT_MulFix_x86_64( FT_Int32 a,
  371. FT_Int32 b )
  372. {
  373. /* Temporarily disable the warning that C90 doesn't support */
  374. /* `long long'. */
  375. #if ( __GNUC__ > 4 ) || ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ >= 6 ) )
  376. #pragma GCC diagnostic push
  377. #pragma GCC diagnostic ignored "-Wlong-long"
  378. #endif
  379. #if 1
  380. /* Technically not an assembly fragment, but GCC does a really good */
  381. /* job at inlining it and generating good machine code for it. */
  382. long long ret, tmp;
  383. ret = (long long)a * b;
  384. tmp = ret >> 63;
  385. ret += 0x8000 + tmp;
  386. return (FT_Int32)( ret >> 16 );
  387. #else
  388. /* For some reason, GCC 4.6 on Ubuntu 12.04 generates invalid machine */
  389. /* code from the lines below. The main issue is that `wide_a' is not */
  390. /* properly initialized by sign-extending `a'. Instead, the generated */
  391. /* machine code assumes that the register that contains `a' on input */
  392. /* can be used directly as a 64-bit value, which is wrong most of the */
  393. /* time. */
  394. long long wide_a = (long long)a;
  395. long long wide_b = (long long)b;
  396. long long result;
  397. __asm__ __volatile__ (
  398. "imul %2, %1\n"
  399. "mov %1, %0\n"
  400. "sar $63, %0\n"
  401. "lea 0x8000(%1, %0), %0\n"
  402. "sar $16, %0\n"
  403. : "=&r"(result), "=&r"(wide_a)
  404. : "r"(wide_b)
  405. : "cc" );
  406. return (FT_Int32)result;
  407. #endif
  408. #if ( __GNUC__ > 4 ) || ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ >= 6 ) )
  409. #pragma GCC diagnostic pop
  410. #endif
  411. }
  412. #endif /* __GNUC__ && __x86_64__ */
  413. #endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */
  414. #ifdef FT_CONFIG_OPTION_INLINE_MULFIX
  415. #ifdef FT_MULFIX_ASSEMBLER
  416. #define FT_MULFIX_INLINED FT_MULFIX_ASSEMBLER
  417. #endif
  418. #endif
  419. #ifdef FT_MAKE_OPTION_SINGLE_OBJECT
  420. #define FT_LOCAL( x ) static x
  421. #define FT_LOCAL_DEF( x ) static x
  422. #else
  423. #ifdef __cplusplus
  424. #define FT_LOCAL( x ) extern "C" x
  425. #define FT_LOCAL_DEF( x ) extern "C" x
  426. #else
  427. #define FT_LOCAL( x ) extern x
  428. #define FT_LOCAL_DEF( x ) x
  429. #endif
  430. #endif /* FT_MAKE_OPTION_SINGLE_OBJECT */
  431. #define FT_LOCAL_ARRAY( x ) extern const x
  432. #define FT_LOCAL_ARRAY_DEF( x ) const x
  433. #ifndef FT_BASE
  434. #ifdef __cplusplus
  435. #define FT_BASE( x ) extern "C" x
  436. #else
  437. #define FT_BASE( x ) extern x
  438. #endif
  439. #endif /* !FT_BASE */
  440. #ifndef FT_BASE_DEF
  441. #ifdef __cplusplus
  442. #define FT_BASE_DEF( x ) x
  443. #else
  444. #define FT_BASE_DEF( x ) x
  445. #endif
  446. #endif /* !FT_BASE_DEF */
  447. #ifndef FT_EXPORT
  448. #ifdef __cplusplus
  449. #define FT_EXPORT( x ) extern "C" x
  450. #else
  451. #define FT_EXPORT( x ) extern x
  452. #endif
  453. #endif /* !FT_EXPORT */
  454. #ifndef FT_EXPORT_DEF
  455. #ifdef __cplusplus
  456. #define FT_EXPORT_DEF( x ) extern "C" x
  457. #else
  458. #define FT_EXPORT_DEF( x ) extern x
  459. #endif
  460. #endif /* !FT_EXPORT_DEF */
  461. #ifndef FT_EXPORT_VAR
  462. #ifdef __cplusplus
  463. #define FT_EXPORT_VAR( x ) extern "C" x
  464. #else
  465. #define FT_EXPORT_VAR( x ) extern x
  466. #endif
  467. #endif /* !FT_EXPORT_VAR */
  468. /* The following macros are needed to compile the library with a */
  469. /* C++ compiler and with 16bit compilers. */
  470. /* */
  471. /* This is special. Within C++, you must specify `extern "C"' for */
  472. /* functions which are used via function pointers, and you also */
  473. /* must do that for structures which contain function pointers to */
  474. /* assure C linkage -- it's not possible to have (local) anonymous */
  475. /* functions which are accessed by (global) function pointers. */
  476. /* */
  477. /* */
  478. /* FT_CALLBACK_DEF is used to _define_ a callback function. */
  479. /* */
  480. /* FT_CALLBACK_TABLE is used to _declare_ a constant variable that */
  481. /* contains pointers to callback functions. */
  482. /* */
  483. /* FT_CALLBACK_TABLE_DEF is used to _define_ a constant variable */
  484. /* that contains pointers to callback functions. */
  485. /* */
  486. /* */
  487. /* Some 16bit compilers have to redefine these macros to insert */
  488. /* the infamous `_cdecl' or `__fastcall' declarations. */
  489. /* */
  490. #ifndef FT_CALLBACK_DEF
  491. #ifdef __cplusplus
  492. #define FT_CALLBACK_DEF( x ) extern "C" x
  493. #else
  494. #define FT_CALLBACK_DEF( x ) static x
  495. #endif
  496. #endif /* FT_CALLBACK_DEF */
  497. #ifndef FT_CALLBACK_TABLE
  498. #ifdef __cplusplus
  499. #define FT_CALLBACK_TABLE extern "C"
  500. #define FT_CALLBACK_TABLE_DEF extern "C"
  501. #else
  502. #define FT_CALLBACK_TABLE extern
  503. #define FT_CALLBACK_TABLE_DEF /* nothing */
  504. #endif
  505. #endif /* FT_CALLBACK_TABLE */
  506. FT_END_HEADER
  507. #endif /* __FTCONFIG_H__ */
  508. /* END */