2002-10-31 23:19:27 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftgzip.c */
|
|
|
|
/* */
|
2003-04-23 09:13:54 +02:00
|
|
|
/* FreeType support for .gz compressed files. */
|
2002-10-31 23:19:27 +01:00
|
|
|
/* */
|
2004-03-05 10:26:24 +01:00
|
|
|
/* This optional component relies on zlib. It should mainly be used to */
|
2002-10-31 23:19:27 +01:00
|
|
|
/* parse compressed PCF fonts, as found with many X11 server */
|
|
|
|
/* distributions. */
|
|
|
|
/* */
|
2016-01-13 11:54:10 +01:00
|
|
|
/* Copyright 2002-2016 by */
|
2002-10-31 23:19:27 +01:00
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */
|
|
|
|
/* modified, and distributed under the terms of the FreeType project */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_INTERNAL_MEMORY_H
|
|
|
|
#include FT_INTERNAL_STREAM_H
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
* builds/unix/ftsystem.c, include/freetype/config/ftheader.h,
include/freetype/internal/services/svotval.h,
include/freetype/internal/services/svpfr.h,
src/base/ftsystem.c, src/bdf/bdfdrivr.c, src/cache/ftcbasic.c,
src/cff/cffcmap.c, src/gzip/ftgzip.c, src/lzw/ftlzw.c,
src/lzw/ftlzw2.c, src/psaux/t1cmap.c, src/sfnt/ttbdf.c,
src/smooth/ftgrays.c:
solved -Wmissing-prototypes warnings with GCC
2006-02-25 15:53:02 +01:00
|
|
|
#include FT_GZIP_H
|
2009-01-13 18:34:48 +01:00
|
|
|
#include FT_CONFIG_STANDARD_LIBRARY_H
|
2002-10-31 23:19:27 +01:00
|
|
|
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
|
|
|
|
#include FT_MODULE_ERRORS_H
|
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#undef FTERRORS_H_
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
|
Prepare source code for amalgamation.
* src\autofit\aferrors.h, src\bdf\bdferror.h, src\bzip2\ftbzip2.c,
src\cache\ftcerror.h, src\cff\cfferrs.h, src\cid\ciderrs.h,
src\gxvalid\gxverror.h, src\gzip\ftgzip.c, src\lzw\ftlzw.c,
src\otvalid\otverror.h, src\pcf\pcferror.h, src\pfr\pfrerror.h,
src\psaux\psauxerr.h, src\pshinter\pshnterr.h,
src\psnames\psnamerr.h, src\raster\rasterrs.h, src\sfnt\sferrors.h,
src\smooth\ftsmerrs.h, src\truetype\tterrors.h,
src\type1\t1errors.h, src\type42\t42error.h, src\winfonts\fnterrs.h:
Add #undef FT_ERR_PREFIX before #define FT_ERR_PREFIX.
2012-03-08 06:04:03 +01:00
|
|
|
#undef FT_ERR_PREFIX
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
#define FT_ERR_PREFIX Gzip_Err_
|
|
|
|
#define FT_ERR_BASE FT_Mod_Err_Gzip
|
|
|
|
|
|
|
|
#include FT_ERRORS_H
|
|
|
|
|
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
#ifdef FT_CONFIG_OPTION_USE_ZLIB
|
|
|
|
|
2009-04-05 17:25:14 +02:00
|
|
|
#ifdef FT_CONFIG_OPTION_PIC
|
|
|
|
#error "gzip code does not support PIC yet"
|
2012-01-16 18:00:24 +01:00
|
|
|
#endif
|
2009-04-05 17:25:14 +02:00
|
|
|
|
2002-11-06 23:32:54 +01:00
|
|
|
#ifdef FT_CONFIG_OPTION_SYSTEM_ZLIB
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
#include <zlib.h>
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
#else /* !FT_CONFIG_OPTION_SYSTEM_ZLIB */
|
2002-11-06 23:32:54 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
/* In this case, we include our own modified sources of the ZLib */
|
|
|
|
/* within the "ftgzip" component. The modifications were necessary */
|
|
|
|
/* to #include all files without conflicts, as well as preventing */
|
|
|
|
/* the definition of "extern" functions that may cause linking */
|
|
|
|
/* conflicts when a program is linked with both FreeType and the */
|
|
|
|
/* original ZLib. */
|
2002-11-06 23:32:54 +01:00
|
|
|
|
2009-07-31 17:30:11 +02:00
|
|
|
#ifndef USE_ZLIB_ZCALLOC
|
|
|
|
#define MY_ZCALLOC /* prevent all zcalloc() & zfree() in zutils.c */
|
|
|
|
#endif
|
2002-11-06 23:32:54 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
#include "zlib.h"
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
#undef SLOW
|
2003-04-25 07:35:04 +02:00
|
|
|
#define SLOW 1 /* we can't use asm-optimized sources here! */
|
|
|
|
|
2013-06-07 18:10:40 +02:00
|
|
|
#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
|
|
|
|
/* We disable the warning `conversion from XXX to YYY, */
|
|
|
|
/* possible loss of data' in order to compile cleanly with */
|
|
|
|
/* the maximum level of warnings: zlib is non-FreeType */
|
|
|
|
/* code. */
|
|
|
|
#pragma warning( push )
|
|
|
|
#pragma warning( disable : 4244 )
|
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
2003-04-25 07:35:04 +02:00
|
|
|
/* Urgh. `inflate_mask' must not be declared twice -- C++ doesn't like
|
2003-06-09 22:55:04 +02:00
|
|
|
this. We temporarily disable it and load all necessary header files. */
|
|
|
|
#define NO_INFLATE_MASK
|
2003-04-25 07:35:04 +02:00
|
|
|
#include "zutil.h"
|
|
|
|
#include "inftrees.h"
|
|
|
|
#include "infblock.h"
|
|
|
|
#include "infcodes.h"
|
|
|
|
#include "infutil.h"
|
2003-06-09 22:55:04 +02:00
|
|
|
#undef NO_INFLATE_MASK
|
2003-04-25 07:35:04 +02:00
|
|
|
|
|
|
|
/* infutil.c must be included before infcodes.c */
|
2003-04-23 09:13:54 +02:00
|
|
|
#include "zutil.c"
|
|
|
|
#include "inftrees.c"
|
|
|
|
#include "infutil.c"
|
2003-04-25 07:35:04 +02:00
|
|
|
#include "infcodes.c"
|
2003-04-23 09:13:54 +02:00
|
|
|
#include "infblock.c"
|
|
|
|
#include "inflate.c"
|
|
|
|
#include "adler32.c"
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2013-06-07 18:10:40 +02:00
|
|
|
#if defined( _MSC_VER )
|
|
|
|
#pragma warning( pop )
|
|
|
|
#endif
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
#endif /* !FT_CONFIG_OPTION_SYSTEM_ZLIB */
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** Z L I B M E M O R Y M A N A G E M E N T *****/
|
|
|
|
/***** *****/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
/* it is better to use FreeType memory routines instead of raw
|
|
|
|
'malloc/free' */
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
static voidpf
|
|
|
|
ft_gzip_alloc( FT_Memory memory,
|
|
|
|
uInt items,
|
|
|
|
uInt size )
|
|
|
|
{
|
|
|
|
FT_ULong sz = (FT_ULong)size * items;
|
2006-01-27 13:11:22 +01:00
|
|
|
FT_Error error;
|
2010-07-12 21:13:22 +02:00
|
|
|
FT_Pointer p = NULL;
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
|
2006-01-27 13:11:22 +01:00
|
|
|
(void)FT_ALLOC( p, sz );
|
|
|
|
return p;
|
2003-04-23 09:13:54 +02:00
|
|
|
}
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
static void
|
|
|
|
ft_gzip_free( FT_Memory memory,
|
|
|
|
voidpf address )
|
|
|
|
{
|
|
|
|
FT_MEM_FREE( address );
|
|
|
|
}
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
|
2009-07-31 17:30:11 +02:00
|
|
|
#if !defined( FT_CONFIG_OPTION_SYSTEM_ZLIB ) && !defined( USE_ZLIB_ZCALLOC )
|
2002-11-06 23:32:54 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
local voidpf
|
|
|
|
zcalloc ( voidpf opaque,
|
|
|
|
unsigned items,
|
|
|
|
unsigned size )
|
|
|
|
{
|
2003-04-25 07:35:04 +02:00
|
|
|
return ft_gzip_alloc( (FT_Memory)opaque, items, size );
|
2003-04-23 09:13:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local void
|
|
|
|
zcfree( voidpf opaque,
|
|
|
|
voidpf ptr )
|
|
|
|
{
|
2003-04-25 07:35:04 +02:00
|
|
|
ft_gzip_free( (FT_Memory)opaque, ptr );
|
2003-04-23 09:13:54 +02:00
|
|
|
}
|
2002-11-06 23:32:54 +01:00
|
|
|
|
2009-07-31 17:30:11 +02:00
|
|
|
#endif /* !SYSTEM_ZLIB && !USE_ZLIB_ZCALLOC */
|
2002-11-06 23:32:54 +01:00
|
|
|
|
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** Z L I B F I L E D E S C R I P T O R *****/
|
|
|
|
/***** *****/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2004-03-05 10:26:24 +01:00
|
|
|
#define FT_GZIP_BUFFER_SIZE 4096
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
typedef struct FT_GZipFileRec_
|
2002-10-31 23:19:27 +01:00
|
|
|
{
|
2003-04-23 09:13:54 +02:00
|
|
|
FT_Stream source; /* parent/source stream */
|
|
|
|
FT_Stream stream; /* embedding stream */
|
|
|
|
FT_Memory memory; /* memory allocator */
|
|
|
|
z_stream zstream; /* zlib input stream */
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
FT_ULong start; /* starting position, after .gz header */
|
2004-03-05 10:26:24 +01:00
|
|
|
FT_Byte input[FT_GZIP_BUFFER_SIZE]; /* input read buffer */
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
FT_Byte buffer[FT_GZIP_BUFFER_SIZE]; /* output buffer */
|
|
|
|
FT_ULong pos; /* position in output */
|
|
|
|
FT_Byte* cursor;
|
|
|
|
FT_Byte* limit;
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
} FT_GZipFileRec, *FT_GZipFile;
|
|
|
|
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
/* gzip flag byte */
|
2002-10-31 23:19:27 +01:00
|
|
|
#define FT_GZIP_ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
|
|
|
|
#define FT_GZIP_HEAD_CRC 0x02 /* bit 1 set: header CRC present */
|
|
|
|
#define FT_GZIP_EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
|
|
|
|
#define FT_GZIP_ORIG_NAME 0x08 /* bit 3 set: original file name present */
|
|
|
|
#define FT_GZIP_COMMENT 0x10 /* bit 4 set: file comment present */
|
|
|
|
#define FT_GZIP_RESERVED 0xE0 /* bits 5..7: reserved */
|
|
|
|
|
|
|
|
|
2004-03-05 10:26:24 +01:00
|
|
|
/* check and skip .gz header - we don't support `transparent' compression */
|
2002-10-31 23:19:27 +01:00
|
|
|
static FT_Error
|
|
|
|
ft_gzip_check_header( FT_Stream stream )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Byte head[4];
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
if ( FT_STREAM_SEEK( 0 ) ||
|
|
|
|
FT_STREAM_READ( head, 4 ) )
|
|
|
|
goto Exit;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
/* head[0] && head[1] are the magic numbers; */
|
2002-10-31 23:19:27 +01:00
|
|
|
/* head[2] is the method, and head[3] the flags */
|
2014-12-07 11:03:57 +01:00
|
|
|
if ( head[0] != 0x1F ||
|
|
|
|
head[1] != 0x8B ||
|
2002-10-31 23:19:27 +01:00
|
|
|
head[2] != Z_DEFLATED ||
|
|
|
|
(head[3] & FT_GZIP_RESERVED) )
|
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_File_Format );
|
2002-10-31 23:19:27 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip time, xflags and os code */
|
|
|
|
(void)FT_STREAM_SKIP( 6 );
|
|
|
|
|
|
|
|
/* skip the extra field */
|
2003-01-16 00:01:02 +01:00
|
|
|
if ( head[3] & FT_GZIP_EXTRA_FIELD )
|
2002-10-31 23:19:27 +01:00
|
|
|
{
|
|
|
|
FT_UInt len;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
if ( FT_READ_USHORT_LE( len ) ||
|
|
|
|
FT_STREAM_SKIP( len ) )
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip original file name */
|
2003-01-16 00:01:02 +01:00
|
|
|
if ( head[3] & FT_GZIP_ORIG_NAME )
|
2002-10-31 23:19:27 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
FT_UInt c;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
|
|
|
if ( FT_READ_BYTE( c ) )
|
2002-10-31 23:19:27 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
if ( c == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip .gz comment */
|
|
|
|
if ( head[3] & FT_GZIP_COMMENT )
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
FT_UInt c;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
|
|
|
if ( FT_READ_BYTE( c ) )
|
2002-10-31 23:19:27 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
if ( c == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip CRC */
|
|
|
|
if ( head[3] & FT_GZIP_HEAD_CRC )
|
|
|
|
if ( FT_STREAM_SKIP( 2 ) )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FT_Error
|
2003-04-23 09:13:54 +02:00
|
|
|
ft_gzip_file_init( FT_GZipFile zip,
|
|
|
|
FT_Stream stream,
|
|
|
|
FT_Stream source )
|
2002-10-31 23:19:27 +01:00
|
|
|
{
|
|
|
|
z_stream* zstream = &zip->zstream;
|
2013-03-14 11:21:17 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
zip->stream = stream;
|
|
|
|
zip->source = source;
|
|
|
|
zip->memory = stream->memory;
|
|
|
|
|
|
|
|
zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
|
|
|
|
zip->cursor = zip->limit;
|
|
|
|
zip->pos = 0;
|
|
|
|
|
|
|
|
/* check and skip .gz header */
|
|
|
|
{
|
|
|
|
stream = source;
|
|
|
|
|
|
|
|
error = ft_gzip_check_header( stream );
|
2003-04-23 09:13:54 +02:00
|
|
|
if ( error )
|
2002-10-31 23:19:27 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
zip->start = FT_STREAM_POS();
|
|
|
|
}
|
|
|
|
|
2004-03-05 10:26:24 +01:00
|
|
|
/* initialize zlib -- there is no zlib header in the compressed stream */
|
|
|
|
zstream->zalloc = (alloc_func)ft_gzip_alloc;
|
|
|
|
zstream->zfree = (free_func) ft_gzip_free;
|
2002-10-31 23:19:27 +01:00
|
|
|
zstream->opaque = stream->memory;
|
|
|
|
|
|
|
|
zstream->avail_in = 0;
|
|
|
|
zstream->next_in = zip->buffer;
|
|
|
|
|
|
|
|
if ( inflateInit2( zstream, -MAX_WBITS ) != Z_OK ||
|
|
|
|
zstream->next_in == NULL )
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_File_Format );
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
ft_gzip_file_done( FT_GZipFile zip )
|
|
|
|
{
|
|
|
|
z_stream* zstream = &zip->zstream;
|
|
|
|
|
2004-03-05 10:26:24 +01:00
|
|
|
|
2003-02-28 09:32:46 +01:00
|
|
|
inflateEnd( zstream );
|
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
/* clear the rest */
|
|
|
|
zstream->zalloc = NULL;
|
|
|
|
zstream->zfree = NULL;
|
|
|
|
zstream->opaque = NULL;
|
|
|
|
zstream->next_in = NULL;
|
|
|
|
zstream->next_out = NULL;
|
|
|
|
zstream->avail_in = 0;
|
|
|
|
zstream->avail_out = 0;
|
|
|
|
|
|
|
|
zip->memory = NULL;
|
|
|
|
zip->source = NULL;
|
|
|
|
zip->stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FT_Error
|
|
|
|
ft_gzip_file_reset( FT_GZipFile zip )
|
|
|
|
{
|
|
|
|
FT_Stream stream = zip->source;
|
|
|
|
FT_Error error;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
if ( !FT_STREAM_SEEK( zip->start ) )
|
|
|
|
{
|
|
|
|
z_stream* zstream = &zip->zstream;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
inflateReset( zstream );
|
|
|
|
|
|
|
|
zstream->avail_in = 0;
|
|
|
|
zstream->next_in = zip->input;
|
|
|
|
zstream->avail_out = 0;
|
|
|
|
zstream->next_out = zip->buffer;
|
|
|
|
|
|
|
|
zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
|
|
|
|
zip->cursor = zip->limit;
|
|
|
|
zip->pos = 0;
|
|
|
|
}
|
2004-03-05 10:26:24 +01:00
|
|
|
|
|
|
|
return error;
|
2002-10-31 23:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FT_Error
|
|
|
|
ft_gzip_file_fill_input( FT_GZipFile zip )
|
|
|
|
{
|
|
|
|
z_stream* zstream = &zip->zstream;
|
|
|
|
FT_Stream stream = zip->source;
|
|
|
|
FT_ULong size;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
if ( stream->read )
|
|
|
|
{
|
2003-04-23 09:13:54 +02:00
|
|
|
size = stream->read( stream, stream->pos, zip->input,
|
|
|
|
FT_GZIP_BUFFER_SIZE );
|
2002-10-31 23:19:27 +01:00
|
|
|
if ( size == 0 )
|
2015-10-04 07:39:22 +02:00
|
|
|
{
|
|
|
|
zip->limit = zip->cursor;
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Stream_Operation );
|
2015-10-04 07:39:22 +02:00
|
|
|
}
|
2002-10-31 23:19:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size = stream->size - stream->pos;
|
|
|
|
if ( size > FT_GZIP_BUFFER_SIZE )
|
|
|
|
size = FT_GZIP_BUFFER_SIZE;
|
|
|
|
|
|
|
|
if ( size == 0 )
|
2015-10-04 07:39:22 +02:00
|
|
|
{
|
|
|
|
zip->limit = zip->cursor;
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Stream_Operation );
|
2015-10-04 07:39:22 +02:00
|
|
|
}
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
FT_MEM_COPY( zip->input, stream->base + stream->pos, size );
|
|
|
|
}
|
|
|
|
stream->pos += size;
|
|
|
|
|
|
|
|
zstream->next_in = zip->input;
|
|
|
|
zstream->avail_in = size;
|
|
|
|
|
2013-03-14 11:21:17 +01:00
|
|
|
return FT_Err_Ok;
|
2002-10-31 23:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FT_Error
|
|
|
|
ft_gzip_file_fill_output( FT_GZipFile zip )
|
|
|
|
{
|
|
|
|
z_stream* zstream = &zip->zstream;
|
2013-03-14 11:21:17 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
zip->cursor = zip->buffer;
|
|
|
|
zstream->next_out = zip->cursor;
|
|
|
|
zstream->avail_out = FT_GZIP_BUFFER_SIZE;
|
|
|
|
|
|
|
|
while ( zstream->avail_out > 0 )
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
if ( zstream->avail_in == 0 )
|
|
|
|
{
|
|
|
|
error = ft_gzip_file_fill_input( zip );
|
|
|
|
if ( error )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = inflate( zstream, Z_NO_FLUSH );
|
|
|
|
|
|
|
|
if ( err == Z_STREAM_END )
|
|
|
|
{
|
|
|
|
zip->limit = zstream->next_out;
|
2003-06-09 17:54:18 +02:00
|
|
|
if ( zip->limit == zip->cursor )
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
2002-10-31 23:19:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if ( err != Z_OK )
|
|
|
|
{
|
2015-10-03 21:12:25 +02:00
|
|
|
zip->limit = zip->cursor;
|
|
|
|
error = FT_THROW( Invalid_Stream_Operation );
|
2002-10-31 23:19:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-05 10:26:24 +01:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
/* fill output buffer; `count' must be <= FT_GZIP_BUFFER_SIZE */
|
2002-10-31 23:19:27 +01:00
|
|
|
static FT_Error
|
|
|
|
ft_gzip_file_skip_output( FT_GZipFile zip,
|
|
|
|
FT_ULong count )
|
|
|
|
{
|
2013-03-14 11:21:17 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2004-03-05 10:26:24 +01:00
|
|
|
FT_ULong delta;
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
delta = (FT_ULong)( zip->limit - zip->cursor );
|
|
|
|
if ( delta >= count )
|
|
|
|
delta = count;
|
|
|
|
|
|
|
|
zip->cursor += delta;
|
|
|
|
zip->pos += delta;
|
|
|
|
|
|
|
|
count -= delta;
|
|
|
|
if ( count == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
error = ft_gzip_file_fill_output( zip );
|
|
|
|
if ( error )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FT_ULong
|
2003-04-23 09:13:54 +02:00
|
|
|
ft_gzip_file_io( FT_GZipFile zip,
|
|
|
|
FT_ULong pos,
|
|
|
|
FT_Byte* buffer,
|
|
|
|
FT_ULong count )
|
2002-10-31 23:19:27 +01:00
|
|
|
{
|
2003-04-23 09:13:54 +02:00
|
|
|
FT_ULong result = 0;
|
|
|
|
FT_Error error;
|
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
/* Reset inflate stream if we're seeking backwards. */
|
|
|
|
/* Yes, that is not too efficient, but it saves memory :-) */
|
2002-10-31 23:19:27 +01:00
|
|
|
if ( pos < zip->pos )
|
|
|
|
{
|
|
|
|
error = ft_gzip_file_reset( zip );
|
2003-04-23 09:13:54 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2002-10-31 23:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* skip unwanted bytes */
|
|
|
|
if ( pos > zip->pos )
|
|
|
|
{
|
|
|
|
error = ft_gzip_file_skip_output( zip, (FT_ULong)( pos - zip->pos ) );
|
2003-04-23 09:13:54 +02:00
|
|
|
if ( error )
|
2002-10-31 23:19:27 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( count == 0 )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
/* now read the data */
|
|
|
|
for (;;)
|
|
|
|
{
|
2003-04-23 09:13:54 +02:00
|
|
|
FT_ULong delta;
|
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
delta = (FT_ULong)( zip->limit - zip->cursor );
|
|
|
|
if ( delta >= count )
|
|
|
|
delta = count;
|
|
|
|
|
|
|
|
FT_MEM_COPY( buffer, zip->cursor, delta );
|
|
|
|
buffer += delta;
|
|
|
|
result += delta;
|
|
|
|
zip->cursor += delta;
|
|
|
|
zip->pos += delta;
|
|
|
|
|
|
|
|
count -= delta;
|
|
|
|
if ( count == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
error = ft_gzip_file_fill_output( zip );
|
2003-04-23 09:13:54 +02:00
|
|
|
if ( error )
|
2002-10-31 23:19:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** G Z E M B E D D I N G S T R E A M *****/
|
|
|
|
/***** *****/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
ft_gzip_stream_close( FT_Stream stream )
|
|
|
|
{
|
2003-04-25 07:35:04 +02:00
|
|
|
FT_GZipFile zip = (FT_GZipFile)stream->descriptor.pointer;
|
2002-10-31 23:19:27 +01:00
|
|
|
FT_Memory memory = stream->memory;
|
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
if ( zip )
|
|
|
|
{
|
|
|
|
/* finalize gzip file descriptor */
|
|
|
|
ft_gzip_file_done( zip );
|
|
|
|
|
|
|
|
FT_FREE( zip );
|
|
|
|
|
|
|
|
stream->descriptor.pointer = NULL;
|
|
|
|
}
|
2015-09-13 08:05:50 +02:00
|
|
|
|
|
|
|
if ( !stream->read )
|
|
|
|
FT_FREE( stream->base );
|
2002-10-31 23:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-26 15:19:54 +02:00
|
|
|
static unsigned long
|
|
|
|
ft_gzip_stream_io( FT_Stream stream,
|
|
|
|
unsigned long offset,
|
|
|
|
unsigned char* buffer,
|
|
|
|
unsigned long count )
|
2002-10-31 23:19:27 +01:00
|
|
|
{
|
2003-04-25 07:35:04 +02:00
|
|
|
FT_GZipFile zip = (FT_GZipFile)stream->descriptor.pointer;
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2015-09-26 15:19:54 +02:00
|
|
|
return ft_gzip_file_io( zip, offset, buffer, count );
|
2002-10-31 23:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
static FT_ULong
|
|
|
|
ft_gzip_get_uncompressed_size( FT_Stream stream )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_ULong old_pos;
|
|
|
|
FT_ULong result = 0;
|
|
|
|
|
2006-05-18 00:55:04 +02:00
|
|
|
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
old_pos = stream->pos;
|
|
|
|
if ( !FT_Stream_Seek( stream, stream->size - 4 ) )
|
|
|
|
{
|
2015-09-13 08:05:50 +02:00
|
|
|
result = FT_Stream_ReadULongLE( stream, &error );
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
if ( error )
|
|
|
|
result = 0;
|
|
|
|
|
2009-03-12 09:07:49 +01:00
|
|
|
(void)FT_Stream_Seek( stream, old_pos );
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-29 17:53:24 +02:00
|
|
|
/* documentation is in ftgzip.h */
|
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
2003-04-23 09:13:54 +02:00
|
|
|
FT_Stream_OpenGzip( FT_Stream stream,
|
|
|
|
FT_Stream source )
|
2002-10-31 23:19:27 +01:00
|
|
|
{
|
|
|
|
FT_Error error;
|
2014-11-26 21:59:21 +01:00
|
|
|
FT_Memory memory;
|
2011-06-14 19:48:33 +02:00
|
|
|
FT_GZipFile zip = NULL;
|
2002-10-31 23:19:27 +01:00
|
|
|
|
2005-03-16 02:49:54 +01:00
|
|
|
|
2014-11-26 21:59:21 +01:00
|
|
|
if ( !stream || !source )
|
|
|
|
{
|
|
|
|
error = FT_THROW( Invalid_Stream_Handle );
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
memory = source->memory;
|
|
|
|
|
2005-03-16 02:49:54 +01:00
|
|
|
/*
|
|
|
|
* check the header right now; this prevents allocating un-necessary
|
|
|
|
* objects when we don't need them
|
|
|
|
*/
|
2005-03-15 19:18:57 +01:00
|
|
|
error = ft_gzip_check_header( source );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2003-04-23 09:13:54 +02:00
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
FT_ZERO( stream );
|
|
|
|
stream->memory = memory;
|
|
|
|
|
2004-06-23 17:44:03 +02:00
|
|
|
if ( !FT_QNEW( zip ) )
|
2002-10-31 23:19:27 +01:00
|
|
|
{
|
|
|
|
error = ft_gzip_file_init( zip, stream, source );
|
|
|
|
if ( error )
|
|
|
|
{
|
|
|
|
FT_FREE( zip );
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->descriptor.pointer = zip;
|
|
|
|
}
|
|
|
|
|
2006-05-18 00:55:04 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
{
|
2006-05-18 00:55:04 +02:00
|
|
|
FT_ULong zip_size = ft_gzip_get_uncompressed_size( source );
|
|
|
|
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
|
2006-05-18 00:55:04 +02:00
|
|
|
if ( zip_size != 0 && zip_size < 40 * 1024 )
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
{
|
2011-06-14 19:48:33 +02:00
|
|
|
FT_Byte* zip_buff = NULL;
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
|
2006-05-18 00:55:04 +02:00
|
|
|
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
if ( !FT_ALLOC( zip_buff, zip_size ) )
|
|
|
|
{
|
|
|
|
FT_ULong count;
|
|
|
|
|
2006-05-18 00:55:04 +02:00
|
|
|
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
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;
|
|
|
|
}
|
2006-05-18 00:55:04 +02:00
|
|
|
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
ft_gzip_file_io( zip, 0, NULL, 0 );
|
|
|
|
FT_FREE( zip_buff );
|
|
|
|
}
|
2013-03-14 11:21:17 +01:00
|
|
|
error = FT_Err_Ok;
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
}
|
2015-10-09 09:38:32 +02:00
|
|
|
|
|
|
|
if ( zip_size )
|
|
|
|
stream->size = zip_size;
|
|
|
|
else
|
|
|
|
stream->size = 0x7FFFFFFFL; /* don't know the real size! */
|
* include/freetype/internal/tttypes.h, src/autofit/afangles.c,
src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/autofit/aftypes.h, src/base/ftcalc.c, src/base/ftoutln.c,
src/gzip/ftgzip.c, src/psaux/psconv.c, src/truetype/ttgload.c,
src/type1/t1gload.c:
this is a major patch used to drastically improve the performance
of loading glyphs. This both speeds up loading the glypn vector
themselves and the auto-fitter.
note that we've started using inline assembler with GCC to
implement FT_MulFix, given that this function is so damn
important for the engine's performance.
the resulting speed-up is about 25%.
2006-05-17 15:34:21 +02:00
|
|
|
}
|
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
stream->pos = 0;
|
2015-09-13 08:05:50 +02:00
|
|
|
stream->base = NULL;
|
2002-10-31 23:19:27 +01:00
|
|
|
stream->read = ft_gzip_stream_io;
|
|
|
|
stream->close = ft_gzip_stream_close;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-08-29 17:53:24 +02:00
|
|
|
|
|
|
|
/* documentation is in ftgzip.h */
|
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_Gzip_Uncompress( FT_Memory memory,
|
|
|
|
FT_Byte* output,
|
|
|
|
FT_ULong* output_len,
|
|
|
|
const FT_Byte* input,
|
|
|
|
FT_ULong input_len )
|
|
|
|
{
|
|
|
|
z_stream stream;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
2014-11-26 21:59:21 +01:00
|
|
|
/* check for `input' delayed to `inflate' */
|
|
|
|
|
|
|
|
if ( !memory || ! output_len || !output )
|
|
|
|
return FT_THROW( Invalid_Argument );
|
|
|
|
|
2013-08-29 17:53:24 +02:00
|
|
|
/* this function is modeled after zlib's `uncompress' function */
|
|
|
|
|
|
|
|
stream.next_in = (Bytef*)input;
|
|
|
|
stream.avail_in = (uInt)input_len;
|
|
|
|
|
|
|
|
stream.next_out = output;
|
|
|
|
stream.avail_out = (uInt)*output_len;
|
|
|
|
|
|
|
|
stream.zalloc = (alloc_func)ft_gzip_alloc;
|
|
|
|
stream.zfree = (free_func) ft_gzip_free;
|
|
|
|
stream.opaque = memory;
|
|
|
|
|
|
|
|
err = inflateInit2( &stream, MAX_WBITS );
|
|
|
|
if ( err != Z_OK )
|
|
|
|
return FT_THROW( Invalid_Argument );
|
|
|
|
|
|
|
|
err = inflate( &stream, Z_FINISH );
|
|
|
|
if ( err != Z_STREAM_END )
|
|
|
|
{
|
|
|
|
inflateEnd( &stream );
|
|
|
|
if ( err == Z_OK )
|
|
|
|
err = Z_BUF_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*output_len = stream.total_out;
|
|
|
|
|
|
|
|
err = inflateEnd( &stream );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err == Z_MEM_ERROR )
|
|
|
|
return FT_THROW( Out_Of_Memory );
|
|
|
|
|
|
|
|
if ( err == Z_BUF_ERROR )
|
|
|
|
return FT_THROW( Array_Too_Large );
|
|
|
|
|
|
|
|
if ( err == Z_DATA_ERROR )
|
|
|
|
return FT_THROW( Invalid_Table );
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else /* !FT_CONFIG_OPTION_USE_ZLIB */
|
2002-10-31 23:19:27 +01:00
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
2003-04-23 09:13:54 +02:00
|
|
|
FT_Stream_OpenGzip( FT_Stream stream,
|
|
|
|
FT_Stream source )
|
2002-10-31 23:19:27 +01:00
|
|
|
{
|
|
|
|
FT_UNUSED( stream );
|
|
|
|
FT_UNUSED( source );
|
|
|
|
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Unimplemented_Feature );
|
2002-10-31 23:19:27 +01:00
|
|
|
}
|
|
|
|
|
2013-08-29 17:53:24 +02:00
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_Gzip_Uncompress( FT_Memory memory,
|
|
|
|
FT_Byte* output,
|
|
|
|
FT_ULong* output_len,
|
|
|
|
const FT_Byte* input,
|
|
|
|
FT_ULong input_len )
|
|
|
|
{
|
|
|
|
FT_UNUSED( memory );
|
|
|
|
FT_UNUSED( output );
|
|
|
|
FT_UNUSED( output_len );
|
|
|
|
FT_UNUSED( input );
|
|
|
|
FT_UNUSED( input_len );
|
|
|
|
|
|
|
|
return FT_THROW( Unimplemented_Feature );
|
|
|
|
}
|
|
|
|
|
2002-10-31 23:19:27 +01:00
|
|
|
#endif /* !FT_CONFIG_OPTION_USE_ZLIB */
|
2003-04-23 09:13:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|