ftsystem.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /***************************************************************************/
  2. /* */
  3. /* ftsystem.h */
  4. /* */
  5. /* FreeType low-level system interface definition (specification). */
  6. /* */
  7. /* Copyright 1996-2001, 2002, 2005, 2010 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 __FTSYSTEM_H__
  18. #define __FTSYSTEM_H__
  19. #include <ft2build.h>
  20. FT_BEGIN_HEADER
  21. /*************************************************************************/
  22. /* */
  23. /* <Section> */
  24. /* system_interface */
  25. /* */
  26. /* <Title> */
  27. /* System Interface */
  28. /* */
  29. /* <Abstract> */
  30. /* How FreeType manages memory and i/o. */
  31. /* */
  32. /* <Description> */
  33. /* This section contains various definitions related to memory */
  34. /* management and i/o access. You need to understand this */
  35. /* information if you want to use a custom memory manager or you own */
  36. /* i/o streams. */
  37. /* */
  38. /*************************************************************************/
  39. /*************************************************************************/
  40. /* */
  41. /* M E M O R Y M A N A G E M E N T */
  42. /* */
  43. /*************************************************************************/
  44. /*************************************************************************
  45. *
  46. * @type:
  47. * FT_Memory
  48. *
  49. * @description:
  50. * A handle to a given memory manager object, defined with an
  51. * @FT_MemoryRec structure.
  52. *
  53. */
  54. typedef struct FT_MemoryRec_* FT_Memory;
  55. /*************************************************************************
  56. *
  57. * @functype:
  58. * FT_Alloc_Func
  59. *
  60. * @description:
  61. * A function used to allocate `size' bytes from `memory'.
  62. *
  63. * @input:
  64. * memory ::
  65. * A handle to the source memory manager.
  66. *
  67. * size ::
  68. * The size in bytes to allocate.
  69. *
  70. * @return:
  71. * Address of new memory block. 0~in case of failure.
  72. *
  73. */
  74. typedef void*
  75. (*FT_Alloc_Func)( FT_Memory memory,
  76. long size );
  77. /*************************************************************************
  78. *
  79. * @functype:
  80. * FT_Free_Func
  81. *
  82. * @description:
  83. * A function used to release a given block of memory.
  84. *
  85. * @input:
  86. * memory ::
  87. * A handle to the source memory manager.
  88. *
  89. * block ::
  90. * The address of the target memory block.
  91. *
  92. */
  93. typedef void
  94. (*FT_Free_Func)( FT_Memory memory,
  95. void* block );
  96. /*************************************************************************
  97. *
  98. * @functype:
  99. * FT_Realloc_Func
  100. *
  101. * @description:
  102. * A function used to re-allocate a given block of memory.
  103. *
  104. * @input:
  105. * memory ::
  106. * A handle to the source memory manager.
  107. *
  108. * cur_size ::
  109. * The block's current size in bytes.
  110. *
  111. * new_size ::
  112. * The block's requested new size.
  113. *
  114. * block ::
  115. * The block's current address.
  116. *
  117. * @return:
  118. * New block address. 0~in case of memory shortage.
  119. *
  120. * @note:
  121. * In case of error, the old block must still be available.
  122. *
  123. */
  124. typedef void*
  125. (*FT_Realloc_Func)( FT_Memory memory,
  126. long cur_size,
  127. long new_size,
  128. void* block );
  129. /*************************************************************************
  130. *
  131. * @struct:
  132. * FT_MemoryRec
  133. *
  134. * @description:
  135. * A structure used to describe a given memory manager to FreeType~2.
  136. *
  137. * @fields:
  138. * user ::
  139. * A generic typeless pointer for user data.
  140. *
  141. * alloc ::
  142. * A pointer type to an allocation function.
  143. *
  144. * free ::
  145. * A pointer type to an memory freeing function.
  146. *
  147. * realloc ::
  148. * A pointer type to a reallocation function.
  149. *
  150. */
  151. struct FT_MemoryRec_
  152. {
  153. void* user;
  154. FT_Alloc_Func alloc;
  155. FT_Free_Func free;
  156. FT_Realloc_Func realloc;
  157. };
  158. /*************************************************************************/
  159. /* */
  160. /* I / O M A N A G E M E N T */
  161. /* */
  162. /*************************************************************************/
  163. /*************************************************************************
  164. *
  165. * @type:
  166. * FT_Stream
  167. *
  168. * @description:
  169. * A handle to an input stream.
  170. *
  171. */
  172. typedef struct FT_StreamRec_* FT_Stream;
  173. /*************************************************************************
  174. *
  175. * @struct:
  176. * FT_StreamDesc
  177. *
  178. * @description:
  179. * A union type used to store either a long or a pointer. This is used
  180. * to store a file descriptor or a `FILE*' in an input stream.
  181. *
  182. */
  183. typedef union FT_StreamDesc_
  184. {
  185. long value;
  186. void* pointer;
  187. } FT_StreamDesc;
  188. /*************************************************************************
  189. *
  190. * @functype:
  191. * FT_Stream_IoFunc
  192. *
  193. * @description:
  194. * A function used to seek and read data from a given input stream.
  195. *
  196. * @input:
  197. * stream ::
  198. * A handle to the source stream.
  199. *
  200. * offset ::
  201. * The offset of read in stream (always from start).
  202. *
  203. * buffer ::
  204. * The address of the read buffer.
  205. *
  206. * count ::
  207. * The number of bytes to read from the stream.
  208. *
  209. * @return:
  210. * The number of bytes effectively read by the stream.
  211. *
  212. * @note:
  213. * This function might be called to perform a seek or skip operation
  214. * with a `count' of~0. A non-zero return value then indicates an
  215. * error.
  216. *
  217. */
  218. typedef unsigned long
  219. (*FT_Stream_IoFunc)( FT_Stream stream,
  220. unsigned long offset,
  221. unsigned char* buffer,
  222. unsigned long count );
  223. /*************************************************************************
  224. *
  225. * @functype:
  226. * FT_Stream_CloseFunc
  227. *
  228. * @description:
  229. * A function used to close a given input stream.
  230. *
  231. * @input:
  232. * stream ::
  233. * A handle to the target stream.
  234. *
  235. */
  236. typedef void
  237. (*FT_Stream_CloseFunc)( FT_Stream stream );
  238. /*************************************************************************
  239. *
  240. * @struct:
  241. * FT_StreamRec
  242. *
  243. * @description:
  244. * A structure used to describe an input stream.
  245. *
  246. * @input:
  247. * base ::
  248. * For memory-based streams, this is the address of the first stream
  249. * byte in memory. This field should always be set to NULL for
  250. * disk-based streams.
  251. *
  252. * size ::
  253. * The stream size in bytes.
  254. *
  255. * pos ::
  256. * The current position within the stream.
  257. *
  258. * descriptor ::
  259. * This field is a union that can hold an integer or a pointer. It is
  260. * used by stream implementations to store file descriptors or `FILE*'
  261. * pointers.
  262. *
  263. * pathname ::
  264. * This field is completely ignored by FreeType. However, it is often
  265. * useful during debugging to use it to store the stream's filename
  266. * (where available).
  267. *
  268. * read ::
  269. * The stream's input function.
  270. *
  271. * close ::
  272. * The stream's close function.
  273. *
  274. * memory ::
  275. * The memory manager to use to preload frames. This is set
  276. * internally by FreeType and shouldn't be touched by stream
  277. * implementations.
  278. *
  279. * cursor ::
  280. * This field is set and used internally by FreeType when parsing
  281. * frames.
  282. *
  283. * limit ::
  284. * This field is set and used internally by FreeType when parsing
  285. * frames.
  286. *
  287. */
  288. typedef struct FT_StreamRec_
  289. {
  290. unsigned char* base;
  291. unsigned long size;
  292. unsigned long pos;
  293. FT_StreamDesc descriptor;
  294. FT_StreamDesc pathname;
  295. FT_Stream_IoFunc read;
  296. FT_Stream_CloseFunc close;
  297. FT_Memory memory;
  298. unsigned char* cursor;
  299. unsigned char* limit;
  300. } FT_StreamRec;
  301. /* */
  302. FT_END_HEADER
  303. #endif /* __FTSYSTEM_H__ */
  304. /* END */