2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ftstream.c
|
|
|
|
*
|
|
|
|
* I/O stream support (body).
|
|
|
|
*
|
2019-02-23 10:07:09 +01:00
|
|
|
* Copyright (C) 2000-2019 by
|
2018-06-03 09:01:17 +02:00
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used,
|
|
|
|
* modified, and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_INTERNAL_STREAM_H
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-06-02 23:31:32 +02:00
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* The macro FT_COMPONENT is used in trace mode. It is an implicit
|
|
|
|
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
|
|
|
|
* messages during execution.
|
|
|
|
*/
|
1999-12-17 00:11:37 +01:00
|
|
|
#undef FT_COMPONENT
|
2018-08-15 18:13:17 +02:00
|
|
|
#define FT_COMPONENT stream
|
1999-12-17 00:11:37 +01:00
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( void )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_OpenMemory( FT_Stream stream,
|
|
|
|
const FT_Byte* base,
|
|
|
|
FT_ULong size )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
stream->base = (FT_Byte*) base;
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->size = size;
|
|
|
|
stream->pos = 0;
|
2015-04-11 05:45:11 +02:00
|
|
|
stream->cursor = NULL;
|
|
|
|
stream->read = NULL;
|
|
|
|
stream->close = NULL;
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_BASE_DEF( void )
|
|
|
|
FT_Stream_Close( FT_Stream stream )
|
|
|
|
{
|
|
|
|
if ( stream && stream->close )
|
|
|
|
stream->close( stream );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Seek( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_ULong pos )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
if ( stream->read )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read( stream, pos, 0, 0 ) )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_ERROR(( "FT_Stream_Seek:"
|
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
2002-03-30 14:16:35 +01:00
|
|
|
pos, stream->size ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* note that seeking to the first position after the file is valid */
|
2000-06-02 16:30:38 +02:00
|
|
|
else if ( pos > stream->size )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_ERROR(( "FT_Stream_Seek:"
|
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
2002-03-30 14:16:35 +01:00
|
|
|
pos, stream->size ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2009-08-03 19:55:58 +02:00
|
|
|
if ( !error )
|
|
|
|
stream->pos = pos;
|
|
|
|
|
2000-01-10 18:19:45 +01:00
|
|
|
return error;
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Skip( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Long distance )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2008-06-09 22:49:29 +02:00
|
|
|
if ( distance < 0 )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Stream_Operation );
|
2008-06-09 22:49:29 +02:00
|
|
|
|
2015-02-16 19:35:16 +01:00
|
|
|
return FT_Stream_Seek( stream, stream->pos + (FT_ULong)distance );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_BASE_DEF( FT_ULong )
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Stream_Pos( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
return stream->pos;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Byte* buffer,
|
|
|
|
FT_ULong count )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2002-03-20 11:49:31 +01:00
|
|
|
return FT_Stream_ReadAt( stream, stream->pos, buffer, count );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ReadAt( FT_Stream stream,
|
|
|
|
FT_ULong pos,
|
|
|
|
FT_Byte* buffer,
|
|
|
|
FT_ULong count )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
FT_ULong read_bytes;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
if ( pos >= stream->size )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_ERROR(( "FT_Stream_ReadAt:"
|
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
2002-03-30 14:16:35 +01:00
|
|
|
pos, stream->size ));
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Stream_Operation );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read )
|
1999-12-17 00:11:37 +01:00
|
|
|
read_bytes = stream->read( stream, pos, buffer, count );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
read_bytes = stream->size - pos;
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( read_bytes > count )
|
1999-12-17 00:11:37 +01:00
|
|
|
read_bytes = count;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_MEM_COPY( buffer, stream->base + pos, read_bytes );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->pos = pos + read_bytes;
|
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( read_bytes < count )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_ERROR(( "FT_Stream_ReadAt:"
|
|
|
|
" invalid read; expected %lu bytes, got %lu\n",
|
2002-03-30 14:16:35 +01:00
|
|
|
count, read_bytes ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2005-03-15 19:18:57 +01:00
|
|
|
FT_BASE_DEF( FT_ULong )
|
|
|
|
FT_Stream_TryRead( FT_Stream stream,
|
|
|
|
FT_Byte* buffer,
|
|
|
|
FT_ULong count )
|
|
|
|
{
|
|
|
|
FT_ULong read_bytes = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if ( stream->pos >= stream->size )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
if ( stream->read )
|
|
|
|
read_bytes = stream->read( stream, stream->pos, buffer, count );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
read_bytes = stream->size - stream->pos;
|
|
|
|
if ( read_bytes > count )
|
|
|
|
read_bytes = count;
|
|
|
|
|
|
|
|
FT_MEM_COPY( buffer, stream->base + stream->pos, read_bytes );
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->pos += read_bytes;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return read_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ExtractFrame( FT_Stream stream,
|
|
|
|
FT_ULong count,
|
|
|
|
FT_Byte** pbytes )
|
2000-05-27 00:13:17 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2000-06-03 08:03:11 +02:00
|
|
|
|
2002-03-20 11:49:31 +01:00
|
|
|
error = FT_Stream_EnterFrame( stream, count );
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( !error )
|
2000-05-27 00:13:17 +02:00
|
|
|
{
|
|
|
|
*pbytes = (FT_Byte*)stream->cursor;
|
2000-06-03 08:03:11 +02:00
|
|
|
|
2002-03-20 11:49:31 +01:00
|
|
|
/* equivalent to FT_Stream_ExitFrame(), with no memory block release */
|
2015-04-11 05:45:11 +02:00
|
|
|
stream->cursor = NULL;
|
|
|
|
stream->limit = NULL;
|
2000-05-27 00:13:17 +02:00
|
|
|
}
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2000-05-27 00:13:17 +02:00
|
|
|
return error;
|
2000-06-03 08:03:11 +02:00
|
|
|
}
|
2000-05-27 00:13:17 +02:00
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( void )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ReleaseFrame( FT_Stream stream,
|
|
|
|
FT_Byte** pbytes )
|
2000-05-27 00:13:17 +02:00
|
|
|
{
|
2009-06-07 13:09:21 +02:00
|
|
|
if ( stream && stream->read )
|
2000-05-27 00:13:17 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory = stream->memory;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2018-07-21 07:38:13 +02:00
|
|
|
|
2006-05-02 12:21:28 +02:00
|
|
|
#ifdef FT_DEBUG_MEMORY
|
|
|
|
ft_mem_free( memory, *pbytes );
|
|
|
|
#else
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( *pbytes );
|
2006-05-02 12:21:28 +02:00
|
|
|
#endif
|
2000-05-27 00:13:17 +02:00
|
|
|
}
|
2018-08-26 06:39:43 +02:00
|
|
|
|
2015-04-11 05:45:11 +02:00
|
|
|
*pbytes = NULL;
|
2000-05-27 00:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_EnterFrame( FT_Stream stream,
|
|
|
|
FT_ULong count )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
FT_ULong read_bytes;
|
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2018-08-26 12:03:33 +02:00
|
|
|
FT_TRACE7(( "FT_Stream_EnterFrame: %ld bytes\n", count ));
|
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
/* check for nested frame access */
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream && stream->cursor == 0 );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
/* allocate the frame in memory */
|
|
|
|
FT_Memory memory = stream->memory;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2010-06-26 09:24:08 +02:00
|
|
|
|
|
|
|
/* simple sanity check */
|
|
|
|
if ( count > stream->size )
|
|
|
|
{
|
|
|
|
FT_ERROR(( "FT_Stream_EnterFrame:"
|
|
|
|
" frame size (%lu) larger than stream size (%lu)\n",
|
|
|
|
count, stream->size ));
|
|
|
|
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
2010-06-26 09:24:08 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
2006-05-02 12:21:28 +02:00
|
|
|
#ifdef FT_DEBUG_MEMORY
|
|
|
|
/* assume _ft_debug_file and _ft_debug_lineno are already set */
|
2015-02-16 19:35:16 +01:00
|
|
|
stream->base = (unsigned char*)ft_mem_qalloc( memory,
|
|
|
|
(FT_Long)count,
|
|
|
|
&error );
|
2006-05-02 12:21:28 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
#else
|
2004-06-23 17:44:03 +02:00
|
|
|
if ( FT_QALLOC( stream->base, count ) )
|
1999-12-17 00:11:37 +01:00
|
|
|
goto Exit;
|
2006-05-02 12:21:28 +02:00
|
|
|
#endif
|
1999-12-17 00:11:37 +01:00
|
|
|
/* read it */
|
|
|
|
read_bytes = stream->read( stream, stream->pos,
|
2000-01-10 18:19:45 +01:00
|
|
|
stream->base, count );
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( read_bytes < count )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_ERROR(( "FT_Stream_EnterFrame:"
|
|
|
|
" invalid read; expected %lu bytes, got %lu\n",
|
1999-12-17 00:11:37 +01:00
|
|
|
count, read_bytes ));
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( stream->base );
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2018-08-26 06:39:43 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->cursor = stream->base;
|
|
|
|
stream->limit = stream->cursor + count;
|
|
|
|
stream->pos += read_bytes;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* check current and new position */
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->pos >= stream->size ||
|
2010-08-04 15:54:55 +02:00
|
|
|
stream->size - stream->pos < count )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_ERROR(( "FT_Stream_EnterFrame:"
|
|
|
|
" invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->pos, count, stream->size ));
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
1999-12-17 00:11:37 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
/* set cursor */
|
2000-01-10 18:19:45 +01:00
|
|
|
stream->cursor = stream->base + stream->pos;
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->limit = stream->cursor + count;
|
|
|
|
stream->pos += count;
|
|
|
|
}
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( void )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ExitFrame( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-05-02 12:51:04 +02:00
|
|
|
/* IMPORTANT: The assertion stream->cursor != 0 was removed, given */
|
|
|
|
/* that it is possible to access a frame of length 0 in */
|
|
|
|
/* some weird fonts (usually, when accessing an array of */
|
2000-06-02 16:30:38 +02:00
|
|
|
/* 0 records, like in some strange kern tables). */
|
2000-05-02 12:51:04 +02:00
|
|
|
/* */
|
|
|
|
/* In this case, the loader code handles the 0-length table */
|
2000-06-02 16:30:38 +02:00
|
|
|
/* gracefully; however, stream.cursor is really set to 0 by the */
|
2002-03-30 14:16:35 +01:00
|
|
|
/* FT_Stream_EnterFrame() call, and this is not an error. */
|
2018-08-26 12:03:33 +02:00
|
|
|
|
|
|
|
FT_TRACE7(( "FT_Stream_ExitFrame\n" ));
|
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
FT_Memory memory = stream->memory;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2018-08-26 06:39:43 +02:00
|
|
|
|
2006-05-02 12:21:28 +02:00
|
|
|
#ifdef FT_DEBUG_MEMORY
|
|
|
|
ft_mem_free( memory, stream->base );
|
|
|
|
stream->base = NULL;
|
|
|
|
#else
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( stream->base );
|
2006-05-02 12:21:28 +02:00
|
|
|
#endif
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2018-08-26 06:39:43 +02:00
|
|
|
|
2015-04-11 05:45:11 +02:00
|
|
|
stream->cursor = NULL;
|
|
|
|
stream->limit = NULL;
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Char )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_GetChar( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
FT_Char result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream && stream->cursor );
|
1999-12-17 00:11:37 +01:00
|
|
|
|
|
|
|
result = 0;
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->cursor < stream->limit )
|
2015-02-16 19:35:16 +01:00
|
|
|
result = (FT_Char)*stream->cursor++;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return result;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_UShort )
|
|
|
|
FT_Stream_GetUShort( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Byte* p;
|
|
|
|
FT_UShort result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream && stream->cursor );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
result = 0;
|
|
|
|
p = stream->cursor;
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( p + 1 < stream->limit )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_USHORT( p );
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->cursor = p;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return result;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_UShort )
|
|
|
|
FT_Stream_GetUShortLE( FT_Stream stream )
|
2000-07-07 21:47:34 +02:00
|
|
|
{
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Byte* p;
|
|
|
|
FT_UShort result;
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream && stream->cursor );
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
result = 0;
|
|
|
|
p = stream->cursor;
|
|
|
|
if ( p + 1 < stream->limit )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_USHORT_LE( p );
|
2000-07-07 21:47:34 +02:00
|
|
|
stream->cursor = p;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_ULong )
|
|
|
|
FT_Stream_GetUOffset( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte* p;
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_ULong result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream && stream->cursor );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
result = 0;
|
|
|
|
p = stream->cursor;
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( p + 2 < stream->limit )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_UOFF3( p );
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->cursor = p;
|
|
|
|
return result;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_ULong )
|
|
|
|
FT_Stream_GetULong( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte* p;
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_ULong result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream && stream->cursor );
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-01-10 18:19:45 +01:00
|
|
|
result = 0;
|
1999-12-17 00:11:37 +01:00
|
|
|
p = stream->cursor;
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( p + 3 < stream->limit )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_ULONG( p );
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->cursor = p;
|
|
|
|
return result;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_ULong )
|
|
|
|
FT_Stream_GetULongLE( FT_Stream stream )
|
2000-07-07 21:47:34 +02:00
|
|
|
{
|
|
|
|
FT_Byte* p;
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_ULong result;
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream && stream->cursor );
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
result = 0;
|
|
|
|
p = stream->cursor;
|
|
|
|
if ( p + 3 < stream->limit )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_ULONG_LE( p );
|
2000-07-07 21:47:34 +02:00
|
|
|
stream->cursor = p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Char )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ReadChar( FT_Stream stream,
|
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte result = 0;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
*error = FT_Err_Ok;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
if ( stream->read( stream, stream->pos, &result, 1L ) != 1L )
|
|
|
|
goto Fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->pos < stream->size )
|
2000-01-17 12:21:49 +01:00
|
|
|
result = stream->base[stream->pos];
|
1999-12-17 00:11:37 +01:00
|
|
|
else
|
|
|
|
goto Fail;
|
|
|
|
}
|
2000-01-17 12:21:49 +01:00
|
|
|
stream->pos++;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2015-02-16 19:35:16 +01:00
|
|
|
return (FT_Char)result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
Fail:
|
2013-03-14 10:27:35 +01:00
|
|
|
*error = FT_THROW( Invalid_Stream_Operation );
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_ERROR(( "FT_Stream_ReadChar:"
|
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
2002-03-30 14:16:35 +01:00
|
|
|
stream->pos, stream->size ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_UShort )
|
|
|
|
FT_Stream_ReadUShort( FT_Stream stream,
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Byte reads[2];
|
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_UShort result = 0;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
*error = FT_Err_Ok;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->pos + 1 < stream->size )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
|
1999-12-17 00:11:37 +01:00
|
|
|
goto Fail;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
p = reads;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p = stream->base + stream->pos;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( p )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_USHORT( p );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-06-02 16:30:38 +02:00
|
|
|
else
|
|
|
|
goto Fail;
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-01-17 12:21:49 +01:00
|
|
|
stream->pos += 2;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
Fail:
|
2013-03-14 10:27:35 +01:00
|
|
|
*error = FT_THROW( Invalid_Stream_Operation );
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_ERROR(( "FT_Stream_ReadUShort:"
|
2009-06-26 06:15:41 +02:00
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->pos, stream->size ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_UShort )
|
|
|
|
FT_Stream_ReadUShortLE( FT_Stream stream,
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Error* error )
|
2000-07-07 21:47:34 +02:00
|
|
|
{
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Byte reads[2];
|
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_UShort result = 0;
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream );
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
*error = FT_Err_Ok;
|
|
|
|
|
|
|
|
if ( stream->pos + 1 < stream->size )
|
|
|
|
{
|
|
|
|
if ( stream->read )
|
|
|
|
{
|
|
|
|
if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
p = reads;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p = stream->base + stream->pos;
|
|
|
|
|
|
|
|
if ( p )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_USHORT_LE( p );
|
2000-07-07 21:47:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
stream->pos += 2;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Fail:
|
2013-03-14 10:27:35 +01:00
|
|
|
*error = FT_THROW( Invalid_Stream_Operation );
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_ERROR(( "FT_Stream_ReadUShortLE:"
|
2009-06-26 06:15:41 +02:00
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
2000-07-07 21:47:34 +02:00
|
|
|
stream->pos, stream->size ));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_ULong )
|
|
|
|
FT_Stream_ReadUOffset( FT_Stream stream,
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte reads[3];
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_ULong result = 0;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
*error = FT_Err_Ok;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->pos + 2 < stream->size )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
if (stream->read( stream, stream->pos, reads, 3L ) != 3L )
|
|
|
|
goto Fail;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
p = reads;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p = stream->base + stream->pos;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( p )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_UOFF3( p );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-06-02 16:30:38 +02:00
|
|
|
else
|
|
|
|
goto Fail;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-01-17 12:21:49 +01:00
|
|
|
stream->pos += 3;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
Fail:
|
2013-03-14 10:27:35 +01:00
|
|
|
*error = FT_THROW( Invalid_Stream_Operation );
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_ERROR(( "FT_Stream_ReadUOffset:"
|
2009-06-26 06:15:41 +02:00
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
2002-03-30 14:16:35 +01:00
|
|
|
stream->pos, stream->size ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_ULong )
|
|
|
|
FT_Stream_ReadULong( FT_Stream stream,
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_Byte reads[4];
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_ULong result = 0;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
*error = FT_Err_Ok;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->pos + 3 < stream->size )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
|
1999-12-17 00:11:37 +01:00
|
|
|
goto Fail;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
p = reads;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p = stream->base + stream->pos;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( p )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_ULONG( p );
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-06-02 16:30:38 +02:00
|
|
|
else
|
|
|
|
goto Fail;
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-01-17 12:21:49 +01:00
|
|
|
stream->pos += 4;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
Fail:
|
2013-03-14 10:27:35 +01:00
|
|
|
*error = FT_THROW( Invalid_Stream_Operation );
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_ERROR(( "FT_Stream_ReadULong:"
|
2009-06-26 06:15:41 +02:00
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
|
|
|
stream->pos, stream->size ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_BASE_DEF( FT_ULong )
|
|
|
|
FT_Stream_ReadULongLE( FT_Stream stream,
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Error* error )
|
2000-07-07 21:47:34 +02:00
|
|
|
{
|
|
|
|
FT_Byte reads[4];
|
2015-02-16 19:35:16 +01:00
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_ULong result = 0;
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
|
2002-02-21 12:48:48 +01:00
|
|
|
FT_ASSERT( stream );
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
*error = FT_Err_Ok;
|
|
|
|
|
|
|
|
if ( stream->pos + 3 < stream->size )
|
|
|
|
{
|
|
|
|
if ( stream->read )
|
|
|
|
{
|
|
|
|
if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
p = reads;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p = stream->base + stream->pos;
|
|
|
|
|
|
|
|
if ( p )
|
2011-04-12 09:26:43 +02:00
|
|
|
result = FT_NEXT_ULONG_LE( p );
|
2000-07-07 21:47:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
stream->pos += 4;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Fail:
|
2013-03-14 10:27:35 +01:00
|
|
|
*error = FT_THROW( Invalid_Stream_Operation );
|
2011-04-12 09:26:43 +02:00
|
|
|
FT_ERROR(( "FT_Stream_ReadULongLE:"
|
2009-06-26 06:15:41 +02:00
|
|
|
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
|
|
|
stream->pos, stream->size ));
|
2000-07-07 21:47:34 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ReadFields( FT_Stream stream,
|
|
|
|
const FT_Frame_Field* fields,
|
|
|
|
void* structure )
|
2000-02-13 14:36:53 +01:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Bool frame_accessed = 0;
|
2008-11-25 06:44:41 +01:00
|
|
|
FT_Byte* cursor;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2013-05-04 15:26:24 +02:00
|
|
|
|
2014-11-25 11:26:14 +01:00
|
|
|
if ( !fields )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Argument );
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2014-11-25 11:26:14 +01:00
|
|
|
if ( !stream )
|
|
|
|
return FT_THROW( Invalid_Stream_Handle );
|
|
|
|
|
2008-11-25 06:44:41 +01:00
|
|
|
cursor = stream->cursor;
|
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
error = FT_Err_Ok;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
FT_ULong value;
|
|
|
|
FT_Int sign_shift;
|
|
|
|
FT_Byte* p;
|
2000-05-17 01:44:38 +02:00
|
|
|
|
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
switch ( fields->value )
|
|
|
|
{
|
|
|
|
case ft_frame_start: /* access a new frame */
|
2002-03-20 11:49:31 +01:00
|
|
|
error = FT_Stream_EnterFrame( stream, fields->offset );
|
2000-06-07 02:00:08 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2000-06-07 02:00:08 +02:00
|
|
|
frame_accessed = 1;
|
2000-08-29 18:03:28 +02:00
|
|
|
cursor = stream->cursor;
|
2000-06-07 02:00:08 +02:00
|
|
|
fields++;
|
|
|
|
continue; /* loop! */
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2000-07-03 17:00:49 +02:00
|
|
|
case ft_frame_bytes: /* read a byte sequence */
|
2000-07-04 20:12:13 +02:00
|
|
|
case ft_frame_skip: /* skip some bytes */
|
2000-07-03 17:00:49 +02:00
|
|
|
{
|
2000-07-31 20:59:02 +02:00
|
|
|
FT_UInt len = fields->size;
|
2000-07-05 06:32:02 +02:00
|
|
|
|
|
|
|
|
2000-09-29 08:41:56 +02:00
|
|
|
if ( cursor + len > stream->limit )
|
2000-07-04 20:12:13 +02:00
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
2000-07-04 20:12:13 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
2000-07-05 06:32:02 +02:00
|
|
|
|
|
|
|
if ( fields->value == ft_frame_bytes )
|
2000-07-04 20:12:13 +02:00
|
|
|
{
|
|
|
|
p = (FT_Byte*)structure + fields->offset;
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_MEM_COPY( p, cursor, len );
|
2000-07-04 20:12:13 +02:00
|
|
|
}
|
2000-09-29 08:41:56 +02:00
|
|
|
cursor += len;
|
2000-07-03 17:00:49 +02:00
|
|
|
fields++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
case ft_frame_byte:
|
|
|
|
case ft_frame_schar: /* read a single byte */
|
2013-05-04 15:26:24 +02:00
|
|
|
value = FT_NEXT_BYTE( cursor );
|
2000-06-07 02:00:08 +02:00
|
|
|
sign_shift = 24;
|
|
|
|
break;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
case ft_frame_short_be:
|
|
|
|
case ft_frame_ushort_be: /* read a 2-byte big-endian short */
|
2016-02-15 12:54:40 +01:00
|
|
|
value = FT_NEXT_USHORT( cursor );
|
2000-06-07 02:00:08 +02:00
|
|
|
sign_shift = 16;
|
|
|
|
break;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
case ft_frame_short_le:
|
|
|
|
case ft_frame_ushort_le: /* read a 2-byte little-endian short */
|
2013-05-04 15:26:24 +02:00
|
|
|
value = FT_NEXT_USHORT_LE( cursor );
|
2000-07-31 20:59:02 +02:00
|
|
|
sign_shift = 16;
|
|
|
|
break;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
case ft_frame_long_be:
|
|
|
|
case ft_frame_ulong_be: /* read a 4-byte big-endian long */
|
2013-05-04 15:26:24 +02:00
|
|
|
value = FT_NEXT_ULONG( cursor );
|
2000-06-07 02:00:08 +02:00
|
|
|
sign_shift = 0;
|
|
|
|
break;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
case ft_frame_long_le:
|
|
|
|
case ft_frame_ulong_le: /* read a 4-byte little-endian long */
|
2013-05-04 15:26:24 +02:00
|
|
|
value = FT_NEXT_ULONG_LE( cursor );
|
2000-07-31 20:59:02 +02:00
|
|
|
sign_shift = 0;
|
|
|
|
break;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
case ft_frame_off3_be:
|
|
|
|
case ft_frame_uoff3_be: /* read a 3-byte big-endian long */
|
2013-05-04 15:26:24 +02:00
|
|
|
value = FT_NEXT_UOFF3( cursor );
|
2000-06-07 02:00:08 +02:00
|
|
|
sign_shift = 8;
|
|
|
|
break;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
case ft_frame_off3_le:
|
|
|
|
case ft_frame_uoff3_le: /* read a 3-byte little-endian long */
|
2013-05-04 15:26:24 +02:00
|
|
|
value = FT_NEXT_UOFF3_LE( cursor );
|
2000-07-31 20:59:02 +02:00
|
|
|
sign_shift = 8;
|
|
|
|
break;
|
2000-02-13 14:36:53 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
default:
|
|
|
|
/* otherwise, exit the loop */
|
2000-08-29 18:03:28 +02:00
|
|
|
stream->cursor = cursor;
|
2000-06-02 16:30:38 +02:00
|
|
|
goto Exit;
|
2000-02-13 14:36:53 +01:00
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
/* now, compute the signed value is necessary */
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( fields->value & FT_FRAME_OP_SIGNED )
|
2000-07-04 20:12:13 +02:00
|
|
|
value = (FT_ULong)( (FT_Int32)( value << sign_shift ) >> sign_shift );
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
/* finally, store the value in the object */
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
p = (FT_Byte*)structure + fields->offset;
|
2000-06-02 16:30:38 +02:00
|
|
|
switch ( fields->size )
|
2000-02-13 14:36:53 +01:00
|
|
|
{
|
2013-05-04 15:26:24 +02:00
|
|
|
case ( 8 / FT_CHAR_BIT ):
|
2000-06-02 16:30:38 +02:00
|
|
|
*(FT_Byte*)p = (FT_Byte)value;
|
|
|
|
break;
|
|
|
|
|
2013-05-04 15:26:24 +02:00
|
|
|
case ( 16 / FT_CHAR_BIT ):
|
2000-06-02 16:30:38 +02:00
|
|
|
*(FT_UShort*)p = (FT_UShort)value;
|
|
|
|
break;
|
|
|
|
|
2013-05-04 15:26:24 +02:00
|
|
|
case ( 32 / FT_CHAR_BIT ):
|
2000-07-04 20:12:13 +02:00
|
|
|
*(FT_UInt32*)p = (FT_UInt32)value;
|
2000-06-29 05:14:25 +02:00
|
|
|
break;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2000-07-05 06:32:02 +02:00
|
|
|
default: /* for 64-bit systems */
|
2000-06-29 05:14:25 +02:00
|
|
|
*(FT_ULong*)p = (FT_ULong)value;
|
2000-02-13 14:36:53 +01:00
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
/* go to next field */
|
|
|
|
fields++;
|
|
|
|
}
|
2000-06-02 16:30:38 +02:00
|
|
|
while ( 1 );
|
2000-02-13 14:36:53 +01:00
|
|
|
|
|
|
|
Exit:
|
|
|
|
/* close the frame if it was opened by this read */
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( frame_accessed )
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ExitFrame( stream );
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
/* END */
|