ftsystem.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /***************************************************************************/
  2. /* */
  3. /* ftsystem.h */
  4. /* */
  5. /* FreeType low-level system interface definition (specification). */
  6. /* */
  7. /* Copyright 1996-2001, 2002 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. /* input 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 a */
  51. /* @FT_MemoryRec structure. */
  52. /* */
  53. typedef struct FT_MemoryRec_* FT_Memory;
  54. /*************************************************************************/
  55. /* */
  56. /* @functype: */
  57. /* FT_Alloc_Func */
  58. /* */
  59. /* @description: */
  60. /* A function used to allocate `size' bytes from `memory'. */
  61. /* */
  62. /* @input: */
  63. /* memory :: A handle to the source memory manager. */
  64. /* */
  65. /* size :: The size in bytes to allocate. */
  66. /* */
  67. /* @return: */
  68. /* Address of new memory block. 0 in case of failure. */
  69. /* */
  70. typedef void*
  71. (*FT_Alloc_Func)( FT_Memory memory,
  72. long size );
  73. /*************************************************************************/
  74. /* */
  75. /* @functype: */
  76. /* FT_Free_Func */
  77. /* */
  78. /* @description: */
  79. /* A function used to release a given block of memory. */
  80. /* */
  81. /* @input: */
  82. /* memory :: A handle to the source memory manager. */
  83. /* */
  84. /* block :: The address of the target memory block. */
  85. /* */
  86. typedef void
  87. (*FT_Free_Func)( FT_Memory memory,
  88. void* block );
  89. /*************************************************************************/
  90. /* */
  91. /* @functype: */
  92. /* FT_Realloc_Func */
  93. /* */
  94. /* @description: */
  95. /* a function used to re-allocate a given block of memory. */
  96. /* */
  97. /* @input: */
  98. /* memory :: A handle to the source memory manager. */
  99. /* */
  100. /* cur_size :: The block's current size in bytes. */
  101. /* */
  102. /* new_size :: The block's requested new size. */
  103. /* */
  104. /* block :: The block's current address. */
  105. /* */
  106. /* @return: */
  107. /* New block address. 0 in case of memory shortage. */
  108. /* */
  109. /* @note: */
  110. /* In case of error, the old block must still be available. */
  111. /* */
  112. typedef void*
  113. (*FT_Realloc_Func)( FT_Memory memory,
  114. long cur_size,
  115. long new_size,
  116. void* block );
  117. /*************************************************************************/
  118. /* */
  119. /* @struct: */
  120. /* FT_MemoryRec */
  121. /* */
  122. /* @description: */
  123. /* A structure used to describe a given memory manager to FreeType 2. */
  124. /* */
  125. /* @fields: */
  126. /* user :: A generic typeless pointer for user data. */
  127. /* */
  128. /* alloc :: A pointer type to an allocation function. */
  129. /* */
  130. /* free :: A pointer type to an memory freeing function. */
  131. /* */
  132. /* realloc :: A pointer type to a reallocation function. */
  133. /* */
  134. struct FT_MemoryRec_
  135. {
  136. void* user;
  137. FT_Alloc_Func alloc;
  138. FT_Free_Func free;
  139. FT_Realloc_Func realloc;
  140. };
  141. /*************************************************************************/
  142. /* */
  143. /* I / O M A N A G E M E N T */
  144. /* */
  145. /*************************************************************************/
  146. /*************************************************************************/
  147. /* */
  148. /* @type: */
  149. /* FT_Stream */
  150. /* */
  151. /* @description: */
  152. /* A handle to an input stream. */
  153. /* */
  154. typedef struct FT_StreamRec_* FT_Stream;
  155. /*************************************************************************/
  156. /* */
  157. /* @struct: */
  158. /* FT_StreamDesc */
  159. /* */
  160. /* @description: */
  161. /* A union type used to store either a long or a pointer. This is */
  162. /* used to store a file descriptor or a FILE* in an input stream. */
  163. /* */
  164. typedef union FT_StreamDesc_
  165. {
  166. long value;
  167. void* pointer;
  168. } FT_StreamDesc;
  169. /*************************************************************************/
  170. /* */
  171. /* @functype: */
  172. /* FT_Stream_IoFunc */
  173. /* */
  174. /* @description: */
  175. /* A function used to seek and read data from a given input stream. */
  176. /* */
  177. /* @input: */
  178. /* stream :: A handle to the source stream. */
  179. /* */
  180. /* offset :: The offset of read in stream (always from start). */
  181. /* */
  182. /* buffer :: The address of the read buffer. */
  183. /* */
  184. /* count :: The number of bytes to read from the stream. */
  185. /* */
  186. /* @return: */
  187. /* The number of bytes effectively read by the stream. */
  188. /* */
  189. /* @note: */
  190. /* This function might be called to perform a seek or skip operation */
  191. /* with a `count' of 0. */
  192. /* */
  193. typedef unsigned long
  194. (*FT_Stream_IoFunc)( FT_Stream stream,
  195. unsigned long offset,
  196. unsigned char* buffer,
  197. unsigned long count );
  198. /*************************************************************************/
  199. /* */
  200. /* @functype: */
  201. /* FT_Stream_CloseFunc */
  202. /* */
  203. /* @description: */
  204. /* A function used to close a given input stream. */
  205. /* */
  206. /* @input: */
  207. /* stream :: A handle to the target stream. */
  208. /* */
  209. typedef void
  210. (*FT_Stream_CloseFunc)( FT_Stream stream );
  211. /*************************************************************************/
  212. /* */
  213. /* @struct: */
  214. /* FT_StreamRec */
  215. /* */
  216. /* @description: */
  217. /* A structure used to describe an input stream. */
  218. /* */
  219. /* @input: */
  220. /* base :: For memory-based streams, this is the address of the */
  221. /* first stream byte in memory. This field should */
  222. /* always be set to NULL for disk-based streams. */
  223. /* */
  224. /* size :: The stream size in bytes. */
  225. /* */
  226. /* pos :: The current position within the stream. */
  227. /* */
  228. /* descriptor :: This field is a union that can hold an integer or a */
  229. /* pointer. It is used by stream implementations to */
  230. /* store file descriptors or FILE* pointers. */
  231. /* */
  232. /* pathname :: This field is completely ignored by FreeType. */
  233. /* However, it is often useful during debugging to use */
  234. /* it to store the stream's filename (where available). */
  235. /* */
  236. /* read :: The stream's input function. */
  237. /* */
  238. /* close :: The stream;s close function. */
  239. /* */
  240. /* memory :: The memory manager to use to preload frames. This is */
  241. /* set internally by FreeType and shouldn't be touched */
  242. /* by stream implementations. */
  243. /* */
  244. /* cursor :: This field is set and used internally by FreeType */
  245. /* when parsing frames. */
  246. /* */
  247. /* limit :: This field is set and used internally by FreeType */
  248. /* when parsing frames. */
  249. /* */
  250. typedef struct FT_StreamRec_
  251. {
  252. unsigned char* base;
  253. unsigned long size;
  254. unsigned long pos;
  255. FT_StreamDesc descriptor;
  256. FT_StreamDesc pathname;
  257. FT_Stream_IoFunc read;
  258. FT_Stream_CloseFunc close;
  259. FT_Memory memory;
  260. unsigned char* cursor;
  261. unsigned char* limit;
  262. } FT_StreamRec;
  263. /* */
  264. FT_END_HEADER
  265. #endif /* __FTSYSTEM_H__ */
  266. /* END */