ftsystem.h 8.6 KB

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