00001 /***************************************************************************/ 00002 /* */ 00003 /* ftsystem.h */ 00004 /* */ 00005 /* FreeType low-level system interface definition (specification). */ 00006 /* */ 00007 /* Copyright 1996-2001, 2002, 2005 by */ 00008 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 00009 /* */ 00010 /* This file is part of the FreeType project, and may only be used, */ 00011 /* modified, and distributed under the terms of the FreeType project */ 00012 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 00013 /* this file you indicate that you have read the license and */ 00014 /* understand and accept it fully. */ 00015 /* */ 00016 /***************************************************************************/ 00017 00018 00019 #ifndef __FTSYSTEM_H__ 00020 #define __FTSYSTEM_H__ 00021 00022 00023 #include <ft2build.h> 00024 00025 00026 FT_BEGIN_HEADER 00027 00028 00029 /*************************************************************************/ 00030 /* */ 00031 /* <Section> */ 00032 /* system_interface */ 00033 /* */ 00034 /* <Title> */ 00035 /* System Interface */ 00036 /* */ 00037 /* <Abstract> */ 00038 /* How FreeType manages memory and i/o. */ 00039 /* */ 00040 /* <Description> */ 00041 /* This section contains various definitions related to memory */ 00042 /* management and i/o access. You need to understand this */ 00043 /* information if you want to use a custom memory manager or you own */ 00044 /* i/o streams. */ 00045 /* */ 00046 /*************************************************************************/ 00047 00048 00049 /*************************************************************************/ 00050 /* */ 00051 /* M E M O R Y M A N A G E M E N T */ 00052 /* */ 00053 /*************************************************************************/ 00054 00055 00056 /************************************************************************* 00057 * 00058 * @type: 00059 * FT_Memory 00060 * 00061 * @description: 00062 * A handle to a given memory manager object, defined with an 00063 * @FT_MemoryRec structure. 00064 * 00065 */ 00066 typedef struct FT_MemoryRec_* FT_Memory; 00067 00068 00069 /************************************************************************* 00070 * 00071 * @functype: 00072 * FT_Alloc_Func 00073 * 00074 * @description: 00075 * A function used to allocate `size' bytes from `memory'. 00076 * 00077 * @input: 00078 * memory :: 00079 * A handle to the source memory manager. 00080 * 00081 * size :: 00082 * The size in bytes to allocate. 00083 * 00084 * @return: 00085 * Address of new memory block. 0~in case of failure. 00086 * 00087 */ 00088 typedef void* 00089 (*FT_Alloc_Func)( FT_Memory memory, 00090 long size ); 00091 00092 00093 /************************************************************************* 00094 * 00095 * @functype: 00096 * FT_Free_Func 00097 * 00098 * @description: 00099 * A function used to release a given block of memory. 00100 * 00101 * @input: 00102 * memory :: 00103 * A handle to the source memory manager. 00104 * 00105 * block :: 00106 * The address of the target memory block. 00107 * 00108 */ 00109 typedef void 00110 (*FT_Free_Func)( FT_Memory memory, 00111 void* block ); 00112 00113 00114 /************************************************************************* 00115 * 00116 * @functype: 00117 * FT_Realloc_Func 00118 * 00119 * @description: 00120 * A function used to re-allocate a given block of memory. 00121 * 00122 * @input: 00123 * memory :: 00124 * A handle to the source memory manager. 00125 * 00126 * cur_size :: 00127 * The block's current size in bytes. 00128 * 00129 * new_size :: 00130 * The block's requested new size. 00131 * 00132 * block :: 00133 * The block's current address. 00134 * 00135 * @return: 00136 * New block address. 0~in case of memory shortage. 00137 * 00138 * @note: 00139 * In case of error, the old block must still be available. 00140 * 00141 */ 00142 typedef void* 00143 (*FT_Realloc_Func)( FT_Memory memory, 00144 long cur_size, 00145 long new_size, 00146 void* block ); 00147 00148 00149 /************************************************************************* 00150 * 00151 * @struct: 00152 * FT_MemoryRec 00153 * 00154 * @description: 00155 * A structure used to describe a given memory manager to FreeType~2. 00156 * 00157 * @fields: 00158 * user :: 00159 * A generic typeless pointer for user data. 00160 * 00161 * alloc :: 00162 * A pointer type to an allocation function. 00163 * 00164 * free :: 00165 * A pointer type to an memory freeing function. 00166 * 00167 * realloc :: 00168 * A pointer type to a reallocation function. 00169 * 00170 */ 00171 struct FT_MemoryRec_ 00172 { 00173 void* user; 00174 FT_Alloc_Func alloc; 00175 FT_Free_Func free; 00176 FT_Realloc_Func realloc; 00177 }; 00178 00179 00180 /*************************************************************************/ 00181 /* */ 00182 /* I / O M A N A G E M E N T */ 00183 /* */ 00184 /*************************************************************************/ 00185 00186 00187 /************************************************************************* 00188 * 00189 * @type: 00190 * FT_Stream 00191 * 00192 * @description: 00193 * A handle to an input stream. 00194 * 00195 */ 00196 typedef struct FT_StreamRec_* FT_Stream; 00197 00198 00199 /************************************************************************* 00200 * 00201 * @struct: 00202 * FT_StreamDesc 00203 * 00204 * @description: 00205 * A union type used to store either a long or a pointer. This is used 00206 * to store a file descriptor or a `FILE*' in an input stream. 00207 * 00208 */ 00209 typedef union FT_StreamDesc_ 00210 { 00211 long value; 00212 void* pointer; 00213 00214 } FT_StreamDesc; 00215 00216 00217 /************************************************************************* 00218 * 00219 * @functype: 00220 * FT_Stream_IoFunc 00221 * 00222 * @description: 00223 * A function used to seek and read data from a given input stream. 00224 * 00225 * @input: 00226 * stream :: 00227 * A handle to the source stream. 00228 * 00229 * offset :: 00230 * The offset of read in stream (always from start). 00231 * 00232 * buffer :: 00233 * The address of the read buffer. 00234 * 00235 * count :: 00236 * The number of bytes to read from the stream. 00237 * 00238 * @return: 00239 * The number of bytes effectively read by the stream. 00240 * 00241 * @note: 00242 * This function might be called to perform a seek or skip operation 00243 * with a `count' of~0. 00244 * 00245 */ 00246 typedef unsigned long 00247 (*FT_Stream_IoFunc)( FT_Stream stream, 00248 unsigned long offset, 00249 unsigned char* buffer, 00250 unsigned long count ); 00251 00252 00253 /************************************************************************* 00254 * 00255 * @functype: 00256 * FT_Stream_CloseFunc 00257 * 00258 * @description: 00259 * A function used to close a given input stream. 00260 * 00261 * @input: 00262 * stream :: 00263 * A handle to the target stream. 00264 * 00265 */ 00266 typedef void 00267 (*FT_Stream_CloseFunc)( FT_Stream stream ); 00268 00269 00270 /************************************************************************* 00271 * 00272 * @struct: 00273 * FT_StreamRec 00274 * 00275 * @description: 00276 * A structure used to describe an input stream. 00277 * 00278 * @input: 00279 * base :: 00280 * For memory-based streams, this is the address of the first stream 00281 * byte in memory. This field should always be set to NULL for 00282 * disk-based streams. 00283 * 00284 * size :: 00285 * The stream size in bytes. 00286 * 00287 * pos :: 00288 * The current position within the stream. 00289 * 00290 * descriptor :: 00291 * This field is a union that can hold an integer or a pointer. It is 00292 * used by stream implementations to store file descriptors or `FILE*' 00293 * pointers. 00294 * 00295 * pathname :: 00296 * This field is completely ignored by FreeType. However, it is often 00297 * useful during debugging to use it to store the stream's filename 00298 * (where available). 00299 * 00300 * read :: 00301 * The stream's input function. 00302 * 00303 * close :: 00304 * The stream;s close function. 00305 * 00306 * memory :: 00307 * The memory manager to use to preload frames. This is set 00308 * internally by FreeType and shouldn't be touched by stream 00309 * implementations. 00310 * 00311 * cursor :: 00312 * This field is set and used internally by FreeType when parsing 00313 * frames. 00314 * 00315 * limit :: 00316 * This field is set and used internally by FreeType when parsing 00317 * frames. 00318 * 00319 */ 00320 typedef struct FT_StreamRec_ 00321 { 00322 unsigned char* base; 00323 unsigned long size; 00324 unsigned long pos; 00325 00326 FT_StreamDesc descriptor; 00327 FT_StreamDesc pathname; 00328 FT_Stream_IoFunc read; 00329 FT_Stream_CloseFunc close; 00330 00331 FT_Memory memory; 00332 unsigned char* cursor; 00333 unsigned char* limit; 00334 00335 } FT_StreamRec; 00336 00337 00338 /* */ 00339 00340 00341 FT_END_HEADER 00342 00343 #endif /* __FTSYSTEM_H__ */ 00344 00345 00346 /* END */