static FT_ULong ft_gzip_stream_io( FT_Stream stream, FT_ULong pos, FT_Byte* buffer, FT_ULong count ) { FT_GZipFile zip = (FT_GZipFile)stream->descriptor.pointer; return ft_gzip_file_io( zip, pos, buffer, count ); }
static unsigned long ft_gzip_stream_io( FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count ) { FT_GZipFile zip = (FT_GZipFile)stream->descriptor.pointer; return ft_gzip_file_io( zip, offset, buffer, count ); }
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; }