1 /***************************************************************************/
5 /* FreeType low-level system interface definition (specification). */
7 /* Copyright 1996-2001, 2002 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
19 #ifndef __FTSYSTEM_H__
20 #define __FTSYSTEM_H__
29 /*************************************************************************/
32 /* system_interface */
35 /* System Interface */
38 /* How FreeType manages memory and i/o. */
41 /* This section contains various definitions related to memory */
42 /* management and i/o access. You need to understand this */
43 /* information if you want to use a custom memory manager or you own */
44 /* input i/o streams. */
46 /*************************************************************************/
49 /*************************************************************************/
51 /* M E M O R Y M A N A G E M E N T */
53 /*************************************************************************/
56 /*************************************************************************/
62 /* A handle to a given memory manager object, defined with a */
63 /* @FT_MemoryRec structure. */
65 typedef struct FT_MemoryRec_* FT_Memory;
68 /*************************************************************************/
74 /* A function used to allocate `size' bytes from `memory'. */
77 /* memory :: A handle to the source memory manager. */
79 /* size :: The size in bytes to allocate. */
82 /* Address of new memory block. 0 in case of failure. */
85 (*FT_Alloc_Func)( FT_Memory memory,
89 /*************************************************************************/
95 /* A function used to release a given block of memory. */
98 /* memory :: A handle to the source memory manager. */
100 /* block :: The address of the target memory block. */
103 (*FT_Free_Func)( FT_Memory memory,
107 /*************************************************************************/
110 /* FT_Realloc_Func */
113 /* a function used to re-allocate a given block of memory. */
116 /* memory :: A handle to the source memory manager. */
118 /* cur_size :: The block's current size in bytes. */
120 /* new_size :: The block's requested new size. */
122 /* block :: The block's current address. */
125 /* New block address. 0 in case of memory shortage. */
128 /* In case of error, the old block must still be available. */
131 (*FT_Realloc_Func)( FT_Memory memory,
137 /*************************************************************************/
143 /* A structure used to describe a given memory manager to FreeType 2. */
146 /* user :: A generic typeless pointer for user data. */
148 /* alloc :: A pointer type to an allocation function. */
150 /* free :: A pointer type to an memory freeing function. */
152 /* realloc :: A pointer type to a reallocation function. */
159 FT_Realloc_Func realloc;
163 /*************************************************************************/
165 /* I / O M A N A G E M E N T */
167 /*************************************************************************/
170 /*************************************************************************/
176 /* A handle to an input stream. */
178 typedef struct FT_StreamRec_* FT_Stream;
181 /*************************************************************************/
187 /* A union type used to store either a long or a pointer. This is */
188 /* used to store a file descriptor or a FILE* in an input stream. */
190 typedef union FT_StreamDesc_
198 /*************************************************************************/
201 /* FT_Stream_IoFunc */
204 /* A function used to seek and read data from a given input stream. */
207 /* stream :: A handle to the source stream. */
209 /* offset :: The offset of read in stream (always from start). */
211 /* buffer :: The address of the read buffer. */
213 /* count :: The number of bytes to read from the stream. */
216 /* The number of bytes effectively read by the stream. */
219 /* This function might be called to perform a seek or skip operation */
220 /* with a `count' of 0. */
222 typedef unsigned long
223 (*FT_Stream_IoFunc)( FT_Stream stream,
224 unsigned long offset,
225 unsigned char* buffer,
226 unsigned long count );
229 /*************************************************************************/
232 /* FT_Stream_CloseFunc */
235 /* A function used to close a given input stream. */
238 /* stream :: A handle to the target stream. */
241 (*FT_Stream_CloseFunc)( FT_Stream stream );
244 /*************************************************************************/
250 /* A structure used to describe an input stream. */
253 /* base :: For memory-based streams, this is the address of the */
254 /* first stream byte in memory. This field should */
255 /* always be set to NULL for disk-based streams. */
257 /* size :: The stream size in bytes. */
259 /* pos :: The current position within the stream. */
261 /* descriptor :: This field is a union that can hold an integer or a */
262 /* pointer. It is used by stream implementations to */
263 /* store file descriptors or FILE* pointers. */
265 /* pathname :: This field is completely ignored by FreeType. */
266 /* However, it is often useful during debugging to use */
267 /* it to store the stream's filename (where available). */
269 /* read :: The stream's input function. */
271 /* close :: The stream;s close function. */
273 /* memory :: The memory manager to use to preload frames. This is */
274 /* set internally by FreeType and shouldn't be touched */
275 /* by stream implementations. */
277 /* cursor :: This field is set and used internally by FreeType */
278 /* when parsing frames. */
280 /* limit :: This field is set and used internally by FreeType */
281 /* when parsing frames. */
283 typedef struct FT_StreamRec_
289 FT_StreamDesc descriptor;
290 FT_StreamDesc pathname;
291 FT_Stream_IoFunc read;
292 FT_Stream_CloseFunc close;
295 unsigned char* cursor;
296 unsigned char* limit;
306 #endif /* __FTSYSTEM_H__ */