misc/libfreetype/src/base/ftstream.c
author sheepluva
Thu, 03 May 2012 14:21:53 +0200
changeset 7017 19a434fc91fc
parent 5172 88f2e05288ba
permissions -rw-r--r--
visually indicate when map preview generation is in progress.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftstream.c                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    I/O stream support (body).                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2000-2002, 2004-2006, 2008-2011 by                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
#define FT_COMPONENT  trace_stream
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  FT_Stream_OpenMemory( FT_Stream       stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
                        const FT_Byte*  base,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
                        FT_ULong        size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
    stream->base   = (FT_Byte*) base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
    stream->size   = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    stream->pos    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    stream->cursor = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
    stream->read   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
    stream->close  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  FT_Stream_Close( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    if ( stream && stream->close )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
      stream->close( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  FT_Stream_Seek( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
                  FT_ULong   pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
      if ( stream->read( stream, pos, 0, 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
        FT_ERROR(( "FT_Stream_Seek:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
                   " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
                   pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
        error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    /* note that seeking to the first position after the file is valid */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    else if ( pos > stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      FT_ERROR(( "FT_Stream_Seek:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
                 " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
                 pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
      stream->pos = pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  FT_Stream_Skip( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
                  FT_Long    distance )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    if ( distance < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
      return FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  FT_BASE_DEF( FT_Long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  FT_Stream_Pos( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    return stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
  FT_Stream_Read( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
                  FT_Byte*   buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
                  FT_ULong   count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    return FT_Stream_ReadAt( stream, stream->pos, buffer, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  FT_Stream_ReadAt( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
                    FT_ULong   pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
                    FT_Byte*   buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
                    FT_ULong   count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    FT_ULong  read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    if ( pos >= stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
      FT_ERROR(( "FT_Stream_ReadAt:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
                 " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
                 pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      return FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
      read_bytes = stream->read( stream, pos, buffer, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
      read_bytes = stream->size - pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      if ( read_bytes > count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
        read_bytes = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
      FT_MEM_COPY( buffer, stream->base + pos, read_bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    stream->pos = pos + read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    if ( read_bytes < count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
      FT_ERROR(( "FT_Stream_ReadAt:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
                 " invalid read; expected %lu bytes, got %lu\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
                 count, read_bytes ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
      error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  FT_BASE_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
  FT_Stream_TryRead( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
                     FT_Byte*   buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
                     FT_ULong   count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
    FT_ULong  read_bytes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    if ( stream->pos >= stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      read_bytes = stream->read( stream, stream->pos, buffer, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
      read_bytes = stream->size - stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      if ( read_bytes > count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
        read_bytes = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
      FT_MEM_COPY( buffer, stream->base + stream->pos, read_bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    stream->pos += read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
    return read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
  FT_Stream_ExtractFrame( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
                          FT_ULong   count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
                          FT_Byte**  pbytes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    error = FT_Stream_EnterFrame( stream, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      *pbytes = (FT_Byte*)stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
      /* equivalent to FT_Stream_ExitFrame(), with no memory block release */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      stream->cursor = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      stream->limit  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
  FT_Stream_ReleaseFrame( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
                          FT_Byte**  pbytes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    if ( stream && stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
      FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
      ft_mem_free( memory, *pbytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
      *pbytes = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      FT_FREE( *pbytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    *pbytes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
  FT_Stream_EnterFrame( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
                        FT_ULong   count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
    FT_Error  error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    FT_ULong  read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
    /* check for nested frame access */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    FT_ASSERT( stream && stream->cursor == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
    if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
      /* allocate the frame in memory */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
      FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
      /* simple sanity check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
      if ( count > stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
        FT_ERROR(( "FT_Stream_EnterFrame:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
                   " frame size (%lu) larger than stream size (%lu)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
                   count, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
        error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      /* assume _ft_debug_file and _ft_debug_lineno are already set */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
      stream->base = (unsigned char*)ft_mem_qalloc( memory, count, &error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
      if ( FT_QALLOC( stream->base, count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
      /* read it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      read_bytes = stream->read( stream, stream->pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
                                 stream->base, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      if ( read_bytes < count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
        FT_ERROR(( "FT_Stream_EnterFrame:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
                   " invalid read; expected %lu bytes, got %lu\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
                   count, read_bytes ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
        FT_FREE( stream->base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
        error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
      stream->cursor = stream->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
      stream->limit  = stream->cursor + count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
      stream->pos   += read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
      /* check current and new position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
      if ( stream->pos >= stream->size        ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
           stream->size - stream->pos < count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
        FT_ERROR(( "FT_Stream_EnterFrame:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
                   " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
                   stream->pos, count, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
        error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
      /* set cursor */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      stream->cursor = stream->base + stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
      stream->limit  = stream->cursor + count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
      stream->pos   += count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
  FT_Stream_ExitFrame( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    /* IMPORTANT: The assertion stream->cursor != 0 was removed, given    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    /*            that it is possible to access a frame of length 0 in    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    /*            some weird fonts (usually, when accessing an array of   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    /*            0 records, like in some strange kern tables).           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    /*                                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    /*  In this case, the loader code handles the 0-length table          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
    /*  gracefully; however, stream.cursor is really set to 0 by the      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    /*  FT_Stream_EnterFrame() call, and this is not an error.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    /*                                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
    FT_ASSERT( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
      FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
      ft_mem_free( memory, stream->base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
      stream->base = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      FT_FREE( stream->base );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
    stream->cursor = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
    stream->limit  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
  FT_BASE_DEF( FT_Char )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
  FT_Stream_GetChar( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
    FT_Char  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    FT_ASSERT( stream && stream->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    if ( stream->cursor < stream->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
      result = *stream->cursor++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
  FT_BASE_DEF( FT_UShort )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  FT_Stream_GetUShort( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
    FT_Short  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    FT_ASSERT( stream && stream->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    result         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    p              = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    if ( p + 1 < stream->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      result       = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    stream->cursor = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
  FT_BASE_DEF( FT_UShort )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
  FT_Stream_GetUShortLE( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    FT_Short  result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    FT_ASSERT( stream && stream->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    result         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
    p              = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
    if ( p + 1 < stream->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
      result       = FT_NEXT_USHORT_LE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
    stream->cursor = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
  FT_BASE_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
  FT_Stream_GetUOffset( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    FT_Long   result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
    FT_ASSERT( stream && stream->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    result         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    p              = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    if ( p + 2 < stream->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
      result       = FT_NEXT_UOFF3( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
    stream->cursor = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
  FT_BASE_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  FT_Stream_GetULong( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
    FT_Long   result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    FT_ASSERT( stream && stream->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    result         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    p              = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    if ( p + 3 < stream->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      result       = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
    stream->cursor = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
  FT_BASE_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
  FT_Stream_GetULongLE( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
    FT_Long   result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    FT_ASSERT( stream && stream->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
    result         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
    p              = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
    if ( p + 3 < stream->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
      result       = FT_NEXT_ULONG_LE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
    stream->cursor = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
  FT_BASE_DEF( FT_Char )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
  FT_Stream_ReadChar( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
                      FT_Error*  error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
    FT_Byte  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
    FT_ASSERT( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    *error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
    if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
      if ( stream->read( stream, stream->pos, &result, 1L ) != 1L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
      if ( stream->pos < stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
        result = stream->base[stream->pos];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
    stream->pos++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
    *error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    FT_ERROR(( "FT_Stream_ReadChar:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
               " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
               stream->pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
  FT_BASE_DEF( FT_UShort )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
  FT_Stream_ReadUShort( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
                       FT_Error*  error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
    FT_Byte   reads[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    FT_Byte*  p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    FT_Short  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
    FT_ASSERT( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
    *error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    if ( stream->pos + 1 < stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
      if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
        if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
        p = reads;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
        p = stream->base + stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
      if ( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
        result = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    stream->pos += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
    *error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
    FT_ERROR(( "FT_Stream_ReadUShort:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
               " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
               stream->pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
  FT_BASE_DEF( FT_UShort )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
  FT_Stream_ReadUShortLE( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
                         FT_Error*  error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    FT_Byte   reads[2];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    FT_Byte*  p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    FT_Short  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    FT_ASSERT( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    *error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    if ( stream->pos + 1 < stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
      if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
        if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
        p = reads;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
        p = stream->base + stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      if ( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
        result = FT_NEXT_USHORT_LE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
    stream->pos += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
    *error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
    FT_ERROR(( "FT_Stream_ReadUShortLE:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
               " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
               stream->pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
  FT_BASE_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
  FT_Stream_ReadUOffset( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
                        FT_Error*  error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
    FT_Byte   reads[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    FT_Byte*  p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
    FT_Long   result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    FT_ASSERT( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    *error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
    if ( stream->pos + 2 < stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
      if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
        if (stream->read( stream, stream->pos, reads, 3L ) != 3L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
        p = reads;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
        p = stream->base + stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
      if ( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
        result = FT_NEXT_UOFF3( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
    stream->pos += 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
    *error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
    FT_ERROR(( "FT_Stream_ReadUOffset:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
               " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
               stream->pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
  FT_BASE_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
  FT_Stream_ReadULong( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
                      FT_Error*  error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
    FT_Byte   reads[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
    FT_Byte*  p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    FT_Long   result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
    FT_ASSERT( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    *error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
    if ( stream->pos + 3 < stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
      if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
        if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
        p = reads;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
        p = stream->base + stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
      if ( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
        result = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
    stream->pos += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
    *error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
    FT_ERROR(( "FT_Stream_ReadULong:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
               " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
               stream->pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
  FT_BASE_DEF( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
  FT_Stream_ReadULongLE( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
                        FT_Error*  error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
    FT_Byte   reads[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    FT_Byte*  p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
    FT_Long   result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    FT_ASSERT( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
    *error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
    if ( stream->pos + 3 < stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
      if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
        if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
        p = reads;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
        p = stream->base + stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
      if ( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
        result = FT_NEXT_ULONG_LE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
    stream->pos += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    *error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
    FT_ERROR(( "FT_Stream_ReadULongLE:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
               " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
               stream->pos, stream->size ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
  FT_Stream_ReadFields( FT_Stream              stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
                        const FT_Frame_Field*  fields,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
                        void*                  structure )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
    FT_Bool   frame_accessed = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
    FT_Byte*  cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
    if ( !fields || !stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
      return FT_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
    cursor = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
    error = FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
    do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
      FT_ULong  value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
      FT_Int    sign_shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
      FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
      switch ( fields->value )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
      case ft_frame_start:  /* access a new frame */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
        error = FT_Stream_EnterFrame( stream, fields->offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
        frame_accessed = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
        cursor         = stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
        fields++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
        continue;  /* loop! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
      case ft_frame_bytes:  /* read a byte sequence */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
      case ft_frame_skip:   /* skip some bytes      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
          FT_UInt  len = fields->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
          if ( cursor + len > stream->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
            error = FT_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
          if ( fields->value == ft_frame_bytes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
            p = (FT_Byte*)structure + fields->offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
            FT_MEM_COPY( p, cursor, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
          cursor += len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
          fields++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
      case ft_frame_byte:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
      case ft_frame_schar:  /* read a single byte */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
        value = FT_NEXT_BYTE(cursor);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
        sign_shift = 24;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
      case ft_frame_short_be:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
      case ft_frame_ushort_be:  /* read a 2-byte big-endian short */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
        value = FT_NEXT_USHORT(cursor);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
        sign_shift = 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
      case ft_frame_short_le:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
      case ft_frame_ushort_le:  /* read a 2-byte little-endian short */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
        value = FT_NEXT_USHORT_LE(cursor);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
        sign_shift = 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
      case ft_frame_long_be:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
      case ft_frame_ulong_be:  /* read a 4-byte big-endian long */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
        value = FT_NEXT_ULONG(cursor);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
        sign_shift = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
      case ft_frame_long_le:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
      case ft_frame_ulong_le:  /* read a 4-byte little-endian long */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
        value = FT_NEXT_ULONG_LE(cursor);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
        sign_shift = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
      case ft_frame_off3_be:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
      case ft_frame_uoff3_be:  /* read a 3-byte big-endian long */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
        value = FT_NEXT_UOFF3(cursor);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
        sign_shift = 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
      case ft_frame_off3_le:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
      case ft_frame_uoff3_le:  /* read a 3-byte little-endian long */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
        value = FT_NEXT_UOFF3_LE(cursor);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
        sign_shift = 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
        /* otherwise, exit the loop */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
        stream->cursor = cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
      /* now, compute the signed value is necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
      if ( fields->value & FT_FRAME_OP_SIGNED )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
        value = (FT_ULong)( (FT_Int32)( value << sign_shift ) >> sign_shift );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
      /* finally, store the value in the object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
      p = (FT_Byte*)structure + fields->offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
      switch ( fields->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
      case (8 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
        *(FT_Byte*)p = (FT_Byte)value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
      case (16 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
        *(FT_UShort*)p = (FT_UShort)value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
      case (32 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
        *(FT_UInt32*)p = (FT_UInt32)value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
      default:  /* for 64-bit systems */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
        *(FT_ULong*)p = (FT_ULong)value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
      /* go to next field */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
      fields++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
    while ( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
    /* close the frame if it was opened by this read */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    if ( frame_accessed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
      FT_Stream_ExitFrame( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
/* END */