src/java.desktop/share/native/libfreetype/include/freetype/internal/ftstream.h
changeset 54876 da3834261f0c
parent 49234 3375a8039fde
equal deleted inserted replaced
54875:bcfedddcf4ce 54876:da3834261f0c
     1 /***************************************************************************/
     1 /****************************************************************************
     2 /*                                                                         */
     2  *
     3 /*  ftstream.h                                                             */
     3  * ftstream.h
     4 /*                                                                         */
     4  *
     5 /*    Stream handling (specification).                                     */
     5  *   Stream handling (specification).
     6 /*                                                                         */
     6  *
     7 /*  Copyright 1996-2018 by                                                 */
     7  * Copyright (C) 1996-2019 by
     8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
     8  * David Turner, Robert Wilhelm, and Werner Lemberg.
     9 /*                                                                         */
     9  *
    10 /*  This file is part of the FreeType project, and may only be used,       */
    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      */
    11  * modified, and distributed under the terms of the FreeType project
    12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
    12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
    13 /*  this file you indicate that you have read the license and              */
    13  * this file you indicate that you have read the license and
    14 /*  understand and accept it fully.                                        */
    14  * understand and accept it fully.
    15 /*                                                                         */
    15  *
    16 /***************************************************************************/
    16  */
    17 
    17 
    18 
    18 
    19 #ifndef FTSTREAM_H_
    19 #ifndef FTSTREAM_H_
    20 #define FTSTREAM_H_
    20 #define FTSTREAM_H_
    21 
    21 
    94 
    94 
    95   /* Construct an FT_Frame_Field out of a structure type and a field name. */
    95   /* Construct an FT_Frame_Field out of a structure type and a field name. */
    96   /* The structure type must be set in the FT_STRUCTURE macro before       */
    96   /* The structure type must be set in the FT_STRUCTURE macro before       */
    97   /* calling the FT_FRAME_START() macro.                                   */
    97   /* calling the FT_FRAME_START() macro.                                   */
    98   /*                                                                       */
    98   /*                                                                       */
    99 #define FT_FIELD_SIZE( f ) \
    99 #define FT_FIELD_SIZE( f )                          \
   100           (FT_Byte)sizeof ( ((FT_STRUCTURE*)0)->f )
   100           (FT_Byte)sizeof ( ((FT_STRUCTURE*)0)->f )
   101 
   101 
   102 #define FT_FIELD_SIZE_DELTA( f ) \
   102 #define FT_FIELD_SIZE_DELTA( f )                       \
   103           (FT_Byte)sizeof ( ((FT_STRUCTURE*)0)->f[0] )
   103           (FT_Byte)sizeof ( ((FT_STRUCTURE*)0)->f[0] )
   104 
   104 
   105 #define FT_FIELD_OFFSET( f ) \
   105 #define FT_FIELD_OFFSET( f )                         \
   106           (FT_UShort)( offsetof( FT_STRUCTURE, f ) )
   106           (FT_UShort)( offsetof( FT_STRUCTURE, f ) )
   107 
   107 
   108 #define FT_FRAME_FIELD( frame_op, field ) \
   108 #define FT_FRAME_FIELD( frame_op, field ) \
   109           {                               \
   109           {                               \
   110             frame_op,                     \
   110             frame_op,                     \
   145           }
   145           }
   146 
   146 
   147 #define FT_FRAME_SKIP_BYTES( count )  { ft_frame_skip, count, 0 }
   147 #define FT_FRAME_SKIP_BYTES( count )  { ft_frame_skip, count, 0 }
   148 
   148 
   149 
   149 
   150   /*************************************************************************/
   150   /**************************************************************************
   151   /*                                                                       */
   151    *
   152   /* Integer extraction macros -- the `buffer' parameter must ALWAYS be of */
   152    * Integer extraction macros -- the 'buffer' parameter must ALWAYS be of
   153   /* type `char*' or equivalent (1-byte elements).                         */
   153    * type 'char*' or equivalent (1-byte elements).
   154   /*                                                                       */
   154    */
   155 
   155 
   156 #define FT_BYTE_( p, i )  ( ((const FT_Byte*)(p))[(i)] )
   156 #define FT_BYTE_( p, i )  ( ((const FT_Byte*)(p))[(i)] )
   157 
   157 
   158 #define FT_INT16( x )   ( (FT_Int16)(x)  )
   158 #define FT_INT16( x )   ( (FT_Int16)(x)  )
   159 #define FT_UINT16( x )  ( (FT_UInt16)(x) )
   159 #define FT_UINT16( x )  ( (FT_UInt16)(x) )
   163 
   163 
   164 #define FT_BYTE_U16( p, i, s )  ( FT_UINT16( FT_BYTE_( p, i ) ) << (s) )
   164 #define FT_BYTE_U16( p, i, s )  ( FT_UINT16( FT_BYTE_( p, i ) ) << (s) )
   165 #define FT_BYTE_U32( p, i, s )  ( FT_UINT32( FT_BYTE_( p, i ) ) << (s) )
   165 #define FT_BYTE_U32( p, i, s )  ( FT_UINT32( FT_BYTE_( p, i ) ) << (s) )
   166 
   166 
   167 
   167 
       
   168   /*
       
   169    * `FT_PEEK_XXX' are generic macros to get data from a buffer position.  No
       
   170    * safety checks are performed.
       
   171    */
   168 #define FT_PEEK_SHORT( p )  FT_INT16( FT_BYTE_U16( p, 0, 8 ) | \
   172 #define FT_PEEK_SHORT( p )  FT_INT16( FT_BYTE_U16( p, 0, 8 ) | \
   169                                       FT_BYTE_U16( p, 1, 0 ) )
   173                                       FT_BYTE_U16( p, 1, 0 ) )
   170 
   174 
   171 #define FT_PEEK_USHORT( p )  FT_UINT16( FT_BYTE_U16( p, 0, 8 ) | \
   175 #define FT_PEEK_USHORT( p )  FT_UINT16( FT_BYTE_U16( p, 0, 8 ) | \
   172                                         FT_BYTE_U16( p, 1, 0 ) )
   176                                         FT_BYTE_U16( p, 1, 0 ) )
   211 
   215 
   212 #define FT_PEEK_UOFF3_LE( p )  FT_UINT32( FT_BYTE_U32( p, 2, 16 ) | \
   216 #define FT_PEEK_UOFF3_LE( p )  FT_UINT32( FT_BYTE_U32( p, 2, 16 ) | \
   213                                           FT_BYTE_U32( p, 1,  8 ) | \
   217                                           FT_BYTE_U32( p, 1,  8 ) | \
   214                                           FT_BYTE_U32( p, 0,  0 ) )
   218                                           FT_BYTE_U32( p, 0,  0 ) )
   215 
   219 
   216 
   220   /*
       
   221    * `FT_NEXT_XXX' are generic macros to get data from a buffer position
       
   222    * which is then increased appropriately.  No safety checks are performed.
       
   223    */
   217 #define FT_NEXT_CHAR( buffer )       \
   224 #define FT_NEXT_CHAR( buffer )       \
   218           ( (signed char)*buffer++ )
   225           ( (signed char)*buffer++ )
   219 
   226 
   220 #define FT_NEXT_BYTE( buffer )         \
   227 #define FT_NEXT_BYTE( buffer )         \
   221           ( (unsigned char)*buffer++ )
   228           ( (unsigned char)*buffer++ )
   256 
   263 
   257 #define FT_NEXT_ULONG_LE( buffer )                                           \
   264 #define FT_NEXT_ULONG_LE( buffer )                                           \
   258           ( (unsigned long)( buffer += 4, FT_PEEK_ULONG_LE( buffer - 4 ) ) )
   265           ( (unsigned long)( buffer += 4, FT_PEEK_ULONG_LE( buffer - 4 ) ) )
   259 
   266 
   260 
   267 
   261   /*************************************************************************/
   268   /**************************************************************************
   262   /*                                                                       */
   269    *
   263   /* Each GET_xxxx() macro uses an implicit `stream' variable.             */
   270    * The `FT_GET_XXX` macros use an implicit 'stream' variable.
   264   /*                                                                       */
   271    *
       
   272    * Note that a call to `FT_STREAM_SEEK` or `FT_STREAM_POS` has **no**
       
   273    * effect on `FT_GET_XXX`!  They operate on `stream->pos`, while
       
   274    * `FT_GET_XXX` use `stream->cursor`.
       
   275    */
   265 #if 0
   276 #if 0
   266 #define FT_GET_MACRO( type )    FT_NEXT_ ## type ( stream->cursor )
   277 #define FT_GET_MACRO( type )    FT_NEXT_ ## type ( stream->cursor )
   267 
   278 
   268 #define FT_GET_CHAR()       FT_GET_MACRO( CHAR )
   279 #define FT_GET_CHAR()       FT_GET_MACRO( CHAR )
   269 #define FT_GET_BYTE()       FT_GET_MACRO( BYTE )
   280 #define FT_GET_BYTE()       FT_GET_MACRO( BYTE )
   297 #define FT_GET_USHORT_LE()  FT_GET_MACRO( FT_Stream_GetUShortLE, FT_UShort )
   308 #define FT_GET_USHORT_LE()  FT_GET_MACRO( FT_Stream_GetUShortLE, FT_UShort )
   298 #define FT_GET_LONG_LE()    FT_GET_MACRO( FT_Stream_GetULongLE, FT_Long )
   309 #define FT_GET_LONG_LE()    FT_GET_MACRO( FT_Stream_GetULongLE, FT_Long )
   299 #define FT_GET_ULONG_LE()   FT_GET_MACRO( FT_Stream_GetULongLE, FT_ULong )
   310 #define FT_GET_ULONG_LE()   FT_GET_MACRO( FT_Stream_GetULongLE, FT_ULong )
   300 #endif
   311 #endif
   301 
   312 
       
   313 
   302 #define FT_READ_MACRO( func, type, var )        \
   314 #define FT_READ_MACRO( func, type, var )        \
   303           ( var = (type)func( stream, &error ), \
   315           ( var = (type)func( stream, &error ), \
   304             error != FT_Err_Ok )
   316             error != FT_Err_Ok )
   305 
   317 
       
   318   /*
       
   319    * The `FT_READ_XXX' macros use implicit `stream' and `error' variables.
       
   320    *
       
   321    * `FT_READ_XXX' can be controlled with `FT_STREAM_SEEK' and
       
   322    * `FT_STREAM_POS'.  They use the full machinery to check whether a read is
       
   323    * valid.
       
   324    */
   306 #define FT_READ_BYTE( var )       FT_READ_MACRO( FT_Stream_ReadChar, FT_Byte, var )
   325 #define FT_READ_BYTE( var )       FT_READ_MACRO( FT_Stream_ReadChar, FT_Byte, var )
   307 #define FT_READ_CHAR( var )       FT_READ_MACRO( FT_Stream_ReadChar, FT_Char, var )
   326 #define FT_READ_CHAR( var )       FT_READ_MACRO( FT_Stream_ReadChar, FT_Char, var )
   308 #define FT_READ_SHORT( var )      FT_READ_MACRO( FT_Stream_ReadUShort, FT_Short, var )
   327 #define FT_READ_SHORT( var )      FT_READ_MACRO( FT_Stream_ReadUShort, FT_Short, var )
   309 #define FT_READ_USHORT( var )     FT_READ_MACRO( FT_Stream_ReadUShort, FT_UShort, var )
   328 #define FT_READ_USHORT( var )     FT_READ_MACRO( FT_Stream_ReadUShort, FT_UShort, var )
   310 #define FT_READ_OFF3( var )       FT_READ_MACRO( FT_Stream_ReadUOffset, FT_Long, var )
   329 #define FT_READ_OFF3( var )       FT_READ_MACRO( FT_Stream_ReadUOffset, FT_Long, var )
   385                      FT_Byte*   buffer,
   404                      FT_Byte*   buffer,
   386                      FT_ULong   count );
   405                      FT_ULong   count );
   387 
   406 
   388   /* Enter a frame of `count' consecutive bytes in a stream.  Returns an */
   407   /* Enter a frame of `count' consecutive bytes in a stream.  Returns an */
   389   /* error if the frame could not be read/accessed.  The caller can use  */
   408   /* error if the frame could not be read/accessed.  The caller can use  */
   390   /* the FT_Stream_Get_XXX functions to retrieve frame data without      */
   409   /* the `FT_Stream_GetXXX' functions to retrieve frame data without     */
   391   /* error checks.                                                       */
   410   /* error checks.                                                       */
   392   /*                                                                     */
   411   /*                                                                     */
   393   /* You must _always_ call FT_Stream_ExitFrame() once you have entered  */
   412   /* You must _always_ call `FT_Stream_ExitFrame' once you have entered  */
   394   /* a stream frame!                                                     */
   413   /* a stream frame!                                                     */
       
   414   /*                                                                     */
       
   415   /* Nested frames are not permitted.                                    */
   395   /*                                                                     */
   416   /*                                                                     */
   396   FT_BASE( FT_Error )
   417   FT_BASE( FT_Error )
   397   FT_Stream_EnterFrame( FT_Stream  stream,
   418   FT_Stream_EnterFrame( FT_Stream  stream,
   398                         FT_ULong   count );
   419                         FT_ULong   count );
   399 
   420 
   400   /* exit a stream frame */
   421   /* exit a stream frame */
   401   FT_BASE( void )
   422   FT_BASE( void )
   402   FT_Stream_ExitFrame( FT_Stream  stream );
   423   FT_Stream_ExitFrame( FT_Stream  stream );
   403 
   424 
       
   425 
   404   /* Extract a stream frame.  If the stream is disk-based, a heap block */
   426   /* Extract a stream frame.  If the stream is disk-based, a heap block */
   405   /* is allocated and the frame bytes are read into it.  If the stream  */
   427   /* is allocated and the frame bytes are read into it.  If the stream  */
   406   /* is memory-based, this function simply set a pointer to the data.   */
   428   /* is memory-based, this function simply sets a pointer to the data.  */
   407   /*                                                                    */
   429   /*                                                                    */
   408   /* Useful to optimize access to memory-based streams transparently.   */
   430   /* Useful to optimize access to memory-based streams transparently.   */
   409   /*                                                                    */
   431   /*                                                                    */
   410   /* All extracted frames must be `freed' with a call to the function   */
   432   /* `FT_Stream_GetXXX' functions can't be used.                        */
   411   /* FT_Stream_ReleaseFrame().                                          */
   433   /*                                                                    */
       
   434   /* An extracted frame must be `freed' with a call to the function     */
       
   435   /* `FT_Stream_ReleaseFrame'.                                          */
   412   /*                                                                    */
   436   /*                                                                    */
   413   FT_BASE( FT_Error )
   437   FT_BASE( FT_Error )
   414   FT_Stream_ExtractFrame( FT_Stream  stream,
   438   FT_Stream_ExtractFrame( FT_Stream  stream,
   415                           FT_ULong   count,
   439                           FT_ULong   count,
   416                           FT_Byte**  pbytes );
   440                           FT_Byte**  pbytes );
   417 
   441 
   418   /* release an extract frame (see FT_Stream_ExtractFrame) */
   442   /* release an extract frame (see `FT_Stream_ExtractFrame') */
   419   FT_BASE( void )
   443   FT_BASE( void )
   420   FT_Stream_ReleaseFrame( FT_Stream  stream,
   444   FT_Stream_ReleaseFrame( FT_Stream  stream,
   421                           FT_Byte**  pbytes );
   445                           FT_Byte**  pbytes );
       
   446 
   422 
   447 
   423   /* read a byte from an entered frame */
   448   /* read a byte from an entered frame */
   424   FT_BASE( FT_Char )
   449   FT_BASE( FT_Char )
   425   FT_Stream_GetChar( FT_Stream  stream );
   450   FT_Stream_GetChar( FT_Stream  stream );
   426 
   451