2000-05-11 20:23:52 +02:00
|
|
|
#include <freetype/internal/ftstream.h>
|
|
|
|
#include <freetype/internal/ftdebug.h>
|
1999-12-17 00:11:37 +01:00
|
|
|
|
|
|
|
#undef FT_COMPONENT
|
|
|
|
#define FT_COMPONENT trace_stream
|
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(void) FT_New_Memory_Stream( FT_Library library,
|
|
|
|
void* base,
|
|
|
|
unsigned long size,
|
|
|
|
FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
stream->memory = library->memory;
|
|
|
|
stream->base = (char*)base;
|
|
|
|
stream->size = size;
|
|
|
|
stream->pos = 0;
|
|
|
|
stream->cursor = 0;
|
|
|
|
stream->read = 0;
|
|
|
|
stream->close = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Error) FT_Seek_Stream( FT_Stream stream,
|
|
|
|
FT_ULong pos )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
FT_Error error;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
stream->pos = pos;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (stream->read)
|
|
|
|
{
|
|
|
|
if (stream->read( stream, pos, 0, 0 ))
|
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
|
|
|
|
FT_ERROR(( "FT_Seek_Stream:" ));
|
|
|
|
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx\n",
|
|
|
|
pos, stream->size ));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = FT_Err_Ok;
|
|
|
|
}
|
|
|
|
/* note that seeking to the first position after the file is valid */
|
|
|
|
else if (pos > stream->size)
|
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
|
|
|
|
FT_ERROR(( "FT_Seek_Stream:" ));
|
|
|
|
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx\n",
|
|
|
|
pos, stream->size ));
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Error) FT_Skip_Stream( FT_Stream stream,
|
|
|
|
FT_Long distance )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
return FT_Seek_Stream( stream, (FT_ULong)(stream->pos + distance) );
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(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
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Error) FT_Read_Stream( FT_Stream stream,
|
|
|
|
void* buffer,
|
|
|
|
FT_ULong count )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
return FT_Read_Stream_At( stream, stream->pos, buffer, count );
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Error) FT_Read_Stream_At( FT_Stream stream,
|
|
|
|
FT_ULong pos,
|
|
|
|
void* 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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (pos >= stream->size)
|
|
|
|
{
|
|
|
|
FT_ERROR(( "FT_Read_Stream_At:" ));
|
|
|
|
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx\n",
|
|
|
|
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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (stream->read)
|
|
|
|
read_bytes = stream->read( stream, pos, buffer, count );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
read_bytes = stream->size - pos;
|
|
|
|
if (read_bytes > count)
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (read_bytes < count)
|
|
|
|
{
|
|
|
|
FT_ERROR(( "FT_Read_Stream_At:" ));
|
|
|
|
FT_ERROR(( " invalid read, expected %lu bytes, got %lu",
|
|
|
|
count, read_bytes ));
|
|
|
|
error = FT_Err_Invalid_Stream_Operation;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Error) FT_Access_Frame( FT_Stream stream,
|
|
|
|
FT_ULong count )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
FT_ULong read_bytes;
|
|
|
|
|
|
|
|
/* check for nested frame access */
|
2000-01-10 18:19:45 +01:00
|
|
|
FT_Assert( stream && stream->cursor == 0 );
|
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (stream->read)
|
|
|
|
{
|
|
|
|
/* allocate the frame in memory */
|
|
|
|
FT_Memory memory = stream->memory;
|
2000-01-10 18:19:45 +01: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 );
|
1999-12-17 00:11:37 +01:00
|
|
|
if (read_bytes < count)
|
|
|
|
{
|
|
|
|
FT_ERROR(( "FT_Access_Frame:" ));
|
|
|
|
FT_ERROR(( " invalid read, expected %lu bytes, got %lu",
|
|
|
|
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 */
|
|
|
|
if (stream->pos >= stream->size || stream->pos + count > stream->size)
|
|
|
|
{
|
|
|
|
FT_ERROR(( "FT_Access_Frame:" ));
|
|
|
|
FT_ERROR(( " invalid i/o, pos = 0x%lx, count = %lu, size = 0x%lx",
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(void) FT_Forget_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 */
|
|
|
|
/* 0 records, like in some strange kern tables).. */
|
|
|
|
/* */
|
|
|
|
/* In this case, the loader code handles the 0-length table */
|
|
|
|
/* gracefully, however, stream.cursor is really set to 0 by the */
|
|
|
|
/* FT_Access_Frame call, and this is not an error.. */
|
|
|
|
/* */
|
|
|
|
FT_Assert( stream );
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (stream->read)
|
|
|
|
{
|
|
|
|
FT_Memory memory = stream->memory;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
FREE( stream->base );
|
|
|
|
}
|
|
|
|
stream->cursor = 0;
|
|
|
|
stream->limit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Char) FT_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-05-02 12:51:04 +02:00
|
|
|
FT_Assert( stream && stream->cursor );
|
1999-12-17 00:11:37 +01:00
|
|
|
|
|
|
|
result = 0;
|
2000-01-10 18:19:45 +01: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
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Short) FT_Get_Short( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
FT_Short result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +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;
|
|
|
|
if (p+1 < stream->limit)
|
|
|
|
result = NEXT_Short(p);
|
|
|
|
stream->cursor = p;
|
|
|
|
return result;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Long) FT_Get_Offset( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
FT_Long result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +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;
|
|
|
|
if (p+2 < stream->limit)
|
|
|
|
result = NEXT_Offset(p);
|
|
|
|
stream->cursor = p;
|
|
|
|
return result;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Long) FT_Get_Long( FT_Stream stream )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
FT_Long result;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
FT_Assert( stream && stream->cursor );
|
|
|
|
|
2000-01-10 18:19:45 +01:00
|
|
|
result = 0;
|
1999-12-17 00:11:37 +01:00
|
|
|
p = stream->cursor;
|
|
|
|
if (p+3 < stream->limit)
|
|
|
|
result = NEXT_Long(p);
|
|
|
|
stream->cursor = p;
|
|
|
|
return result;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Char) FT_Read_Char( FT_Stream stream,
|
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
char result = 0;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (stream->read)
|
|
|
|
{
|
|
|
|
if ( stream->read( stream, stream->pos, &result, 1L ) != 1L )
|
|
|
|
goto Fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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++;
|
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;
|
|
|
|
FT_ERROR(( "FT_Read_Char:" ));
|
|
|
|
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx",
|
|
|
|
stream->pos, stream->size ));
|
|
|
|
return 0;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Short) FT_Read_Short( FT_Stream stream,
|
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
char reads[2];
|
|
|
|
char* p = 0;
|
|
|
|
FT_Short result = 0;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (stream->pos+1 < stream->size)
|
|
|
|
{
|
|
|
|
if (stream->read)
|
|
|
|
{
|
|
|
|
if (stream->read( stream, stream->pos, reads, 2L ) != 2L )
|
|
|
|
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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (p)
|
2000-01-17 12:21:49 +01:00
|
|
|
result = NEXT_Short(p);
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
|
|
|
else goto Fail;
|
|
|
|
|
2000-01-17 12:21:49 +01:00
|
|
|
stream->pos += 2;
|
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;
|
|
|
|
FT_ERROR(( "FT_Read_Short:" ));
|
|
|
|
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx",
|
|
|
|
stream->pos, stream->size ));
|
|
|
|
return 0;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Long) FT_Read_Offset( FT_Stream stream,
|
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
char reads[3];
|
|
|
|
char* p = 0;
|
|
|
|
FT_Long result = 0;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (stream->pos+2 < stream->size)
|
|
|
|
{
|
|
|
|
if (stream->read)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (p)
|
2000-01-17 12:21:49 +01:00
|
|
|
result = NEXT_Offset(p);
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
|
|
|
else goto Fail;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
2000-01-17 12:21:49 +01:00
|
|
|
stream->pos += 3;
|
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;
|
|
|
|
FT_ERROR(( "FT_Read_Offset:" ));
|
|
|
|
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx",
|
|
|
|
stream->pos, stream->size ));
|
|
|
|
return 0;
|
|
|
|
}
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Long) FT_Read_Long( FT_Stream stream,
|
|
|
|
FT_Error* error )
|
1999-12-17 00:11:37 +01:00
|
|
|
{
|
|
|
|
char reads[4];
|
|
|
|
char* p = 0;
|
|
|
|
FT_Long result = 0;
|
2000-01-10 18:19:45 +01:00
|
|
|
|
1999-12-17 00:11:37 +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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (stream->pos+3 < stream->size)
|
|
|
|
{
|
|
|
|
if (stream->read)
|
|
|
|
{
|
|
|
|
if (stream->read( stream, stream->pos, reads, 4L ) != 4L )
|
|
|
|
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
|
|
|
|
1999-12-17 00:11:37 +01:00
|
|
|
if (p)
|
2000-01-17 12:21:49 +01:00
|
|
|
result = NEXT_Long(p);
|
1999-12-17 00:11:37 +01:00
|
|
|
}
|
|
|
|
else goto Fail;
|
|
|
|
|
2000-01-17 12:21:49 +01:00
|
|
|
stream->pos += 4;
|
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;
|
|
|
|
FT_ERROR(( "FT_Read_Long:" ));
|
|
|
|
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx",
|
|
|
|
stream->pos, stream->size ));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-05-12 14:17:15 +02:00
|
|
|
BASE_FUNC(FT_Error) FT_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-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
if (!fields || !stream)
|
|
|
|
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-02-13 14:36:53 +01:00
|
|
|
switch (fields->value)
|
|
|
|
{
|
|
|
|
case ft_frame_start: /* access a new frame */
|
|
|
|
{
|
|
|
|
error = FT_Access_Frame( stream, fields->offset );
|
|
|
|
if (error) goto Exit;
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
frame_accessed = 1;
|
|
|
|
fields++;
|
|
|
|
continue; /* loop ! */
|
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
case ft_frame_byte:
|
|
|
|
case ft_frame_schar: /* read a single byte */
|
|
|
|
{
|
|
|
|
value = GET_Byte();
|
|
|
|
sign_shift = 24;
|
|
|
|
break;
|
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
case ft_frame_short_be:
|
|
|
|
case ft_frame_ushort_be: /* read a 2-byte big-endian short */
|
|
|
|
{
|
|
|
|
value = GET_UShort();
|
|
|
|
sign_shift = 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ft_frame_short_le:
|
|
|
|
case ft_frame_ushort_le: /* read a 2-byte little-endian short */
|
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
value = 0;
|
|
|
|
p = stream->cursor;
|
|
|
|
if (p+1 < stream->limit)
|
|
|
|
{
|
|
|
|
value = (FT_UShort)p[0] | ((FT_UShort)p[1] << 8);
|
|
|
|
stream->cursor += 2;
|
|
|
|
}
|
|
|
|
sign_shift = 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ft_frame_long_be:
|
|
|
|
case ft_frame_ulong_be: /* read a 4-byte big-endian long */
|
|
|
|
{
|
|
|
|
value = GET_ULong();
|
|
|
|
sign_shift = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ft_frame_long_le:
|
|
|
|
case ft_frame_ulong_le: /* read a 4-byte little-endian long */
|
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
value = 0;
|
|
|
|
p = stream->cursor;
|
|
|
|
if (p+3 < stream->limit)
|
|
|
|
{
|
|
|
|
value = (FT_ULong)p[0] |
|
|
|
|
((FT_ULong)p[1] << 8) |
|
|
|
|
((FT_ULong)p[2] << 16) |
|
|
|
|
((FT_ULong)p[3] << 24);
|
|
|
|
stream->cursor += 4;
|
|
|
|
}
|
|
|
|
sign_shift = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ft_frame_off3_be:
|
|
|
|
case ft_frame_uoff3_be: /* read a 3-byte big-endian long */
|
|
|
|
{
|
|
|
|
value = GET_UOffset();
|
|
|
|
sign_shift = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ft_frame_off3_le:
|
|
|
|
case ft_frame_uoff3_le: /* read a 3-byte little-endian long */
|
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
value = 0;
|
|
|
|
p = stream->cursor;
|
|
|
|
if (p+3 < stream->limit)
|
|
|
|
{
|
|
|
|
value = (FT_ULong)p[0] |
|
|
|
|
((FT_ULong)p[1] << 8) |
|
|
|
|
((FT_ULong)p[2] << 16) |
|
|
|
|
((FT_ULong)p[3] << 24);
|
|
|
|
stream->cursor += 4;
|
|
|
|
}
|
|
|
|
sign_shift = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* otherwise, exit the loop */
|
|
|
|
goto Exit;
|
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
/* now, compute the signed value is necessary */
|
|
|
|
if (fields->value & FT_FRAME_OP_SIGNED)
|
|
|
|
value = (FT_ULong)((FT_Long)(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;
|
|
|
|
switch (fields->size)
|
|
|
|
{
|
|
|
|
case 1: *(FT_Byte*)p = (FT_Byte) value; break;
|
|
|
|
case 2: *(FT_UShort*)p = (FT_UShort)value; break;
|
|
|
|
case 4: *(FT_ULong*)p = (FT_ULong) value; break;
|
|
|
|
default: ; /* ignore !! */
|
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
/* go to next field */
|
|
|
|
fields++;
|
|
|
|
}
|
|
|
|
while (1);
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
/* close the frame if it was opened by this read */
|
|
|
|
if (frame_accessed)
|
|
|
|
FT_Forget_Frame(stream);
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-02-13 14:36:53 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|