ftsystem.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /***************************************************************************/
  2. /* */
  3. /* ftsystem.h */
  4. /* */
  5. /* FreeType low-level system interface definition (specification). */
  6. /* */
  7. /* Copyright 1996-2001, 2002, 2005, 2010, 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. #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. * @also:
  172. * See @FT_StreamRec for the publicly accessible fields of a given
  173. * stream object.
  174. *
  175. */
  176. typedef struct FT_StreamRec_* FT_Stream;
  177. /*************************************************************************
  178. *
  179. * @struct:
  180. * FT_StreamDesc
  181. *
  182. * @description:
  183. * A union type used to store either a long or a pointer. This is used
  184. * to store a file descriptor or a `FILE*' in an input stream.
  185. *
  186. */
  187. typedef union FT_StreamDesc_
  188. {
  189. long value;
  190. void* pointer;
  191. } FT_StreamDesc;
  192. /*************************************************************************
  193. *
  194. * @functype:
  195. * FT_Stream_IoFunc
  196. *
  197. * @description:
  198. * A function used to seek and read data from a given input stream.
  199. *
  200. * @input:
  201. * stream ::
  202. * A handle to the source stream.
  203. *
  204. * offset ::
  205. * The offset of read in stream (always from start).
  206. *
  207. * buffer ::
  208. * The address of the read buffer.
  209. *
  210. * count ::
  211. * The number of bytes to read from the stream.
  212. *
  213. * @return:
  214. * The number of bytes effectively read by the stream.
  215. *
  216. * @note:
  217. * This function might be called to perform a seek or skip operation
  218. * with a `count' of~0. A non-zero return value then indicates an
  219. * error.
  220. *
  221. */
  222. typedef unsigned long
  223. (*FT_Stream_IoFunc)( FT_Stream stream,
  224. unsigned long offset,
  225. unsigned char* buffer,
  226. unsigned long count );
  227. /*************************************************************************
  228. *
  229. * @functype:
  230. * FT_Stream_CloseFunc
  231. *
  232. * @description:
  233. * A function used to close a given input stream.
  234. *
  235. * @input:
  236. * stream ::
  237. * A handle to the target stream.
  238. *
  239. */
  240. typedef void
  241. (*FT_Stream_CloseFunc)( FT_Stream stream );
  242. /*************************************************************************
  243. *
  244. * @struct:
  245. * FT_StreamRec
  246. *
  247. * @description:
  248. * A structure used to describe an input stream.
  249. *
  250. * @input:
  251. * base ::
  252. * For memory-based streams, this is the address of the first stream
  253. * byte in memory. This field should always be set to NULL for
  254. * disk-based streams.
  255. *
  256. * size ::
  257. * The stream size in bytes.
  258. *
  259. * In case of compressed streams where the size is unknown before
  260. * actually doing the decompression, the value is set to 0x7FFFFFFF.
  261. * (Note that this size value can occur for normal streams also; it is
  262. * thus just a hint.)
  263. *
  264. * pos ::
  265. * The current position within the stream.
  266. *
  267. * descriptor ::
  268. * This field is a union that can hold an integer or a pointer. It is
  269. * used by stream implementations to store file descriptors or `FILE*'
  270. * pointers.
  271. *
  272. * pathname ::
  273. * This field is completely ignored by FreeType. However, it is often
  274. * useful during debugging to use it to store the stream's filename
  275. * (where available).
  276. *
  277. * read ::
  278. * The stream's input function.
  279. *
  280. * close ::
  281. * The stream's close function.
  282. *
  283. * memory ::
  284. * The memory manager to use to preload frames. This is set
  285. * internally by FreeType and shouldn't be touched by stream
  286. * implementations.
  287. *
  288. * cursor ::
  289. * This field is set and used internally by FreeType when parsing
  290. * frames.
  291. *
  292. * limit ::
  293. * This field is set and used internally by FreeType when parsing
  294. * frames.
  295. *
  296. */
  297. typedef struct FT_StreamRec_
  298. {
  299. unsigned char* base;
  300. unsigned long size;
  301. unsigned long pos;
  302. FT_StreamDesc descriptor;
  303. FT_StreamDesc pathname;
  304. FT_Stream_IoFunc read;
  305. FT_Stream_CloseFunc close;
  306. FT_Memory memory;
  307. unsigned char* cursor;
  308. unsigned char* limit;
  309. } FT_StreamRec;
  310. /* */
  311. FT_END_HEADER
  312. #endif /* __FTSYSTEM_H__ */
  313. /* END */