This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / subsys / win32k / freetype / src / base / ftsystem.c
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ftsystem.c                                                             */
4 /*                                                                         */
5 /*    ANSI-specific FreeType low-level system interface (body).            */
6 /*                                                                         */
7 /*  Copyright 1996-2000 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
18   /*************************************************************************/
19   /*                                                                       */
20   /* This file contains the default interface used by FreeType to access   */
21   /* low-level, i.e. memory management, i/o access as well as thread       */
22   /* synchronisation.  It can be replaced by user-specific routines if     */
23   /* necessary.                                                            */
24   /*                                                                       */
25   /*************************************************************************/
26
27 #include <ddk/ntddk.h>
28
29 #include <freetype/config/ftconfig.h>
30 #include <freetype/internal/ftdebug.h>
31 #include <freetype/ftsystem.h>
32 #include <freetype/fterrors.h>
33 #include <freetype/fttypes.h>
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39
40   /*************************************************************************/
41   /*                                                                       */
42   /*                       MEMORY MANAGEMENT INTERFACE                     */
43   /*                                                                       */
44   /*************************************************************************/
45
46   /*************************************************************************/
47   /*                                                                       */
48   /* It is not necessary to do any error checking for the                  */
49   /* allocation-related functions.  This will be done by the higher level  */
50   /* routines like FT_Alloc() or FT_Realloc().                             */
51   /*                                                                       */
52   /*************************************************************************/
53
54
55   /*************************************************************************/
56   /*                                                                       */
57   /* <Function>                                                            */
58   /*    ft_alloc                                                           */
59   /*                                                                       */
60   /* <Description>                                                         */
61   /*    The memory allocation function.                                    */
62   /*                                                                       */
63   /* <Input>                                                               */
64   /*    memory :: A pointer to the memory object.                          */
65   /*                                                                       */
66   /*    size   :: The requested size in bytes.                             */
67   /*                                                                       */
68   /* <Return>                                                              */
69   /*    block  :: The address of newly allocated block.                    */
70   /*                                                                       */
71   static
72   void*  ft_alloc( FT_Memory  memory,
73                    long       size )
74   {
75     FT_UNUSED( memory );
76
77 /*    return malloc( size ); */
78     return ExAllocatePool(NonPagedPool, size);
79   }
80
81
82   /*************************************************************************/
83   /*                                                                       */
84   /* <Function>                                                            */
85   /*    ft_realloc                                                         */
86   /*                                                                       */
87   /* <Description>                                                         */
88   /*    The memory reallocation function.                                  */
89   /*                                                                       */
90   /* <Input>                                                               */
91   /*    memory   :: A pointer to the memory object.                        */
92   /*                                                                       */
93   /*    cur_size :: The current size of the allocated memory block.        */
94   /*                                                                       */
95   /*    new_size :: The newly requested size in bytes.                     */
96   /*                                                                       */
97   /*    block    :: The current address of the block in memory.            */
98   /*                                                                       */
99   /* <Return>                                                              */
100   /*    The address of the reallocated memory block.                       */
101   /*                                                                       */
102   static
103   void*  ft_realloc( FT_Memory  memory,
104                      long       cur_size,
105                      long       new_size,
106                      void*      block )
107   {
108     FT_UNUSED( memory );
109     FT_UNUSED( cur_size );
110
111 /*    return realloc( block, new_size ); */
112     ExFreePool(block);
113     return ExAllocatePool(NonPagedPool, new_size);
114   }
115
116
117   /*************************************************************************/
118   /*                                                                       */
119   /* <Function>                                                            */
120   /*    ft_free                                                            */
121   /*                                                                       */
122   /* <Description>                                                         */
123   /*    The memory release function.                                       */
124   /*                                                                       */
125   /* <Input>                                                               */
126   /*    memory  :: A pointer to the memory object.                         */
127   /*                                                                       */
128   /*    block   :: The address of block in memory to be freed.             */
129   /*                                                                       */
130   static
131   void  ft_free( FT_Memory  memory,
132                  void*      block )
133   {
134     FT_UNUSED( memory );
135
136 /*    free( block ); */
137     ExFreePool(block);
138   }
139
140
141   /*************************************************************************/
142   /*                                                                       */
143   /*                     RESOURCE MANAGEMENT INTERFACE                     */
144   /*                                                                       */
145   /*************************************************************************/
146
147
148   /*************************************************************************/
149   /*                                                                       */
150   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
151   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
152   /* messages during execution.                                            */
153   /*                                                                       */
154 #undef  FT_COMPONENT
155 #define FT_COMPONENT  trace_io
156
157   /* We use the macro STREAM_FILE for convenience to extract the       */
158   /* system-specific stream handle from a given FreeType stream object */
159 #define STREAM_FILE( stream )  ( (FILE*)stream->descriptor.pointer )
160
161
162   /*************************************************************************/
163   /*                                                                       */
164   /* <Function>                                                            */
165   /*    ft_close_stream                                                    */
166   /*                                                                       */
167   /* <Description>                                                         */
168   /*    The function to close a stream.                                    */
169   /*                                                                       */
170   /* <Input>                                                               */
171   /*    stream :: A pointer to the stream object.                          */
172   /*                                                                       */
173   static
174   void  ft_close_stream( FT_Stream  stream )
175   {
176     DbgPrint("ftsystem.c: UNIMPLEMENTED CALL\n");
177
178 /*    fclose( STREAM_FILE( stream ) ); */
179
180     stream->descriptor.pointer = NULL;
181     stream->size               = 0;
182     stream->base               = 0;
183   }
184
185
186   /*************************************************************************/
187   /*                                                                       */
188   /* <Function>                                                            */
189   /*    ft_io_stream                                                       */
190   /*                                                                       */
191   /* <Description>                                                         */
192   /*    The function to open a stream.                                     */
193   /*                                                                       */
194   /* <Input>                                                               */
195   /*    stream :: A pointer to the stream object.                          */
196   /*                                                                       */
197   /*    offset :: The position in the data stream to start reading.        */
198   /*                                                                       */
199   /*    buffer :: The address of buffer to store the read data.            */
200   /*                                                                       */
201   /*    count  :: The number of bytes to read from the stream.             */
202   /*                                                                       */
203   /* <Return>                                                              */
204   /*    The number of bytes actually read.                                 */
205   /*                                                                       */
206   static
207   unsigned long  ft_io_stream( FT_Stream       stream,
208                                unsigned long   offset,
209                                unsigned char*  buffer,
210                                unsigned long   count )
211   {
212     FILE*  file;
213
214     DbgPrint("ftsystem.c: UNIMPLEMENTED CALL\n");
215     file = STREAM_FILE( stream );
216
217 /*    fseek( file, offset, SEEK_SET ); */
218 /*    return (unsigned long)fread( buffer, 1, count, file ); */
219   }
220
221
222   /*************************************************************************/
223   /*                                                                       */
224   /* <Function>                                                            */
225   /*    FT_New_Stream                                                      */
226   /*                                                                       */
227   /* <Description>                                                         */
228   /*    Creates a new stream object.                                       */
229   /*                                                                       */
230   /* <Input>                                                               */
231   /*    filepathname :: The name of the stream (usually a file) to be      */
232   /*                    opened.                                            */
233   /*                                                                       */
234   /*    stream       :: A pointer to the stream object.                    */
235   /*                                                                       */
236   /* <Return>                                                              */
237   /*    FreeType error code.  0 means success.                             */
238   /*                                                                       */
239   FT_EXPORT_FUNC( FT_Error )  FT_New_Stream( const char*  filepathname,
240                                              FT_Stream    stream )
241   {
242 /*    FILE*  file; FIXME */
243
244     DbgPrint("ftsystem.c: UNIMPLEMENTED CALL\n");
245
246 /*    if ( !stream )
247       return FT_Err_Invalid_Stream_Handle;
248
249     file = fopen( filepathname, "rb" );
250     if ( !file )
251     {
252       FT_ERROR(( "FT_New_Stream:" ));
253       FT_ERROR(( " could not open `%s'\n", filepathname ));
254
255       return FT_Err_Cannot_Open_Resource;
256     }
257
258     fseek( file, 0, SEEK_END );
259     stream->size = ftell( file );
260     fseek( file, 0, SEEK_SET );
261
262     stream->descriptor.pointer = file;
263     stream->pathname.pointer   = (char*)filepathname;
264     stream->pos                = 0;
265
266     stream->read  = ft_io_stream;
267     stream->close = ft_close_stream;
268
269     FT_TRACE1(( "FT_New_Stream:" ));
270     FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
271                 filepathname, stream->size )); */
272
273     return FT_Err_Ok;
274   }
275
276
277   /*************************************************************************/
278   /*                                                                       */
279   /* <Function>                                                            */
280   /*    FT_New_Memory                                                      */
281   /*                                                                       */
282   /* <Description>                                                         */
283   /*    Creates a new memory object.                                       */
284   /*                                                                       */
285   /* <Return>                                                              */
286   /*    A pointer to the new memory object.  0 in case of error.           */
287   /*                                                                       */
288   FT_EXPORT_FUNC( FT_Memory )  FT_New_Memory( void )
289   {
290     FT_Memory  memory;
291
292 /*    memory = (FT_Memory)malloc( sizeof ( *memory ) ); */
293
294     memory = ExAllocatePool(NonPagedPool, sizeof(*memory));
295     if ( memory )
296     {
297       memory->user    = 0;
298       memory->alloc   = ft_alloc;
299       memory->realloc = ft_realloc;
300       memory->free    = ft_free;
301     }
302
303     return memory;
304   }
305
306
307 /* END */