2000-06-02 16:30:38 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftstream.c */
|
|
|
|
/* */
|
|
|
|
/* I/O stream support (body). */
|
|
|
|
/* */
|
2001-06-28 19:49:10 +02:00
|
|
|
/* Copyright 2000-2001 by */
|
2000-06-02 16:30:38 +02:00
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
2000-06-05 07:26:15 +02:00
|
|
|
/* This file is part of the FreeType project, and may only be used, */
|
|
|
|
/* modified, and distributed under the terms of the FreeType project */
|
2000-06-02 16:30:38 +02:00
|
|
|
/* 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-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
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* 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
|
|
|
|
#define FT_COMPONENT trace_stream
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( void )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Open_Memory( 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;
|
|
|
|
stream->cursor = 0;
|
|
|
|
stream->read = 0;
|
|
|
|
stream->close = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
stream->close = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
FT_Error error;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->pos = pos;
|
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
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Seek:" ));
|
2000-06-02 16:30:38 +02:00
|
|
|
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
1999-12-17 00:11:37 +01:00
|
|
|
pos, stream->size ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
error = FT_Err_Ok;
|
|
|
|
}
|
|
|
|
/* 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
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Seek:" ));
|
2000-06-02 16:30:38 +02:00
|
|
|
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
1999-12-17 00:11:37 +01:00
|
|
|
pos, stream->size ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
else
|
|
|
|
error = FT_Err_Ok;
|
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
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) );
|
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_Long )
|
|
|
|
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-02-24 06:26:57 +01:00
|
|
|
return FT_Stream_Read_At( 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-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read_At( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
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
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Read_At:" ));
|
2000-06-02 16:30:38 +02:00
|
|
|
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
1999-12-17 00:11:37 +01:00
|
|
|
pos, stream->size ));
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return FT_Err_Invalid_Stream_Operation;
|
|
|
|
}
|
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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
MEM_Copy( buffer, stream->base + pos, read_bytes );
|
|
|
|
}
|
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
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Read_At:" ));
|
2000-06-06 22:41:48 +02:00
|
|
|
FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n",
|
1999-12-17 00:11:37 +01:00
|
|
|
count, read_bytes ));
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
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_Extract_Frame( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
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-02-24 06:26:57 +01:00
|
|
|
error = FT_Stream_Enter_Frame( 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-02-24 06:26:57 +01:00
|
|
|
/* equivalent to FT_Stream_Exit_Frame(), with no memory block release */
|
2000-05-27 00:13:17 +02:00
|
|
|
stream->cursor = 0;
|
|
|
|
stream->limit = 0;
|
|
|
|
}
|
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-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Release_Frame( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Byte** pbytes )
|
2000-05-27 00:13:17 +02:00
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
if ( stream->read )
|
2000-05-27 00:13:17 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory = stream->memory;
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
|
2000-05-27 00:13:17 +02:00
|
|
|
FREE( *pbytes );
|
|
|
|
}
|
|
|
|
*pbytes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Enter_Frame( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if ( ALLOC( stream->base, count ) )
|
|
|
|
goto Exit;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
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
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Enter_Frame:" ));
|
2000-06-06 22:41:48 +02:00
|
|
|
FT_ERROR(( " 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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
FREE( stream->base );
|
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
}
|
|
|
|
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 ||
|
|
|
|
stream->pos + count > stream->size )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Enter_Frame:" ));
|
2000-06-06 22:41:48 +02:00
|
|
|
FT_ERROR(( " 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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
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-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Exit_Frame( 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-02-24 06:26:57 +01:00
|
|
|
/* FT_Stream_Enter_Frame() call, and this is not an error. */
|
2000-05-02 12:51:04 +02:00
|
|
|
/* */
|
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
|
|
|
|
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
FREE( stream->base );
|
|
|
|
}
|
|
|
|
stream->cursor = 0;
|
|
|
|
stream->limit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Char )
|
* src/base/ftdbgmem.c (ft_mem_table_resize, ft_mem_table_new,
ft_mem_table_set, ft_mem_debug_alloc, ft_mem_debug_free,
ft_mem_debug_realloc, ft_mem_debug_done, FT_Alloc_Debug,
FT_Realloc_Debug, FT_Free_Debug): Fix compiler warnings.
* src/base/ftcalc.c (FT_MulFix): Ditto.
* src/cff/cffdrivr.c (cff_get_name_index): Ditto.
* src/cff/cffobjs.c (CFF_Size_Get_Global_Funcs, CFF_Size_Init,
CFF_GlyphSlot_Init): Ditto.
* src/cid/cidobjs.c (CID_GlyphSlot_Init,
CID_Size_Get_Globals_Funcs): Ditto.
* src/type1/t1objs.c (T1_Size_Get_Globals_Funcs, T1_GlyphSlot_Init):
Ditto.
* src/pshinter/pshmod.c (pshinter_interface): Use `static const'.
* src/winfonts/winfnt.c (FNT_Get_Next_Char): Remove unused
variables.
* include/freetype/internal/psaux.h (T1_Builder_Funcs): Renamed
to...
(T1_Builder_FuncsRec): This.
(T1_Builder_Funcs): New typedef.
(PSAux_Interface): Remove compiler warnings.
* src/psaux/psauxmod.c (t1_builder_funcs), src/psaux/psobjs.h
(t1_builder_funcs): Updated.
* src/pshinter/pshglob.h (PSH_Blue_Align): Replaced with ...
(PSH_BLUE_ALIGN_{NONE,TOP,BOT}): New defines.
(PSH_AlignmentRec): Updated.
* include/freetype/internal/ftstream.h (GET_Char, GET_Byte): Fix
typo.
* include/freetype/internal/ftgloadr.h (FT_SubGlyph): Ditto.
* src/base/ftstream (FT_Get_Char): Rename to...
(FT_Stream_Get_Char): This.
* src/base/ftnames.c (FT_Get_Sfnt_Name): s/index/idx/ -- `index' is
a built-in function in gcc, causing warning messages with gcc 3.0.
* src/autohint/ahglyph.c (ah_outline_load): Ditto.
* src/autohint/ahglobal.c (ah_hinter_compute_blues): Ditto.
* src/cache/ftcmanag.c (ftc_family_table_alloc,
ftc_family_table_free, FTC_Manager_Done, FTC_Manager_Register_Cache):
Ditto.
* src/cff/cffload.c (cff_new_index, cff_done_index,
cff_explicit_index, CFF_Access_Element, CFF_Forget_Element,
CFF_Get_Name, CFF_Get_String, CFF_Load_SubFont, CFF_Load_Font,
CFF_Done_Font): Ditto.
* src/psaux/psobjs.c (PS_Table_Add, PS_Parser_LoadField): Ditto.
* src/psaux/t1decode.c (T1_Decoder_Parse_Charstrings): Ditto.
* src/pshinter/pshrec.c (ps_mask_test_bit, ps_mask_clear_bit,
ps_mask_set_bit, ps_dimension_add_t1stem, ps_hints_t1stem3,
* src/pshinter/pshalgo1.c (psh1_hint_table_record,
psh1_hint_table_record_mask, psh1_hint_table_activate_mask): Ditto.
* src/pshinter/pshalgo2.c (psh2_hint_table_record,
psh2_hint_table_record_mask, psh2_hint_table_activate_mask): Ditto.
* src/sfnt/ttpost.c (Load_Format_20, Load_Format_25,
TT_Get_PS_Name): Ditto.
* src/truetype/ttgload.c (TT_Get_Metrics, Get_HMetrics,
load_truetype_glyph): Ditto.
* src/type1/t1load.c (parse_subrs, T1_Open_Face): Ditto.
* src/type1/t1afm.c (T1_Get_Kerning): Ditto.
* include/freetype/cache/ftcmanag.h (ftc_family_table_free): Ditto.
2002-03-07 22:59:59 +01:00
|
|
|
FT_Stream_Get_Char( 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 )
|
1999-12-17 00:11:37 +01:00
|
|
|
result = *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
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Short )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Get_Short( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte* p;
|
1999-12-17 00:11:37 +01:00
|
|
|
FT_Short 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 )
|
|
|
|
result = NEXT_Short( 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
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Short )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Get_ShortLE( FT_Stream stream )
|
2000-07-07 21:47:34 +02:00
|
|
|
{
|
|
|
|
FT_Byte* p;
|
|
|
|
FT_Short result;
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
result = NEXT_ShortLE( p );
|
|
|
|
stream->cursor = p;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Long )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Get_Offset( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte* p;
|
|
|
|
FT_Long 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 )
|
|
|
|
result = NEXT_Offset( 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
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Long )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Get_Long( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte* p;
|
|
|
|
FT_Long 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 )
|
|
|
|
result = NEXT_Long( p );
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->cursor = p;
|
|
|
|
return result;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Long )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Get_LongLE( FT_Stream stream )
|
2000-07-07 21:47:34 +02:00
|
|
|
{
|
|
|
|
FT_Byte* p;
|
|
|
|
FT_Long result;
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
result = NEXT_LongLE( p );
|
|
|
|
stream->cursor = p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Char )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read_Char( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
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
|
|
|
|
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:
|
|
|
|
*error = FT_Err_Invalid_Stream_Operation;
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Read_Char:" ));
|
2000-06-06 22:41:48 +02:00
|
|
|
FT_ERROR(( " 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
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Short )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read_Short( FT_Stream stream,
|
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte reads[2];
|
|
|
|
FT_Byte* p = 0;
|
2000-06-29 05:14:25 +02:00
|
|
|
FT_Short 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 )
|
|
|
|
result = NEXT_Short( 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:
|
|
|
|
*error = FT_Err_Invalid_Stream_Operation;
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Read_Short:" ));
|
2000-06-06 22:41:48 +02:00
|
|
|
FT_ERROR(( " 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
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Short )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read_ShortLE( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Error* error )
|
2000-07-07 21:47:34 +02:00
|
|
|
{
|
|
|
|
FT_Byte reads[2];
|
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_Short result = 0;
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
result = NEXT_ShortLE( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
stream->pos += 2;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Fail:
|
|
|
|
*error = FT_Err_Invalid_Stream_Operation;
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Read_Short:" ));
|
2000-07-07 21:47:34 +02:00
|
|
|
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
|
|
|
stream->pos, stream->size ));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Long )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read_Offset( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte reads[3];
|
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_Long 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 )
|
|
|
|
result = NEXT_Offset( 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:
|
|
|
|
*error = FT_Err_Invalid_Stream_Operation;
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Read_Offset:" ));
|
2000-06-06 22:41:48 +02:00
|
|
|
FT_ERROR(( " 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
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Long )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read_Long( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
2000-07-05 06:32:02 +02:00
|
|
|
FT_Byte reads[4];
|
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_Long 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 )
|
|
|
|
result = NEXT_Long( 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:
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Read_Long:" ));
|
2000-06-06 22:41:48 +02:00
|
|
|
FT_ERROR(( " 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
|
|
|
*error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Long )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read_LongLE( FT_Stream stream,
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_Error* error )
|
2000-07-07 21:47:34 +02:00
|
|
|
{
|
|
|
|
FT_Byte reads[4];
|
|
|
|
FT_Byte* p = 0;
|
|
|
|
FT_Long result = 0;
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
result = NEXT_LongLE( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
stream->pos += 4;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Fail:
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_ERROR(( "FT_Stream_Read_Long:" ));
|
2000-07-07 21:47:34 +02:00
|
|
|
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
|
|
|
|
stream->pos, stream->size ));
|
|
|
|
*error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Read_Fields( 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;
|
2000-08-29 18:03:28 +02:00
|
|
|
FT_Byte* cursor = stream->cursor;
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-06-02 16:30:38 +02:00
|
|
|
|
|
|
|
if ( !fields || !stream )
|
2000-02-13 14:36:53 +01:00
|
|
|
return FT_Err_Invalid_Argument;
|
2000-05-17 01:44:38 +02:00
|
|
|
|
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-02-24 06:26:57 +01:00
|
|
|
error = FT_Stream_Enter_Frame( 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
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
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;
|
2000-09-29 08:41:56 +02:00
|
|
|
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 */
|
2000-08-29 18:03:28 +02:00
|
|
|
value = 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 */
|
2000-08-29 18:03:28 +02:00
|
|
|
value = 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 */
|
2000-08-29 18:03:28 +02:00
|
|
|
value = NEXT_UShortLE(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 */
|
2000-08-29 18:03:28 +02:00
|
|
|
value = 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 */
|
2000-08-29 18:03:28 +02:00
|
|
|
value = NEXT_ULongLE(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 */
|
2000-08-29 18:03:28 +02:00
|
|
|
value = NEXT_UOffset(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 */
|
2000-08-29 18:03:28 +02:00
|
|
|
value = NEXT_UOffsetLE(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
|
|
|
{
|
2000-06-02 16:30:38 +02:00
|
|
|
case 1:
|
|
|
|
*(FT_Byte*)p = (FT_Byte)value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
*(FT_UShort*)p = (FT_UShort)value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
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-02-24 06:26:57 +01:00
|
|
|
FT_Stream_Exit_Frame( 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 */
|