summaryrefslogtreecommitdiff
path: root/Build/source/libs/freetype/freetype-1.5/lib/ttfile.h
blob: 13d5fb98e15d11ac0a0a5c60d14b25d8ddc282fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/*******************************************************************
 *
 *  ttfile.h                                                     1.4
 *
 *    File I/O Component (specification).
 *
 *  Copyright 1996-2002 by
 *  David Turner, Robert Wilhelm, and Werner Lemberg.
 *
 *  This file is part of the FreeType project, and may only be used
 *  modified and distributed under the terms of the FreeType project
 *  license, LICENSE.TXT.  By continuing to use, modify, or distribute
 *  this file you indicate that you have read the license and
 *  understand and accept it fully.
 *
 *  Changes between 1.4 and 1.2 :
 *
 *  - the macros which used to be in ttload.h are now here
 *    (with their underlying functions)
 *
 *  Changes between 1.3 and 1.2:
 *
 *  - all functions report error values now
 *
 *  - the stream semantics have also changed
 *
 *  Changes between 1.2 and 1.1:
 *
 *  - added macros to support re-entrant builds
 *
 *  - added the TT_Duplicate_File function to duplicate streams
 *    (re-entrant builds only)
 *
 ******************************************************************/

#ifndef TTFILE_H
#define TTFILE_H

#include "ttconfig.h"
#include "freetype.h"
#include "ttengine.h"
#include "ttdebug.h"

#ifdef __cplusplus
  extern "C" {
#endif

  /* Initialize file component */
  FT_INTERNAL_DEF( TT_Error )
  TTFile_Init( PEngine_Instance  engine );

  /* Done with file component */
  FT_INTERNAL_DEF( TT_Error )
  TTFile_Done( PEngine_Instance  engine );


  /****************************************************************/
  /*                                                              */
  /*  Macros.                                                     */
  /*                                                              */
  /****************************************************************/

/* The following macros are defined to simplify the writing of */
/* the various table and glyph loaders.                        */

/* For examples see the code in ttload.c, ttgload.c etc.       */

#define USE_Stream( original, duplicate ) \
          ( (error = TT_Use_Stream( original, &duplicate )) != TT_Err_Ok )

#define DONE_Stream( _stream ) \
          TT_Done_Stream( &_stream )

/* Define a file frame -- use it only when needed */
#define DEFINE_A_FRAME   TFileFrame  frame = TT_Null_FileFrame

/* Define a stream -- use it only when needed */
#define DEFINE_A_STREAM  TT_Stream   stream


#ifdef TT_CONFIG_OPTION_THREAD_SAFE  /* re-entrant implementation */

/* The following macros define the necessary local */
/* variables used to access streams and frames.    */

/* Define stream locals with frame */
#define DEFINE_STREAM_LOCALS  \
          TT_Error  error;    \
          DEFINE_A_STREAM;    \
          DEFINE_A_FRAME

/* Define stream locals without frame */
#define DEFINE_STREAM_LOCALS_WO_FRAME  \
          TT_Error  error;             \
          DEFINE_A_STREAM

/* Define locals with a predefined stream in reentrant mode -- see ttload.c */
#define DEFINE_LOAD_LOCALS( STREAM )  \
          TT_Error  error;            \
          DEFINE_A_STREAM = (STREAM); \
          DEFINE_A_FRAME

/* Define locals without frame with a predefined stream - see ttload.c */
#define DEFINE_LOAD_LOCALS_WO_FRAME( STREAM ) \
          TT_Error      error;                \
          DEFINE_A_STREAM = (STREAM)

/* Define all locals necessary to access a font file */
#define DEFINE_ALL_LOCALS  \
          TT_Error  error; \
          DEFINE_A_STREAM; \
          DEFINE_A_FRAME


#define ACCESS_Frame( _size_ ) \
          ( (error = TT_Access_Frame( stream, \
                                      &frame, \
                                      (Long)(_size_) )) != TT_Err_Ok )
#define CHECK_AND_ACCESS_Frame( _size_ ) \
          ( (error = TT_Check_And_Access_Frame( stream, \
                                                &frame, \
                                                (Long)(_size_) )) != TT_Err_Ok )
#define FORGET_Frame() \
          ( (void)TT_Forget_Frame( stream, &frame ) )

#define GET_Byte()    TT_Get_Byte  ( &frame )
#define GET_Char()    TT_Get_Char  ( &frame )
#define GET_UShort()  TT_Get_UShort( &frame )
#define GET_Short()   TT_Get_Short ( &frame )
#define GET_Long()    TT_Get_Long  ( &frame )
#define GET_ULong()   TT_Get_ULong ( &frame )
#define GET_Tag4()    TT_Get_ULong ( &frame )

#define FILE_Pos()    TT_File_Pos ( stream )

#define FILE_Seek( _position_ ) \
          ( (error = TT_Seek_File( stream, \
                                   (Long)(_position_) )) != TT_Err_Ok )
#define FILE_Skip( _distance_ ) \
          ( (error = TT_Skip_File( stream, \
                                   (Long)(_distance_) )) != TT_Err_Ok )
#define FILE_Read( buffer, count ) \
          ( (error = TT_Read_File ( stream, \
                                    buffer, \
                                    (Long)(count) )) != TT_Err_Ok )
#define FILE_Read_At( pos, buffer, count ) \
          ( (error = TT_Read_At_File( stream, \
                                      (Long)(pos), \
                                      buffer, \
                                      (Long)(count) )) != TT_Err_Ok )

#else   /* thread-safe implementation */

/* Define stream locals with frame -- nothing in thread-safe mode */
#define DEFINE_STREAM_LOCALS  \
          TT_Error  error

/* Define stream locals without frame -- nothing in thread-safe mode */
#define DEFINE_STREAM_LOCALS_WO_FRAME \
          TT_Error  error

/* Define locals with a predefined stream in reentrant mode -- see ttload.c */
#define DEFINE_LOAD_LOCALS( STREAM ) \
          TT_Error  error


/* Define locals without frame with a predefined stream - see ttload.c */
#define DEFINE_LOAD_LOCALS_WO_FRAME( STREAM ) \
          TT_Error  error

/* Define all locals necessary to access a font file */
#define DEFINE_ALL_LOCALS  \
          TT_Error  error; \
          DEFINE_A_STREAM


#define ACCESS_Frame( _size_ ) \
          ( (error = TT_Access_Frame( (Long)(_size_) )) != TT_Err_Ok )
#define CHECK_AND_ACCESS_Frame( _size_ ) \
          ( (error = TT_Check_And_Access_Frame( (Long)(_size_) )) != TT_Err_Ok )
#define FORGET_Frame() \
          ( (void)TT_Forget_Frame() )

#define GET_Byte()    TT_Get_Byte  ()
#define GET_Char()    TT_Get_Char  ()
#define GET_UShort()  TT_Get_UShort()
#define GET_Short()   TT_Get_Short ()
#define GET_Long()    TT_Get_Long  ()
#define GET_ULong()   TT_Get_ULong ()
#define GET_Tag4()    TT_Get_ULong ()

#define FILE_Pos()    TT_File_Pos()

#define FILE_Seek( _position_ ) \
          ( (error = TT_Seek_File( (Long)(_position_) )) != TT_Err_Ok )
#define FILE_Skip( _distance_ ) \
          ( (error = TT_Skip_File( (Long)(_distance_) )) != TT_Err_Ok )
#define FILE_Read( buffer, count ) \
          ( (error = TT_Read_File ( buffer, \
                                    (Long)(count) )) != TT_Err_Ok )
#define FILE_Read_At( pos, buffer, count ) \
          ( (error = TT_Read_At_File( (Long)(pos), \
                                      buffer, \
                                      (Long)(count) )) != TT_Err_Ok )

#endif /* TT_CONFIG_OPTION_THREAD_SAFE */


  /****************************************************************/
  /*                                                              */
  /*  Stream functions.                                           */
  /*                                                              */
  /****************************************************************/

  /* Open a file and return a stream handle for it.           */
  /* Should only be used for a new face object's main stream. */

  FT_INTERNAL_DEF( TT_Error )
  TT_Open_Stream( const TT_Text* name,
                  TT_Stream*     stream );


  /* Closes, then discards, a stream when it's no longer needed.   */
  /* Should only be used for a stream opend with TT_Open_Stream(). */

  FT_INTERNAL_DEF( TT_Error )
  TT_Close_Stream( TT_Stream*  stream );


  /* Informs the component that we're going to use the file   */
  /* opened in 'org_stream', and report errors to the 'error' */
  /* variable.                                                */

  /* in non re-entrant builds, 'org_stream' is simply copied   */
  /* to 'stream'. Otherwise, the latter is a duplicate handle  */
  /* for the file opened with 'org_stream'                     */

  FT_EXPORT_DEF( TT_Error )
  TT_Use_Stream( TT_Stream   org_stream,
                 TT_Stream*  stream );

  /* Informs the component that we don't need to perform file */
  /* operations on the stream 'stream' anymore.  This must be */
  /* used with streams "opened" with TT_Use_Stream() only!    */

  /* in re-entrant builds, this will really discard the stream */

  FT_EXPORT_DEF( TT_Error )
  TT_Done_Stream( TT_Stream*  stream );

  /* Closes the stream's file handle to release system resources */
  /* The function TT_Use_Stream automatically re-activates a     */
  /* flushed stream when it uses one                             */

  FT_EXPORT_DEF( TT_Error )
  TT_Flush_Stream( TT_Stream*  stream );

/* The macros STREAM_ARGS and STREAM_ARG let us build a thread-safe */
/* or re-entrant implementation depending on a single configuration */
/*define.                                                           */

#ifdef TT_CONFIG_OPTION_THREAD_SAFE

#define STREAM_ARGS   TT_Stream  stream,
#define STREAM_ARG    TT_Stream  stream

#else

#define STREAM_ARGS   /* void */
#define STREAM_ARG    void

#endif /* TT_CONFIG_OPTION_THREAD_SAFE */


  /****************************************************************/
  /*                                                              */
  /*  File Functions.                                             */
  /*                                                              */
  /*  The following functions perform file operations on the      */
  /*  currently 'used' stream.  In thread-safe builds, only one   */
  /*  stream can be used at a time.  Synchronisation is performed */
  /*  through the Use_Stream()/Done_Stream() functions.           */
  /*                                                              */
  /****************************************************************/

  /* Read 'count' bytes from file into 'buffer' */

  FT_EXPORT_DEF( TT_Error )
  TT_Read_File( STREAM_ARGS void*   buffer,
                            Long    count );


  /* Seek file cursor to a given position */

  FT_EXPORT_DEF( TT_Error )
  TT_Seek_File( STREAM_ARGS Long  position );


  /* Skip the next 'distance' bytes in file */

  FT_EXPORT_DEF( TT_Error )
  TT_Skip_File( STREAM_ARGS Long  distance );


  /* Read the 'count' bytes at 'position' into 'buffer' */

  FT_EXPORT_DEF( TT_Error )
  TT_Read_At_File( STREAM_ARGS Long   position,
                               void*  buffer,
                               Long   count );

  /* Return current file position */

  FT_EXPORT_DEF( Long )
  TT_File_Pos( STREAM_ARG );

  /* Return length of a given stream, even if it is flushed */

  FT_EXPORT_DEF( Long )
  TT_Stream_Size( TT_Stream  stream );


  /****************************************************************/
  /*                                                              */
  /*  Frame operations.                                           */
  /*                                                              */
  /*  For a comprehensive explanation of frames, please refer to  */
  /*  the documentation files.                                    */
  /*                                                              */
  /****************************************************************/

  /* Frame type declaration.*/

  struct  TFileFrame_
  {
    Byte*  address;  /* frame buffer                     */
    Byte*  cursor;   /* current cursor position in frame */
    Long   size;     /* frame size                       */
  };

  typedef struct TFileFrame_  TFileFrame;

  FT_EXPORT_DECL( const TFileFrame )
        TT_Null_FileFrame;


/* The macro ZERO_Frame is used to define and init a frame.      */
/* It is important to have a default frame of { NULL, NULL, 0 }  */
/* before a call to TT_Access_Frame().  Otherwise, the call will */
/* fail with a TT_Err_Nested_Frame_Accesses error.               */

#define ZERO_Frame( frame )     \
      {                         \
        (frame).address = NULL; \
        (frame).cursor  = NULL; \
        (frame).size    = 0;    \
      }


/* The macros FRAME_ARGS and FRAME_ARG let us build a thread-safe   */
/* or re-entrant implementation depending on a single configuration */
/* define                                                           */

#ifdef TT_CONFIG_OPTION_THREAD_SAFE

#define FRAME_ARGS   TFileFrame*  frame,
#define FRAME_ARG    TFileFrame*  frame

#else

#define FRAME_ARGS   /* void */
#define FRAME_ARG    void

#endif /* TT_CONFIG_OPTION_THREAD_SAFE */


  /* Access the next 'size' bytes from current position. */
  /* Fails if all bytes cannot be read/accessed.         */

  FT_EXPORT_DEF( TT_Error )
  TT_Access_Frame( STREAM_ARGS FRAME_ARGS Long  size );


  /* Access the bytes located in the next 'size' bytes of the file. */
  /* Doesn't fail if less than 'size' bytes are accessible (like    */
  /* at the end of the file).                                       */

  FT_EXPORT_DEF( TT_Error )
  TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS Long  size );

  /* Forget frame */

  FT_EXPORT_DEF( TT_Error )
  TT_Forget_Frame( STREAM_ARGS FRAME_ARG );


  /* primitive routines for data accessing */

  FT_EXPORT_DEF( Char )
  TT_Get_Char(  FRAME_ARG );

  FT_EXPORT_DEF( Short )
  TT_Get_Short( FRAME_ARG );

  FT_EXPORT_DEF( Long  )
  TT_Get_Long(  FRAME_ARG );

#ifdef TT_CONFIG_OPTION_THREAD_SAFE

#define  TT_Get_Byte( frame )   ( (Byte  )TT_Get_Char ( frame ) )
#define  TT_Get_UShort( frame ) ( (UShort)TT_Get_Short( frame ) )
#define  TT_Get_ULong( frame )  ( (ULong )TT_Get_Long ( frame ) )

#else

#define  TT_Get_Byte()   ( (Byte  )TT_Get_Char () )
#define  TT_Get_UShort() ( (UShort)TT_Get_Short() )
#define  TT_Get_ULong()  ( (ULong )TT_Get_Long () )

#endif /* TT_CONFIG_OPTION_THREAD_SAFE */


#ifdef __cplusplus
  }
#endif

#endif /* TTFILE_H */


/* END */