1 /****************************************************************************
5 * FreeType low-level system interface definition (specification).
7 * Copyright (C) 1996-2020 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.
28 /**************************************************************************
37 * How FreeType manages memory and i/o.
40 * This section contains various definitions related to memory management
41 * and i/o access. You need to understand this information if you want to
42 * use a custom memory manager or you own i/o streams.
47 /**************************************************************************
49 * M E M O R Y M A N A G E M E N T
54 /**************************************************************************
60 * A handle to a given memory manager object, defined with an
61 * @FT_MemoryRec structure.
64 typedef struct FT_MemoryRec_* FT_Memory;
67 /**************************************************************************
73 * A function used to allocate `size` bytes from `memory`.
77 * A handle to the source memory manager.
80 * The size in bytes to allocate.
83 * Address of new memory block. 0~in case of failure.
87 (*FT_Alloc_Func)( FT_Memory memory,
91 /**************************************************************************
97 * A function used to release a given block of memory.
101 * A handle to the source memory manager.
104 * The address of the target memory block.
108 (*FT_Free_Func)( FT_Memory memory,
112 /**************************************************************************
118 * A function used to re-allocate a given block of memory.
122 * A handle to the source memory manager.
125 * The block's current size in bytes.
128 * The block's requested new size.
131 * The block's current address.
134 * New block address. 0~in case of memory shortage.
137 * In case of error, the old block must still be available.
141 (*FT_Realloc_Func)( FT_Memory memory,
147 /**************************************************************************
153 * A structure used to describe a given memory manager to FreeType~2.
157 * A generic typeless pointer for user data.
160 * A pointer type to an allocation function.
163 * A pointer type to an memory freeing function.
166 * A pointer type to a reallocation function.
174 FT_Realloc_Func realloc;
178 /**************************************************************************
180 * I / O M A N A G E M E N T
185 /**************************************************************************
191 * A handle to an input stream.
194 * See @FT_StreamRec for the publicly accessible fields of a given stream
198 typedef struct FT_StreamRec_* FT_Stream;
201 /**************************************************************************
207 * A union type used to store either a long or a pointer. This is used
208 * to store a file descriptor or a `FILE*` in an input stream.
211 typedef union FT_StreamDesc_
219 /**************************************************************************
225 * A function used to seek and read data from a given input stream.
229 * A handle to the source stream.
232 * The offset of read in stream (always from start).
235 * The address of the read buffer.
238 * The number of bytes to read from the stream.
241 * The number of bytes effectively read by the stream.
244 * This function might be called to perform a seek or skip operation with
245 * a `count` of~0. A non-zero return value then indicates an error.
248 typedef unsigned long
249 (*FT_Stream_IoFunc)( FT_Stream stream,
250 unsigned long offset,
251 unsigned char* buffer,
252 unsigned long count );
255 /**************************************************************************
258 * FT_Stream_CloseFunc
261 * A function used to close a given input stream.
265 * A handle to the target stream.
269 (*FT_Stream_CloseFunc)( FT_Stream stream );
272 /**************************************************************************
278 * A structure used to describe an input stream.
282 * For memory-based streams, this is the address of the first stream
283 * byte in memory. This field should always be set to `NULL` for
284 * disk-based streams.
287 * The stream size in bytes.
289 * In case of compressed streams where the size is unknown before
290 * actually doing the decompression, the value is set to 0x7FFFFFFF.
291 * (Note that this size value can occur for normal streams also; it is
295 * The current position within the stream.
298 * This field is a union that can hold an integer or a pointer. It is
299 * used by stream implementations to store file descriptors or `FILE*`
303 * This field is completely ignored by FreeType. However, it is often
304 * useful during debugging to use it to store the stream's filename
308 * The stream's input function.
311 * The stream's close function.
314 * The memory manager to use to preload frames. This is set internally
315 * by FreeType and shouldn't be touched by stream implementations.
318 * This field is set and used internally by FreeType when parsing
319 * frames. In particular, the `FT_GET_XXX` macros use this instead of
323 * This field is set and used internally by FreeType when parsing
327 typedef struct FT_StreamRec_
333 FT_StreamDesc descriptor;
334 FT_StreamDesc pathname;
335 FT_Stream_IoFunc read;
336 FT_Stream_CloseFunc close;
339 unsigned char* cursor;
340 unsigned char* limit;
349 #endif /* FTSYSTEM_H_ */