home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / ft-beta.zip / freetype / lib / ttfile.h < prev    next >
C/C++ Source or Header  |  1997-10-06  |  7KB  |  195 lines

  1. /*******************************************************************
  2.  *
  3.  *  ttfile.h                                                     1.3
  4.  *
  5.  *    File I/O Component (specification).
  6.  *
  7.  *  Copyright 1996, 1997 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.  *  Changes between 1.3 and 1.2 :
  17.  *
  18.  *  - all functions report error values now
  19.  *
  20.  *  - the stream semantics have also changed
  21.  *
  22.  *  Changes between 1.2 and 1.1 :
  23.  *
  24.  *  - added macros to support re-entrant builds
  25.  *
  26.  *  - added the TT_Duplicate_File function to duplicate streams
  27.  *    ( re-entrant builds only )
  28.  *
  29.  ******************************************************************/
  30.  
  31. /* #define TT_CONFIG_REENTRANT */
  32.  
  33. #ifndef TTFILE_H
  34. #define TTFILE_H
  35.  
  36. #include "freetype.h"
  37. #include "tterror.h"
  38.  
  39.   #ifdef __cplusplus
  40.   extern "C" {
  41.   #endif
  42.   
  43.   TT_Error  TTFile_Init();
  44.   /* Init file component */
  45.  
  46.   TT_Error  TTFile_Done();
  47.   /* Done with file component */
  48.  
  49.   /**********************************************************************/
  50.   /*                                                                    */
  51.   /*  Stream functions.                                                 */
  52.   /*                                                                    */
  53.   /**********************************************************************/
  54.  
  55.   TT_Error  TT_Open_Stream( const char*  name,
  56.                             TT_Stream*   stream );
  57.   /* Open a file and return a stream handle for it           */
  58.   /* should only be used for a new face object's main stream */
  59.  
  60.   TT_Error  TT_Close_Stream( TT_Stream*  stream );
  61.   /* closes, then discards, a stream when it becomes unuseful   */
  62.   /* should only be used for a stream opend with TT_Open_Stream */
  63.  
  64.   TT_Error  TT_Use_Stream( TT_Stream   org_stream,
  65.                            TT_Stream*  stream );
  66.   /* Notice the component that we're going to use the file     */
  67.   /* opened in 'org_stream', and report errors to the 'error'  */
  68.   /* variable.                                                 */
  69.  
  70.   /* in non re-entrant builds, 'org_stream' is simply copied   */
  71.   /* to 'stream'. Otherwise, the latter is a duplicate handle  */
  72.   /* for the file opened with 'org_stream'                     */
  73.  
  74.   TT_Error  TT_Done_Stream( TT_Stream*  stream );
  75.   /* Notice the component that we don't need to perform file */
  76.   /* operations on the stream 'stream' anymore. This must be */
  77.   /* used with streams "opened" with TT_Use_Stream only !    */
  78.  
  79.   /* in re-entrant builds, this will really discard the stream */
  80.  
  81. #ifdef TT_CONFIG_REENTRANT
  82.   #define STREAM_ARGS   TT_Stream  stream,
  83.   #define STREAM_ARG    TT_Stream  stream
  84.  
  85. #else
  86.   #define STREAM_ARGS   /* void */
  87.   #define STREAM_ARG
  88.  
  89. #endif /* REENTRANT */
  90.  
  91.   /* The macro STREAM_OPS lets us build a thread-safe or re-entrant  */
  92.   /* implementation depending on a single configuration define     */
  93.  
  94.   /****************************************************************/
  95.   /*                                                              */
  96.   /*  File Functions.                                             */
  97.   /*                                                              */
  98.   /*  the following functions perform file operations on the      */
  99.   /*  currently 'used' stream. In thread-safe builds, only one    */
  100.   /*  stream can be used at a time. Synchronisation is performed  */
  101.   /*  through the Use_Stream/Done_Stream functions.               */
  102.   /*                                                              */
  103.   /****************************************************************/
  104.  
  105.   TT_Error  TT_Read_File( STREAM_ARGS void*  buffer, 
  106.                                       long   count );
  107.   /* Read 'count' bytes from file into 'buffer' */
  108.  
  109.   TT_Error  TT_Seek_File( STREAM_ARGS long  position );
  110.   /* Seek file cursor to a given position */
  111.  
  112.   TT_Error  TT_Skip_File( STREAM_ARGS long  distance );
  113.   /* Skip the next 'distance' bytes in file */
  114.  
  115.   TT_Error  TT_Read_At_File( STREAM_ARGS long   position,
  116.                                          void*  buffer,
  117.                                          long   count );
  118.   /* Read the 'count' bytes at 'position' into 'buffer' */
  119.  
  120.   Long  TT_File_Pos( STREAM_ARG );
  121.   /* Return current file position */
  122.  
  123.   /********************************************************************/
  124.   /*                                                                  */
  125.   /*  Frame operations.                                               */
  126.   /*                                                                  */
  127.   /*  For a comprehensive explanation of frames, please refer to the  */
  128.   /*  documentation file 'macros.txt'                                 */
  129.   /*                                                                  */
  130.   /********************************************************************/
  131.  
  132.   /* Frame type declaration.*/
  133.  
  134.   typedef struct _TFileFrame
  135.   {
  136.     unsigned char*  address;  /* frame buffer                     */
  137.     unsigned char*  cursor;   /* current cursor position in frame */
  138.     int             size;     /* frame size                       */
  139.   } TFileFrame;
  140.  
  141.   extern const TFileFrame  Null_FileFrame;
  142.  
  143.   #define ZERO_Frame(frame) \
  144.       { \
  145.         (frame).address = NULL; \
  146.         (frame).cursor  = NULL; \
  147.         (frame).size    = 0;    \
  148.       }
  149.  
  150.   /* The macro CONSTRUCT_FRAME is used to define and init a frame  */
  151.   /* It is important to have an default frame of { NULL, NULL, 0 } */
  152.   /* before a call to TT_Access_Frame. Otherwise, the call will    */
  153.   /* fail with a TT_Err_Nested_Frame_Accesses error                */
  154.  
  155. #ifdef TT_CONFIG_REENTRANT
  156.   #define FRAME_ARGS   TFileFrame* frame,
  157.   #define FRAME_ARG    TFileFrame* frame
  158.  
  159. #else
  160.   #define FRAME_ARGS  /* void */
  161.   #define FRAME_ARG   /* void */
  162.  
  163. #endif /* REENTRANT */
  164.  
  165.   /* The macro FRAME_OPS lets us build a thread-safe or re-entrant */
  166.   /* implementation depending on a single configuration define     */
  167.  
  168.   TT_Error  TT_Access_Frame( STREAM_ARGS FRAME_ARGS int size );
  169.   /* Access the next 'size' bytes from current position */
  170.   /* Fails if all bytes cannot be read/accessed         */
  171.  
  172.   TT_Error  TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS int size );
  173.   /* Access the bytes located in the next 'size' bytes of the file */
  174.   /* Doesn't fail if less than 'size' bytes are accessible ( like  */
  175.   /* at the end of the file )                                      */
  176.  
  177.   TT_Error  TT_Forget_Frame( FRAME_ARG );
  178.   /* Forget frame */
  179.  
  180.   unsigned char   Get_Byte  ( FRAME_ARG );
  181.   char            Get_Char  ( FRAME_ARG );
  182.   short           Get_Short ( FRAME_ARG );
  183.   unsigned short  Get_UShort( FRAME_ARG );
  184.   long            Get_Long  ( FRAME_ARG );
  185.   unsigned long   Get_ULong ( FRAME_ARG );
  186.  
  187.   #ifdef __cplusplus
  188.   }
  189.   #endif
  190.  
  191. #endif /* TTFILE_H */
  192.  
  193.  
  194. /* End */
  195.