fttypes.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /****************************************************************************
  2. *
  3. * fttypes.h
  4. *
  5. * FreeType simple types definitions (specification only).
  6. *
  7. * Copyright (C) 1996-2023 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. #ifndef FTTYPES_H_
  18. #define FTTYPES_H_
  19. #include <ft2build.h>
  20. #include FT_CONFIG_CONFIG_H
  21. #include <freetype/ftsystem.h>
  22. #include <freetype/ftimage.h>
  23. #include <stddef.h>
  24. FT_BEGIN_HEADER
  25. /**************************************************************************
  26. *
  27. * @section:
  28. * basic_types
  29. *
  30. * @title:
  31. * Basic Data Types
  32. *
  33. * @abstract:
  34. * The basic data types defined by the library.
  35. *
  36. * @description:
  37. * This section contains the basic data types defined by FreeType~2,
  38. * ranging from simple scalar types to bitmap descriptors. More
  39. * font-specific structures are defined in a different section. Note
  40. * that FreeType does not use floating-point data types. Fractional
  41. * values are represented by fixed-point integers, with lower bits
  42. * storing the fractional part.
  43. *
  44. * @order:
  45. * FT_Byte
  46. * FT_Bytes
  47. * FT_Char
  48. * FT_Int
  49. * FT_UInt
  50. * FT_Int16
  51. * FT_UInt16
  52. * FT_Int32
  53. * FT_UInt32
  54. * FT_Int64
  55. * FT_UInt64
  56. * FT_Short
  57. * FT_UShort
  58. * FT_Long
  59. * FT_ULong
  60. * FT_Bool
  61. * FT_Offset
  62. * FT_PtrDist
  63. * FT_String
  64. * FT_Tag
  65. * FT_Error
  66. * FT_Fixed
  67. * FT_Pointer
  68. * FT_Pos
  69. * FT_Vector
  70. * FT_BBox
  71. * FT_Matrix
  72. * FT_FWord
  73. * FT_UFWord
  74. * FT_F2Dot14
  75. * FT_UnitVector
  76. * FT_F26Dot6
  77. * FT_Data
  78. *
  79. * FT_MAKE_TAG
  80. *
  81. * FT_Generic
  82. * FT_Generic_Finalizer
  83. *
  84. * FT_Bitmap
  85. * FT_Pixel_Mode
  86. * FT_Palette_Mode
  87. * FT_Glyph_Format
  88. * FT_IMAGE_TAG
  89. *
  90. */
  91. /**************************************************************************
  92. *
  93. * @type:
  94. * FT_Bool
  95. *
  96. * @description:
  97. * A typedef of unsigned char, used for simple booleans. As usual,
  98. * values 1 and~0 represent true and false, respectively.
  99. */
  100. typedef unsigned char FT_Bool;
  101. /**************************************************************************
  102. *
  103. * @type:
  104. * FT_FWord
  105. *
  106. * @description:
  107. * A signed 16-bit integer used to store a distance in original font
  108. * units.
  109. */
  110. typedef signed short FT_FWord; /* distance in FUnits */
  111. /**************************************************************************
  112. *
  113. * @type:
  114. * FT_UFWord
  115. *
  116. * @description:
  117. * An unsigned 16-bit integer used to store a distance in original font
  118. * units.
  119. */
  120. typedef unsigned short FT_UFWord; /* unsigned distance */
  121. /**************************************************************************
  122. *
  123. * @type:
  124. * FT_Char
  125. *
  126. * @description:
  127. * A simple typedef for the _signed_ char type.
  128. */
  129. typedef signed char FT_Char;
  130. /**************************************************************************
  131. *
  132. * @type:
  133. * FT_Byte
  134. *
  135. * @description:
  136. * A simple typedef for the _unsigned_ char type.
  137. */
  138. typedef unsigned char FT_Byte;
  139. /**************************************************************************
  140. *
  141. * @type:
  142. * FT_Bytes
  143. *
  144. * @description:
  145. * A typedef for constant memory areas.
  146. */
  147. typedef const FT_Byte* FT_Bytes;
  148. /**************************************************************************
  149. *
  150. * @type:
  151. * FT_Tag
  152. *
  153. * @description:
  154. * A typedef for 32-bit tags (as used in the SFNT format).
  155. */
  156. typedef FT_UInt32 FT_Tag;
  157. /**************************************************************************
  158. *
  159. * @type:
  160. * FT_String
  161. *
  162. * @description:
  163. * A simple typedef for the char type, usually used for strings.
  164. */
  165. typedef char FT_String;
  166. /**************************************************************************
  167. *
  168. * @type:
  169. * FT_Short
  170. *
  171. * @description:
  172. * A typedef for signed short.
  173. */
  174. typedef signed short FT_Short;
  175. /**************************************************************************
  176. *
  177. * @type:
  178. * FT_UShort
  179. *
  180. * @description:
  181. * A typedef for unsigned short.
  182. */
  183. typedef unsigned short FT_UShort;
  184. /**************************************************************************
  185. *
  186. * @type:
  187. * FT_Int
  188. *
  189. * @description:
  190. * A typedef for the int type.
  191. */
  192. typedef signed int FT_Int;
  193. /**************************************************************************
  194. *
  195. * @type:
  196. * FT_UInt
  197. *
  198. * @description:
  199. * A typedef for the unsigned int type.
  200. */
  201. typedef unsigned int FT_UInt;
  202. /**************************************************************************
  203. *
  204. * @type:
  205. * FT_Long
  206. *
  207. * @description:
  208. * A typedef for signed long.
  209. */
  210. typedef signed long FT_Long;
  211. /**************************************************************************
  212. *
  213. * @type:
  214. * FT_ULong
  215. *
  216. * @description:
  217. * A typedef for unsigned long.
  218. */
  219. typedef unsigned long FT_ULong;
  220. /**************************************************************************
  221. *
  222. * @type:
  223. * FT_F2Dot14
  224. *
  225. * @description:
  226. * A signed 2.14 fixed-point type used for unit vectors.
  227. */
  228. typedef signed short FT_F2Dot14;
  229. /**************************************************************************
  230. *
  231. * @type:
  232. * FT_F26Dot6
  233. *
  234. * @description:
  235. * A signed 26.6 fixed-point type used for vectorial pixel coordinates.
  236. */
  237. typedef signed long FT_F26Dot6;
  238. /**************************************************************************
  239. *
  240. * @type:
  241. * FT_Fixed
  242. *
  243. * @description:
  244. * This type is used to store 16.16 fixed-point values, like scaling
  245. * values or matrix coefficients.
  246. */
  247. typedef signed long FT_Fixed;
  248. /**************************************************************************
  249. *
  250. * @type:
  251. * FT_Error
  252. *
  253. * @description:
  254. * The FreeType error code type. A value of~0 is always interpreted as a
  255. * successful operation.
  256. */
  257. typedef int FT_Error;
  258. /**************************************************************************
  259. *
  260. * @type:
  261. * FT_Pointer
  262. *
  263. * @description:
  264. * A simple typedef for a typeless pointer.
  265. */
  266. typedef void* FT_Pointer;
  267. /**************************************************************************
  268. *
  269. * @type:
  270. * FT_Offset
  271. *
  272. * @description:
  273. * This is equivalent to the ANSI~C `size_t` type, i.e., the largest
  274. * _unsigned_ integer type used to express a file size or position, or a
  275. * memory block size.
  276. */
  277. typedef size_t FT_Offset;
  278. /**************************************************************************
  279. *
  280. * @type:
  281. * FT_PtrDist
  282. *
  283. * @description:
  284. * This is equivalent to the ANSI~C `ptrdiff_t` type, i.e., the largest
  285. * _signed_ integer type used to express the distance between two
  286. * pointers.
  287. */
  288. typedef ft_ptrdiff_t FT_PtrDist;
  289. /**************************************************************************
  290. *
  291. * @struct:
  292. * FT_UnitVector
  293. *
  294. * @description:
  295. * A simple structure used to store a 2D vector unit vector. Uses
  296. * FT_F2Dot14 types.
  297. *
  298. * @fields:
  299. * x ::
  300. * Horizontal coordinate.
  301. *
  302. * y ::
  303. * Vertical coordinate.
  304. */
  305. typedef struct FT_UnitVector_
  306. {
  307. FT_F2Dot14 x;
  308. FT_F2Dot14 y;
  309. } FT_UnitVector;
  310. /**************************************************************************
  311. *
  312. * @struct:
  313. * FT_Matrix
  314. *
  315. * @description:
  316. * A simple structure used to store a 2x2 matrix. Coefficients are in
  317. * 16.16 fixed-point format. The computation performed is:
  318. *
  319. * ```
  320. * x' = x*xx + y*xy
  321. * y' = x*yx + y*yy
  322. * ```
  323. *
  324. * @fields:
  325. * xx ::
  326. * Matrix coefficient.
  327. *
  328. * xy ::
  329. * Matrix coefficient.
  330. *
  331. * yx ::
  332. * Matrix coefficient.
  333. *
  334. * yy ::
  335. * Matrix coefficient.
  336. */
  337. typedef struct FT_Matrix_
  338. {
  339. FT_Fixed xx, xy;
  340. FT_Fixed yx, yy;
  341. } FT_Matrix;
  342. /**************************************************************************
  343. *
  344. * @struct:
  345. * FT_Data
  346. *
  347. * @description:
  348. * Read-only binary data represented as a pointer and a length.
  349. *
  350. * @fields:
  351. * pointer ::
  352. * The data.
  353. *
  354. * length ::
  355. * The length of the data in bytes.
  356. */
  357. typedef struct FT_Data_
  358. {
  359. const FT_Byte* pointer;
  360. FT_UInt length;
  361. } FT_Data;
  362. /**************************************************************************
  363. *
  364. * @functype:
  365. * FT_Generic_Finalizer
  366. *
  367. * @description:
  368. * Describe a function used to destroy the 'client' data of any FreeType
  369. * object. See the description of the @FT_Generic type for details of
  370. * usage.
  371. *
  372. * @input:
  373. * The address of the FreeType object that is under finalization. Its
  374. * client data is accessed through its `generic` field.
  375. */
  376. typedef void (*FT_Generic_Finalizer)( void* object );
  377. /**************************************************************************
  378. *
  379. * @struct:
  380. * FT_Generic
  381. *
  382. * @description:
  383. * Client applications often need to associate their own data to a
  384. * variety of FreeType core objects. For example, a text layout API
  385. * might want to associate a glyph cache to a given size object.
  386. *
  387. * Some FreeType object contains a `generic` field, of type `FT_Generic`,
  388. * which usage is left to client applications and font servers.
  389. *
  390. * It can be used to store a pointer to client-specific data, as well as
  391. * the address of a 'finalizer' function, which will be called by
  392. * FreeType when the object is destroyed (for example, the previous
  393. * client example would put the address of the glyph cache destructor in
  394. * the `finalizer` field).
  395. *
  396. * @fields:
  397. * data ::
  398. * A typeless pointer to any client-specified data. This field is
  399. * completely ignored by the FreeType library.
  400. *
  401. * finalizer ::
  402. * A pointer to a 'generic finalizer' function, which will be called
  403. * when the object is destroyed. If this field is set to `NULL`, no
  404. * code will be called.
  405. */
  406. typedef struct FT_Generic_
  407. {
  408. void* data;
  409. FT_Generic_Finalizer finalizer;
  410. } FT_Generic;
  411. /**************************************************************************
  412. *
  413. * @macro:
  414. * FT_MAKE_TAG
  415. *
  416. * @description:
  417. * This macro converts four-letter tags that are used to label TrueType
  418. * tables into an `FT_Tag` type, to be used within FreeType.
  419. *
  420. * @note:
  421. * The produced values **must** be 32-bit integers. Don't redefine this
  422. * macro.
  423. */
  424. #define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
  425. ( ( FT_STATIC_BYTE_CAST( FT_Tag, _x1 ) << 24 ) | \
  426. ( FT_STATIC_BYTE_CAST( FT_Tag, _x2 ) << 16 ) | \
  427. ( FT_STATIC_BYTE_CAST( FT_Tag, _x3 ) << 8 ) | \
  428. FT_STATIC_BYTE_CAST( FT_Tag, _x4 ) )
  429. /*************************************************************************/
  430. /*************************************************************************/
  431. /* */
  432. /* L I S T M A N A G E M E N T */
  433. /* */
  434. /*************************************************************************/
  435. /*************************************************************************/
  436. /**************************************************************************
  437. *
  438. * @section:
  439. * list_processing
  440. *
  441. */
  442. /**************************************************************************
  443. *
  444. * @type:
  445. * FT_ListNode
  446. *
  447. * @description:
  448. * Many elements and objects in FreeType are listed through an @FT_List
  449. * record (see @FT_ListRec). As its name suggests, an FT_ListNode is a
  450. * handle to a single list element.
  451. */
  452. typedef struct FT_ListNodeRec_* FT_ListNode;
  453. /**************************************************************************
  454. *
  455. * @type:
  456. * FT_List
  457. *
  458. * @description:
  459. * A handle to a list record (see @FT_ListRec).
  460. */
  461. typedef struct FT_ListRec_* FT_List;
  462. /**************************************************************************
  463. *
  464. * @struct:
  465. * FT_ListNodeRec
  466. *
  467. * @description:
  468. * A structure used to hold a single list element.
  469. *
  470. * @fields:
  471. * prev ::
  472. * The previous element in the list. `NULL` if first.
  473. *
  474. * next ::
  475. * The next element in the list. `NULL` if last.
  476. *
  477. * data ::
  478. * A typeless pointer to the listed object.
  479. */
  480. typedef struct FT_ListNodeRec_
  481. {
  482. FT_ListNode prev;
  483. FT_ListNode next;
  484. void* data;
  485. } FT_ListNodeRec;
  486. /**************************************************************************
  487. *
  488. * @struct:
  489. * FT_ListRec
  490. *
  491. * @description:
  492. * A structure used to hold a simple doubly-linked list. These are used
  493. * in many parts of FreeType.
  494. *
  495. * @fields:
  496. * head ::
  497. * The head (first element) of doubly-linked list.
  498. *
  499. * tail ::
  500. * The tail (last element) of doubly-linked list.
  501. */
  502. typedef struct FT_ListRec_
  503. {
  504. FT_ListNode head;
  505. FT_ListNode tail;
  506. } FT_ListRec;
  507. /* */
  508. #define FT_IS_EMPTY( list ) ( (list).head == 0 )
  509. #define FT_BOOL( x ) FT_STATIC_CAST( FT_Bool, (x) != 0 )
  510. /* concatenate C tokens */
  511. #define FT_ERR_XCAT( x, y ) x ## y
  512. #define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y )
  513. /* see `ftmoderr.h` for descriptions of the following macros */
  514. #define FT_ERR( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
  515. #define FT_ERROR_BASE( x ) ( (x) & 0xFF )
  516. #define FT_ERROR_MODULE( x ) ( (x) & 0xFF00U )
  517. #define FT_ERR_EQ( x, e ) \
  518. ( FT_ERROR_BASE( x ) == FT_ERROR_BASE( FT_ERR( e ) ) )
  519. #define FT_ERR_NEQ( x, e ) \
  520. ( FT_ERROR_BASE( x ) != FT_ERROR_BASE( FT_ERR( e ) ) )
  521. FT_END_HEADER
  522. #endif /* FTTYPES_H_ */
  523. /* END */