FT_Stream_EnterFrame( FT_Stream stream, FT_ULong count ) { FT_Error error = FT_Err_Ok; FT_ULong read_bytes; /* check for nested frame access */ FT_ASSERT( stream && stream->cursor == 0 ); if ( stream->read ) { /* allocate the frame in memory */ FT_Memory memory = stream->memory; if ( FT_QALLOC( stream->base, count ) ) goto Exit; /* read it */ read_bytes = stream->read( stream, stream->pos, stream->base, count ); if ( read_bytes < count ) { FT_ERROR(( "FT_Stream_EnterFrame:" )); FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n", count, read_bytes )); FT_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_Stream_EnterFrame:" )); FT_ERROR(( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", stream->pos, count, stream->size )); error = FT_Err_Invalid_Stream_Operation; goto Exit; } /* set cursor */ stream->cursor = stream->base + stream->pos; stream->limit = stream->cursor + count; stream->pos += count; } Exit: return error; }
FT_QAlloc( FT_Memory memory, FT_Long size, void* *p ) { FT_Error error; (void)FT_QALLOC( *p, size ); return error; }
FT_Bitmap_Copy( FT_Library library, const FT_Bitmap *source, FT_Bitmap *target) { FT_Memory memory = library->memory; FT_Error error = FT_Err_Ok; FT_Int pitch = source->pitch; FT_ULong size; if ( source == target ) return FT_Err_Ok; if ( source->buffer == NULL ) { *target = *source; return FT_Err_Ok; } if ( pitch < 0 ) pitch = -pitch; size = (FT_ULong)( pitch * source->rows ); if ( target->buffer ) { FT_Int target_pitch = target->pitch; FT_ULong target_size; if ( target_pitch < 0 ) target_pitch = -target_pitch; target_size = (FT_ULong)( target_pitch * target->rows ); if ( target_size != size ) (void)FT_QREALLOC( target->buffer, target_size, size ); } else (void)FT_QALLOC( target->buffer, size ); if ( !error ) { unsigned char *p; p = target->buffer; *target = *source; target->buffer = p; FT_MEM_COPY( target->buffer, source->buffer, size ); } return error; }
afm_parser_read_vals( AFM_Parser parser, AFM_Value vals, FT_UInt n ) { AFM_Stream stream = parser->stream; char* str; FT_UInt i; if ( n > AFM_MAX_ARGUMENTS ) return 0; for ( i = 0; i < n; i++ ) { FT_Offset len; AFM_Value val = vals + i; if ( val->type == AFM_VALUE_TYPE_STRING ) str = afm_stream_read_string( stream ); else str = afm_stream_read_one( stream ); if ( !str ) break; len = AFM_STREAM_KEY_LEN( stream, str ); switch ( val->type ) { case AFM_VALUE_TYPE_STRING: case AFM_VALUE_TYPE_NAME: { FT_Memory memory = parser->memory; FT_Error error; if ( !FT_QALLOC( val->u.s, len + 1 ) ) { ft_memcpy( val->u.s, str, len ); val->u.s[len] = '\0'; } } break; case AFM_VALUE_TYPE_FIXED: val->u.f = PS_Conv_ToFixed( (FT_Byte**)(void*)&str, (FT_Byte*)str + len, 0 ); break; case AFM_VALUE_TYPE_INTEGER: val->u.i = PS_Conv_ToInt( (FT_Byte**)(void*)&str, (FT_Byte*)str + len ); break; case AFM_VALUE_TYPE_BOOL: val->u.b = FT_BOOL( len == 4 && !ft_strncmp( str, "true", 4 ) ); break; case AFM_VALUE_TYPE_INDEX: if ( parser->get_index ) val->u.i = parser->get_index( str, len, parser->user_data ); else val->u.i = 0; break; } } return i; }
FT_Stream_EnterFrame( FT_Stream stream, FT_ULong count ) { FT_Error error = FT_Err_Ok; FT_ULong read_bytes; /* check for nested frame access */ FT_ASSERT( stream && stream->cursor == 0 ); if ( stream->read ) { /* allocate the frame in memory */ FT_Memory memory = stream->memory; #ifdef FT_DEBUG_MEMORY /* assume _ft_debug_file and _ft_debug_lineno are already set */ stream->base = (unsigned char*)ft_mem_qalloc( memory, count, &error ); if ( error ) goto Exit; #else if ( FT_QALLOC( stream->base, count ) ) goto Exit; #endif /* read it */ read_bytes = stream->read( stream, stream->pos, stream->base, count ); if ( read_bytes < count ) { FT_ERROR(( "FT_Stream_EnterFrame:" )); FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n", count, read_bytes )); FT_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_Stream_EnterFrame:" )); FT_ERROR(( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", stream->pos, count, stream->size )); error = FT_Err_Invalid_Stream_Operation; goto Exit; } /* set cursor */ stream->cursor = stream->base + stream->pos; stream->limit = stream->cursor + count; stream->pos += count; } Exit: return error; }
FT_Bitmap_Copy( FT_Library library, const FT_Bitmap *source, FT_Bitmap *target) { FT_Memory memory; FT_Error error = FT_Err_Ok; FT_Int pitch; FT_ULong size; FT_Int source_pitch_sign, target_pitch_sign; if ( !library ) return FT_THROW( Invalid_Library_Handle ); if ( !source || !target ) return FT_THROW( Invalid_Argument ); if ( source == target ) return FT_Err_Ok; source_pitch_sign = source->pitch < 0 ? -1 : 1; target_pitch_sign = target->pitch < 0 ? -1 : 1; if ( source->buffer == NULL ) { *target = *source; if ( source_pitch_sign != target_pitch_sign ) target->pitch = -target->pitch; return FT_Err_Ok; } memory = library->memory; pitch = source->pitch; if ( pitch < 0 ) pitch = -pitch; size = (FT_ULong)pitch * source->rows; if ( target->buffer ) { FT_Int target_pitch = target->pitch; FT_ULong target_size; if ( target_pitch < 0 ) target_pitch = -target_pitch; target_size = (FT_ULong)target_pitch * target->rows; if ( target_size != size ) (void)FT_QREALLOC( target->buffer, target_size, size ); } else (void)FT_QALLOC( target->buffer, size ); if ( !error ) { unsigned char *p; p = target->buffer; *target = *source; target->buffer = p; if ( source_pitch_sign == target_pitch_sign ) FT_MEM_COPY( target->buffer, source->buffer, size ); else { /* take care of bitmap flow */ FT_UInt i; FT_Byte* s = source->buffer; FT_Byte* t = target->buffer; t += pitch * ( target->rows - 1 ); for ( i = target->rows; i > 0; i-- ) { FT_ARRAY_COPY( t, s, pitch ); s += pitch; t -= pitch; } } } return error; }