FT_Stream_OpenBzip2( FT_Stream stream, FT_Stream source ) { FT_Error error; FT_Memory memory; FT_BZip2File zip = NULL; if ( !stream || !source ) { error = FT_THROW( Invalid_Stream_Handle ); goto Exit; } memory = source->memory; /* * check the header right now; this prevents allocating unnecessary * objects when we don't need them */ error = ft_bzip2_check_header( source ); if ( error ) goto Exit; FT_ZERO( stream ); stream->memory = memory; if ( !FT_QNEW( zip ) ) { error = ft_bzip2_file_init( zip, stream, source ); if ( error ) { FT_FREE( zip ); goto Exit; } stream->descriptor.pointer = zip; } stream->size = 0x7FFFFFFFL; /* don't know the real size! */ stream->pos = 0; stream->base = 0; stream->read = ft_bzip2_stream_io; stream->close = ft_bzip2_stream_close; Exit: return error; }
cf2_stack_init( FT_Memory memory, FT_Error* e ) { FT_Error error = FT_Err_Ok; /* for FT_QNEW */ CF2_Stack stack = NULL; if ( !FT_QNEW( stack ) ) { /* initialize the structure; FT_QNEW zeroes it */ stack->memory = memory; stack->error = e; stack->top = &stack->buffer[0]; /* empty stack */ } return stack; }
FT_Stream_OpenGzip( FT_Stream stream, FT_Stream source ) { FT_Error error; FT_Memory memory = source->memory; FT_GZipFile zip; /* * check the header right now; this prevents allocating un-necessary * objects when we don't need them */ error = ft_gzip_check_header( source ); if ( error ) goto Exit; FT_ZERO( stream ); stream->memory = memory; if ( !FT_QNEW( zip ) ) { error = ft_gzip_file_init( zip, stream, source ); if ( error ) { FT_FREE( zip ); goto Exit; } stream->descriptor.pointer = zip; } /* * We use the following trick to try to dramatically improve the * performance while dealing with small files. If the original stream * size is less than a certain threshold, we try to load the whole font * file into memory. This saves us from using the 32KB buffer needed * to inflate the file, plus the two 4KB intermediate input/output * buffers used in the `FT_GZipFile' structure. */ { FT_ULong zip_size = ft_gzip_get_uncompressed_size( source ); if ( zip_size != 0 && zip_size < 40 * 1024 ) { FT_Byte* zip_buff; if ( !FT_ALLOC( zip_buff, zip_size ) ) { FT_ULong count; count = ft_gzip_file_io( zip, 0, zip_buff, zip_size ); if ( count == zip_size ) { ft_gzip_file_done( zip ); FT_FREE( zip ); stream->descriptor.pointer = NULL; stream->size = zip_size; stream->pos = 0; stream->base = zip_buff; stream->read = NULL; stream->close = ft_gzip_stream_close; goto Exit; } ft_gzip_file_io( zip, 0, NULL, 0 ); FT_FREE( zip_buff ); } error = 0; } } stream->size = 0x7FFFFFFFL; /* don't know the real size! */ stream->pos = 0; stream->base = 0; stream->read = ft_gzip_stream_io; stream->close = ft_gzip_stream_close; Exit: return error; }