michael@0: /***************************************************************************/ michael@0: /* */ michael@0: /* ftsystem.h */ michael@0: /* */ michael@0: /* FreeType low-level system interface definition (specification). */ michael@0: /* */ michael@0: /* Copyright 1996-2001, 2002, 2005, 2010 by */ michael@0: /* David Turner, Robert Wilhelm, and Werner Lemberg. */ michael@0: /* */ michael@0: /* This file is part of the FreeType project, and may only be used, */ michael@0: /* modified, and distributed under the terms of the FreeType project */ michael@0: /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ michael@0: /* this file you indicate that you have read the license and */ michael@0: /* understand and accept it fully. */ michael@0: /* */ michael@0: /***************************************************************************/ michael@0: michael@0: michael@0: #ifndef __FTSYSTEM_H__ michael@0: #define __FTSYSTEM_H__ michael@0: michael@0: michael@0: #include michael@0: michael@0: michael@0: FT_BEGIN_HEADER michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /*
*/ michael@0: /* system_interface */ michael@0: /* */ michael@0: /* */ michael@0: /* System Interface */ michael@0: /* */ michael@0: /* <Abstract> */ michael@0: /* How FreeType manages memory and i/o. */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* This section contains various definitions related to memory */ michael@0: /* management and i/o access. You need to understand this */ michael@0: /* information if you want to use a custom memory manager or you own */ michael@0: /* i/o streams. */ michael@0: /* */ michael@0: /*************************************************************************/ michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* M E M O R Y M A N A G E M E N T */ michael@0: /* */ michael@0: /*************************************************************************/ michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @type: michael@0: * FT_Memory michael@0: * michael@0: * @description: michael@0: * A handle to a given memory manager object, defined with an michael@0: * @FT_MemoryRec structure. michael@0: * michael@0: */ michael@0: typedef struct FT_MemoryRec_* FT_Memory; michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @functype: michael@0: * FT_Alloc_Func michael@0: * michael@0: * @description: michael@0: * A function used to allocate `size' bytes from `memory'. michael@0: * michael@0: * @input: michael@0: * memory :: michael@0: * A handle to the source memory manager. michael@0: * michael@0: * size :: michael@0: * The size in bytes to allocate. michael@0: * michael@0: * @return: michael@0: * Address of new memory block. 0~in case of failure. michael@0: * michael@0: */ michael@0: typedef void* michael@0: (*FT_Alloc_Func)( FT_Memory memory, michael@0: long size ); michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @functype: michael@0: * FT_Free_Func michael@0: * michael@0: * @description: michael@0: * A function used to release a given block of memory. michael@0: * michael@0: * @input: michael@0: * memory :: michael@0: * A handle to the source memory manager. michael@0: * michael@0: * block :: michael@0: * The address of the target memory block. michael@0: * michael@0: */ michael@0: typedef void michael@0: (*FT_Free_Func)( FT_Memory memory, michael@0: void* block ); michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @functype: michael@0: * FT_Realloc_Func michael@0: * michael@0: * @description: michael@0: * A function used to re-allocate a given block of memory. michael@0: * michael@0: * @input: michael@0: * memory :: michael@0: * A handle to the source memory manager. michael@0: * michael@0: * cur_size :: michael@0: * The block's current size in bytes. michael@0: * michael@0: * new_size :: michael@0: * The block's requested new size. michael@0: * michael@0: * block :: michael@0: * The block's current address. michael@0: * michael@0: * @return: michael@0: * New block address. 0~in case of memory shortage. michael@0: * michael@0: * @note: michael@0: * In case of error, the old block must still be available. michael@0: * michael@0: */ michael@0: typedef void* michael@0: (*FT_Realloc_Func)( FT_Memory memory, michael@0: long cur_size, michael@0: long new_size, michael@0: void* block ); michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @struct: michael@0: * FT_MemoryRec michael@0: * michael@0: * @description: michael@0: * A structure used to describe a given memory manager to FreeType~2. michael@0: * michael@0: * @fields: michael@0: * user :: michael@0: * A generic typeless pointer for user data. michael@0: * michael@0: * alloc :: michael@0: * A pointer type to an allocation function. michael@0: * michael@0: * free :: michael@0: * A pointer type to an memory freeing function. michael@0: * michael@0: * realloc :: michael@0: * A pointer type to a reallocation function. michael@0: * michael@0: */ michael@0: struct FT_MemoryRec_ michael@0: { michael@0: void* user; michael@0: FT_Alloc_Func alloc; michael@0: FT_Free_Func free; michael@0: FT_Realloc_Func realloc; michael@0: }; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* I / O M A N A G E M E N T */ michael@0: /* */ michael@0: /*************************************************************************/ michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @type: michael@0: * FT_Stream michael@0: * michael@0: * @description: michael@0: * A handle to an input stream. michael@0: * michael@0: */ michael@0: typedef struct FT_StreamRec_* FT_Stream; michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @struct: michael@0: * FT_StreamDesc michael@0: * michael@0: * @description: michael@0: * A union type used to store either a long or a pointer. This is used michael@0: * to store a file descriptor or a `FILE*' in an input stream. michael@0: * michael@0: */ michael@0: typedef union FT_StreamDesc_ michael@0: { michael@0: long value; michael@0: void* pointer; michael@0: michael@0: } FT_StreamDesc; michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @functype: michael@0: * FT_Stream_IoFunc michael@0: * michael@0: * @description: michael@0: * A function used to seek and read data from a given input stream. michael@0: * michael@0: * @input: michael@0: * stream :: michael@0: * A handle to the source stream. michael@0: * michael@0: * offset :: michael@0: * The offset of read in stream (always from start). michael@0: * michael@0: * buffer :: michael@0: * The address of the read buffer. michael@0: * michael@0: * count :: michael@0: * The number of bytes to read from the stream. michael@0: * michael@0: * @return: michael@0: * The number of bytes effectively read by the stream. michael@0: * michael@0: * @note: michael@0: * This function might be called to perform a seek or skip operation michael@0: * with a `count' of~0. A non-zero return value then indicates an michael@0: * error. michael@0: * michael@0: */ michael@0: typedef unsigned long michael@0: (*FT_Stream_IoFunc)( FT_Stream stream, michael@0: unsigned long offset, michael@0: unsigned char* buffer, michael@0: unsigned long count ); michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @functype: michael@0: * FT_Stream_CloseFunc michael@0: * michael@0: * @description: michael@0: * A function used to close a given input stream. michael@0: * michael@0: * @input: michael@0: * stream :: michael@0: * A handle to the target stream. michael@0: * michael@0: */ michael@0: typedef void michael@0: (*FT_Stream_CloseFunc)( FT_Stream stream ); michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @struct: michael@0: * FT_StreamRec michael@0: * michael@0: * @description: michael@0: * A structure used to describe an input stream. michael@0: * michael@0: * @input: michael@0: * base :: michael@0: * For memory-based streams, this is the address of the first stream michael@0: * byte in memory. This field should always be set to NULL for michael@0: * disk-based streams. michael@0: * michael@0: * size :: michael@0: * The stream size in bytes. michael@0: * michael@0: * pos :: michael@0: * The current position within the stream. michael@0: * michael@0: * descriptor :: michael@0: * This field is a union that can hold an integer or a pointer. It is michael@0: * used by stream implementations to store file descriptors or `FILE*' michael@0: * pointers. michael@0: * michael@0: * pathname :: michael@0: * This field is completely ignored by FreeType. However, it is often michael@0: * useful during debugging to use it to store the stream's filename michael@0: * (where available). michael@0: * michael@0: * read :: michael@0: * The stream's input function. michael@0: * michael@0: * close :: michael@0: * The stream's close function. michael@0: * michael@0: * memory :: michael@0: * The memory manager to use to preload frames. This is set michael@0: * internally by FreeType and shouldn't be touched by stream michael@0: * implementations. michael@0: * michael@0: * cursor :: michael@0: * This field is set and used internally by FreeType when parsing michael@0: * frames. michael@0: * michael@0: * limit :: michael@0: * This field is set and used internally by FreeType when parsing michael@0: * frames. michael@0: * michael@0: */ michael@0: typedef struct FT_StreamRec_ michael@0: { michael@0: unsigned char* base; michael@0: unsigned long size; michael@0: unsigned long pos; michael@0: michael@0: FT_StreamDesc descriptor; michael@0: FT_StreamDesc pathname; michael@0: FT_Stream_IoFunc read; michael@0: FT_Stream_CloseFunc close; michael@0: michael@0: FT_Memory memory; michael@0: unsigned char* cursor; michael@0: unsigned char* limit; michael@0: michael@0: } FT_StreamRec; michael@0: michael@0: michael@0: /* */ michael@0: michael@0: michael@0: FT_END_HEADER michael@0: michael@0: #endif /* __FTSYSTEM_H__ */ michael@0: michael@0: michael@0: /* END */